Skip to content

Commit

Permalink
Merge pull request #29 from bketelsen/goreleaser
Browse files Browse the repository at this point in the history
Goreleaser
  • Loading branch information
bketelsen authored Sep 10, 2021
2 parents 6ef5222 + 8864d12 commit c15f76a
Show file tree
Hide file tree
Showing 216 changed files with 13,829 additions and 4,107 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: build and release

on:
push:
tags:
- v*
branches:
- main
pull_request:

jobs:
unit-tests:
strategy:
matrix:
go-version: [ 1.16 ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
-
name: Cache Go modules
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
-
name: Setup
run: make setup
-
name: Make Unit Tests
run: make test
-
name: Diff
run: git diff
goreleaser:
strategy:
matrix:
go-version: [ 1.16 ]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs:
- unit-tests
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Cache Go modules
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Setup
run: make setup
- name: Make build
run: make build

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
if: success()
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ _testmain.go
# Ignore JetBrains IDE Project Files
.idea
/crypt

# goreleaser
dist/

# coverage
coverage.txt
40 changes: 40 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
project_name: crypt

before:
hooks:
- go mod tidy

builds:
- id: crypt
main: ./bin/crypt
binary: crypt
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
ldflags:
- -s -w -X main.version={{ .Version }} -X main.commit={{ .Commit }} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
env:
- GO111MODULE=on
- MACOSX_DEPLOYMENT_TARGET=10.11
changelog:
filters:
exclude:
- Merge
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip
files:
- README.md
- LICENSE
63 changes: 60 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,61 @@
.PHONY: fmt
SOURCE_FILES?=./...
TEST_PATTERN?=.
TEST_OPTIONS?=
TEST_TIMEOUT?=15m
TEST_PARALLEL?=2
DOCKER_BUILDKIT?=1
export DOCKER_BUILDKIT

export GO111MODULE := on

# Install all the build and lint dependencies
setup:
go mod tidy
git config core.hooksPath .githooks
.PHONY: setup

test:
go test $(TEST_OPTIONS) -p $(TEST_PARALLEL) -v -failfast -race -coverpkg=./... -covermode=atomic -coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=$(TEST_TIMEOUT)
.PHONY: test

cover: test
go tool cover -html=coverage.txt
.PHONY: cover

fmt:
gofmt -l -w `find . -type f -name '*.go' -not -path "./vendor/*"`
goimports -l -w `find . -type f -name '*.go' -not -path "./vendor/*"`
gofumpt -w backend
gofumpt -w bin/crypt
gofumpt -w config
gofumpt -w encoding
.PHONY: fmt


ci: test
.PHONY: ci

build:
go build -o crypt ./bin/crypt
.PHONY: build

install:
go install ./bin/crypt

deps:
go get -u github.com/bketelsen/crypt/bin/crypt
go mod tidy
go mod verify
go mod vendor
.PHONY: deps

todo:
@grep \
--exclude-dir=vendor \
--exclude-dir=node_modules \
--exclude-dir=bin \
--exclude=Makefile \
--text \
--color \
-nRo -E ' TODO:.*|SkipNow' .
.PHONY: todo

.DEFAULT_GOAL := build
14 changes: 9 additions & 5 deletions bin/crypt/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ func getCmd(flagset *flag.FlagSet) {
return
}
value, err := getEncrypted(key, secretKeyring, backendStore)

if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", value)
}

func versionCmd(flagset *flag.FlagSet, ver string) {
flagset.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s version\n", os.Args[0])
flagset.PrintDefaults()
}
fmt.Println(ver)
}

func getEncrypted(key, keyring string, store backend.Store) ([]byte, error) {
var value []byte
kr, err := os.Open(keyring)
Expand All @@ -62,7 +69,6 @@ func getEncrypted(key, keyring string, store backend.Store) ([]byte, error) {
return value, err
}
return value, err

}

func getPlain(key string, store backend.Store) ([]byte, error) {
Expand Down Expand Up @@ -101,7 +107,6 @@ func listCmd(flagset *flag.FlagSet) {
return
}
list, err := listEncrypted(key, secretKeyring, backendStore)

if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -178,12 +183,11 @@ func setCmd(flagset *flag.FlagSet) {
log.Fatal(err)
}
return

}

func setPlain(key string, store backend.Store, d []byte) error {
err := store.Set(key, d)
return err

}

func setEncrypted(key, keyring string, d []byte, store backend.Store) error {
Expand Down
36 changes: 33 additions & 3 deletions bin/crypt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ import (
"fmt"
"log"
"os"
"runtime/debug"
)

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

var (
Version = "dev"
Commit string
CommitDate string
builtBy string
)

var (
data string
backendName string
Expand Down Expand Up @@ -39,6 +47,10 @@ func main() {
getCmd(flagset)
case "list":
listCmd(flagset)
case "version":
ver := buildVersion(Version, Commit, CommitDate, builtBy)
versionCmd(flagset, ver)

default:
help()
}
Expand All @@ -48,13 +60,31 @@ func help() {
const usage = `usage: %s COMMAND [arg...]
commands:
get retrieve the value of a key
list retrieve all values under a key
set set the value of a key
get retrieve the value of a key
list retrieve all values under a key
set set the value of a key
version print the version of crypt
-plaintext don't encrypt or decrypt the values before storage or retrieval
`

_, _ = fmt.Fprintf(os.Stderr, usage, os.Args[0])
os.Exit(1)
}

func buildVersion(version, commit, date, builtBy string) string {
result := "crypt version " + version
if commit != "" {
result = fmt.Sprintf("%s\ncommit: %s", result, commit)
}
if date != "" {
result = fmt.Sprintf("%s\nbuilt at: %s", result, date)
}
if builtBy != "" {
result = fmt.Sprintf("%s\nbuilt by: %s", result, builtBy)
}
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
result = fmt.Sprintf("%s\nmodule version: %s, checksum: %s", result, info.Main.Version, info.Main.Sum)
}
return result
}
11 changes: 10 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ go 1.12

require (
cloud.google.com/go/firestore v1.1.0
github.com/hashicorp/consul/api v1.1.0
github.com/armon/go-metrics v0.3.9 // indirect
github.com/fatih/color v1.12.0 // indirect
github.com/hashicorp/consul/api v1.10.1
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v0.16.2 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
go.etcd.io/etcd/client/v2 v2.305.0
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/sys v0.0.0-20210909193231-528a39cd75f3 // indirect
google.golang.org/api v0.44.0
google.golang.org/grpc v1.38.0
)
Loading

0 comments on commit c15f76a

Please sign in to comment.