Skip to content

Commit 8864d12

Browse files
committed
goreleaser, go mod update
1 parent 60ccdd7 commit 8864d12

File tree

216 files changed

+13812
-4125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

216 files changed

+13812
-4125
lines changed

.github/workflows/main.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: build and release
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
branches:
8+
- main
9+
pull_request:
10+
11+
jobs:
12+
unit-tests:
13+
strategy:
14+
matrix:
15+
go-version: [ 1.16 ]
16+
os: [ ubuntu-latest, macos-latest, windows-latest ]
17+
runs-on: ${{ matrix.os }}
18+
steps:
19+
-
20+
name: Checkout
21+
uses: actions/checkout@v2
22+
with:
23+
fetch-depth: 0
24+
-
25+
name: Set up Go
26+
uses: actions/setup-go@v2
27+
with:
28+
go-version: ${{ matrix.go-version }}
29+
-
30+
name: Cache Go modules
31+
uses: actions/cache@v1
32+
with:
33+
path: ~/go/pkg/mod
34+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
35+
restore-keys: |
36+
${{ runner.os }}-go-
37+
-
38+
name: Setup
39+
run: make setup
40+
-
41+
name: Make Unit Tests
42+
run: make test
43+
-
44+
name: Diff
45+
run: git diff
46+
goreleaser:
47+
strategy:
48+
matrix:
49+
go-version: [ 1.16 ]
50+
runs-on: ubuntu-latest
51+
if: startsWith(github.ref, 'refs/tags/')
52+
needs:
53+
- unit-tests
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v2
57+
with:
58+
fetch-depth: 0
59+
- name: Set up Go
60+
uses: actions/setup-go@v2
61+
with:
62+
go-version: ${{ matrix.go-version }}
63+
- name: Cache Go modules
64+
uses: actions/cache@v1
65+
with:
66+
path: ~/go/pkg/mod
67+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
68+
restore-keys: |
69+
${{ runner.os }}-go-
70+
- name: Setup
71+
run: make setup
72+
- name: Make build
73+
run: make build
74+
75+
- name: Run GoReleaser
76+
uses: goreleaser/goreleaser-action@v2
77+
if: success()
78+
with:
79+
version: latest
80+
args: release --rm-dist
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ _testmain.go
3232

3333
# goreleaser
3434
dist/
35+
36+
# coverage
37+
coverage.txt

.goreleaser.yml

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
11
project_name: crypt
2+
23
before:
34
hooks:
4-
# You may remove this if you don't use go modules.
55
- go mod tidy
6+
67
builds:
7-
- env:
8-
- CGO_ENABLED=0
8+
- id: crypt
9+
main: ./bin/crypt
10+
binary: crypt
11+
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
12+
ldflags:
13+
- -s -w -X main.version={{ .Version }} -X main.commit={{ .Commit }} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser
914
goos:
1015
- linux
11-
- windows
1216
- darwin
17+
- windows
1318
goarch:
1419
- amd64
1520
- arm64
16-
archives:
17-
- replacements:
18-
darwin: Darwin
19-
linux: Linux
20-
windows: Windows
21-
386: i386
22-
amd64: x86_64
23-
checksum:
24-
name_template: 'checksums.txt'
25-
snapshot:
26-
name_template: "{{ incpatch .Version }}-next"
21+
env:
22+
- GO111MODULE=on
23+
- MACOSX_DEPLOYMENT_TARGET=10.11
2724
changelog:
28-
sort: asc
2925
filters:
3026
exclude:
31-
- '^docs:'
32-
- '^test:'
27+
- Merge
28+
archives:
29+
- replacements:
30+
darwin: Darwin
31+
linux: Linux
32+
windows: Windows
33+
386: i386
34+
amd64: x86_64
35+
format_overrides:
36+
- goos: windows
37+
format: zip
38+
files:
39+
- README.md
40+
- LICENSE

Makefile

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,61 @@
1-
.PHONY: fmt
1+
SOURCE_FILES?=./...
2+
TEST_PATTERN?=.
3+
TEST_OPTIONS?=
4+
TEST_TIMEOUT?=15m
5+
TEST_PARALLEL?=2
6+
DOCKER_BUILDKIT?=1
7+
export DOCKER_BUILDKIT
8+
9+
export GO111MODULE := on
10+
11+
# Install all the build and lint dependencies
12+
setup:
13+
go mod tidy
14+
git config core.hooksPath .githooks
15+
.PHONY: setup
16+
17+
test:
18+
go test $(TEST_OPTIONS) -p $(TEST_PARALLEL) -v -failfast -race -coverpkg=./... -covermode=atomic -coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=$(TEST_TIMEOUT)
19+
.PHONY: test
20+
21+
cover: test
22+
go tool cover -html=coverage.txt
23+
.PHONY: cover
24+
225
fmt:
3-
gofmt -l -w `find . -type f -name '*.go' -not -path "./vendor/*"`
4-
goimports -l -w `find . -type f -name '*.go' -not -path "./vendor/*"`
26+
gofumpt -w backend
27+
gofumpt -w bin/crypt
28+
gofumpt -w config
29+
gofumpt -w encoding
30+
.PHONY: fmt
31+
32+
33+
ci: test
34+
.PHONY: ci
35+
36+
build:
37+
go build -o crypt ./bin/crypt
38+
.PHONY: build
39+
40+
install:
41+
go install ./bin/crypt
42+
43+
deps:
44+
go get -u github.com/bketelsen/crypt/bin/crypt
45+
go mod tidy
46+
go mod verify
47+
go mod vendor
48+
.PHONY: deps
49+
50+
todo:
51+
@grep \
52+
--exclude-dir=vendor \
53+
--exclude-dir=node_modules \
54+
--exclude-dir=bin \
55+
--exclude=Makefile \
56+
--text \
57+
--color \
58+
-nRo -E ' TODO:.*|SkipNow' .
59+
.PHONY: todo
60+
61+
.DEFAULT_GOAL := build

bin/crypt/cmd.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,20 @@ func getCmd(flagset *flag.FlagSet) {
3939
return
4040
}
4141
value, err := getEncrypted(key, secretKeyring, backendStore)
42-
4342
if err != nil {
4443
log.Fatal(err)
4544
}
4645
fmt.Printf("%s\n", value)
4746
}
4847

48+
func versionCmd(flagset *flag.FlagSet, ver string) {
49+
flagset.Usage = func() {
50+
fmt.Fprintf(os.Stderr, "usage: %s version\n", os.Args[0])
51+
flagset.PrintDefaults()
52+
}
53+
fmt.Println(ver)
54+
}
55+
4956
func getEncrypted(key, keyring string, store backend.Store) ([]byte, error) {
5057
var value []byte
5158
kr, err := os.Open(keyring)
@@ -62,7 +69,6 @@ func getEncrypted(key, keyring string, store backend.Store) ([]byte, error) {
6269
return value, err
6370
}
6471
return value, err
65-
6672
}
6773

6874
func getPlain(key string, store backend.Store) ([]byte, error) {
@@ -101,7 +107,6 @@ func listCmd(flagset *flag.FlagSet) {
101107
return
102108
}
103109
list, err := listEncrypted(key, secretKeyring, backendStore)
104-
105110
if err != nil {
106111
log.Fatal(err)
107112
}
@@ -178,12 +183,11 @@ func setCmd(flagset *flag.FlagSet) {
178183
log.Fatal(err)
179184
}
180185
return
181-
182186
}
187+
183188
func setPlain(key string, store backend.Store, d []byte) error {
184189
err := store.Set(key, d)
185190
return err
186-
187191
}
188192

189193
func setEncrypted(key, keyring string, d []byte, store backend.Store) error {

bin/crypt/main.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@ import (
55
"fmt"
66
"log"
77
"os"
8+
"runtime/debug"
89
)
910

1011
var flagset = flag.NewFlagSet("crypt", flag.ExitOnError)
1112

13+
var (
14+
Version = "dev"
15+
Commit string
16+
CommitDate string
17+
builtBy string
18+
)
19+
1220
var (
1321
data string
1422
backendName string
@@ -39,6 +47,10 @@ func main() {
3947
getCmd(flagset)
4048
case "list":
4149
listCmd(flagset)
50+
case "version":
51+
ver := buildVersion(Version, Commit, CommitDate, builtBy)
52+
versionCmd(flagset, ver)
53+
4254
default:
4355
help()
4456
}
@@ -48,13 +60,31 @@ func help() {
4860
const usage = `usage: %s COMMAND [arg...]
4961
5062
commands:
51-
get retrieve the value of a key
52-
list retrieve all values under a key
53-
set set the value of a key
63+
get retrieve the value of a key
64+
list retrieve all values under a key
65+
set set the value of a key
66+
version print the version of crypt
5467
5568
-plaintext don't encrypt or decrypt the values before storage or retrieval
5669
`
5770

5871
_, _ = fmt.Fprintf(os.Stderr, usage, os.Args[0])
5972
os.Exit(1)
6073
}
74+
75+
func buildVersion(version, commit, date, builtBy string) string {
76+
result := "crypt version " + version
77+
if commit != "" {
78+
result = fmt.Sprintf("%s\ncommit: %s", result, commit)
79+
}
80+
if date != "" {
81+
result = fmt.Sprintf("%s\nbuilt at: %s", result, date)
82+
}
83+
if builtBy != "" {
84+
result = fmt.Sprintf("%s\nbuilt by: %s", result, builtBy)
85+
}
86+
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
87+
result = fmt.Sprintf("%s\nmodule version: %s, checksum: %s", result, info.Main.Version, info.Main.Sum)
88+
}
89+
return result
90+
}

go.mod

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@ go 1.12
44

55
require (
66
cloud.google.com/go/firestore v1.1.0
7-
github.com/hashicorp/consul/api v1.1.0
7+
github.com/armon/go-metrics v0.3.9 // indirect
8+
github.com/fatih/color v1.12.0 // indirect
9+
github.com/hashicorp/consul/api v1.10.1
10+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
11+
github.com/hashicorp/go-hclog v0.16.2 // indirect
12+
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
13+
github.com/hashicorp/golang-lru v0.5.4 // indirect
14+
github.com/mattn/go-isatty v0.0.14 // indirect
15+
github.com/mitchellh/mapstructure v1.4.1 // indirect
816
go.etcd.io/etcd/client/v2 v2.305.0
917
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
18+
golang.org/x/sys v0.0.0-20210909193231-528a39cd75f3 // indirect
1019
google.golang.org/api v0.44.0
1120
google.golang.org/grpc v1.38.0
1221
)

0 commit comments

Comments
 (0)