Skip to content

Commit eee2b96

Browse files
committed
Add initial release workflow with goreleaser-cross
1 parent 5bc5cf3 commit eee2b96

File tree

3 files changed

+229
-2
lines changed

3 files changed

+229
-2
lines changed

.github/workflows/release.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Create Release & Upload Assets
2+
3+
on:
4+
push:
5+
# Sequence of patterns matched against refs/tags
6+
tags:
7+
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
8+
9+
jobs:
10+
test:
11+
name: Lint, Test, Build
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Install dependencies
15+
run: sudo apt update && sudo apt install -y libpcsclite-dev
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
- name: Setup Go
19+
uses: actions/setup-go@v3
20+
with:
21+
go-version: "1.18"
22+
- name: golangci-lint
23+
uses: golangci/golangci-lint-action@v2
24+
with:
25+
version: latest
26+
- name: Test, Build
27+
id: lintTestBuild
28+
run: V=1 make ci
29+
30+
create_release:
31+
name: Create Release
32+
needs: test
33+
runs-on: ubuntu-latest
34+
outputs:
35+
version: ${{ steps.extract-tag.outputs.VERSION }}
36+
vversion: ${{ steps.extract-tag.outputs.VVERSION }}
37+
is_prerelease: ${{ steps.is_prerelease.outputs.IS_PRERELEASE }}
38+
steps:
39+
- name: Extract Tag Names
40+
id: extract-tag
41+
run: |
42+
VVERSION=${GITHUB_REF#refs/tags/}
43+
VERSION=${GITHUB_REF#refs/tags/v}
44+
echo "::set-output name=VVERSION::${VVERSION}"
45+
echo "::set-output name=VERSION::${VERSION}"
46+
- name: Is Pre-release
47+
id: is_prerelease
48+
run: |
49+
set +e
50+
echo ${{ github.ref }} | grep "\-rc.*"
51+
OUT=$?
52+
if [ $OUT -eq 0 ]; then IS_PRERELEASE=true; else IS_PRERELEASE=false; fi
53+
echo "::set-output name=IS_PRERELEASE::${IS_PRERELEASE}"
54+
- name: Create Release
55+
id: create_release
56+
uses: actions/create-release@v1
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
with:
60+
tag_name: ${{ github.ref }}
61+
release_name: Release ${{ github.ref }}
62+
draft: false
63+
prerelease: ${{ steps.is_prerelease.outputs.IS_PRERELEASE }}
64+
65+
goreleaser:
66+
name: Upload Assets to Github w/ goreleaser
67+
runs-on: ubuntu-latest
68+
needs: create_release
69+
steps:
70+
- name: Install dependencies
71+
run: sudo apt update && sudo apt install -y libpcsclite-dev
72+
- name: Checkout
73+
uses: actions/checkout@v3
74+
with:
75+
fetch-depth: 0
76+
- name: Set up Go
77+
uses: actions/setup-go@v3
78+
with:
79+
go-version: 1.18
80+
- name: release dry run
81+
run: make release-dry-run
82+
- name: setup release environment
83+
run: |-
84+
echo 'GITHUB_TOKEN=${{secrets.GORELEASER_ACCESS_TOKEN}}' > .release-env
85+
- name: release publish
86+
run: make release

.goreleaser.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# step-kms-plugin .goreleaser.yml file.
2+
# Check the documentation at:
3+
# - http://goreleaser.com
4+
# - https://github.com/goreleaser/goreleaser-cross
5+
# - https://github.com/goreleaser/goreleaser-cross-example
6+
project_name: step-kms-plugin
7+
8+
builds:
9+
- id: linux-amd64
10+
main: ./main.go
11+
binary: step-kms-plugin
12+
goos:
13+
- linux
14+
goarch:
15+
- amd64
16+
env:
17+
- CC=gcc
18+
- CXX=g++
19+
flags:
20+
- -trimpath
21+
ldflags:
22+
- -s -w -X cmd.Version={{.Version}} -X cmd.BuildTime={{.Date}}
23+
- id: darwin-amd64
24+
main: ./main.go
25+
binary: step-kms-plugin
26+
goos:
27+
- darwin
28+
goarch:
29+
- amd64
30+
env:
31+
- CC=o64-clang
32+
- CXX=o64-clang++
33+
flags:
34+
- -trimpath
35+
ldflags:
36+
- -s -w -X cmd.Version={{.Version}} -X cmd.BuildTime={{.Date}}
37+
- id: darwin-arm64
38+
main: ./main.go
39+
binary: step-kms-plugin
40+
goos:
41+
- darwin
42+
goarch:
43+
- arm64
44+
env:
45+
- CC=oa64-clang
46+
- CXX=oa64-clang++
47+
flags:
48+
- -trimpath
49+
ldflags:
50+
- -s -w -X cmd.Version={{.Version}} -X cmd.BuildTime={{.Date}}
51+
52+
archives:
53+
- id: step-kms-plugin
54+
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
55+
format_overrides:
56+
- goos: windows
57+
format: zip
58+
builds:
59+
- linux-amd64
60+
- darwin-amd64
61+
- darwin-arm64
62+
wrap_in_directory: "{{ .ProjectName }}_{{ .Version }}"
63+
files:
64+
- README.md
65+
- LICENSE
66+
- completions/*
67+
68+
nfpms:
69+
- builds:
70+
- linux-amd64
71+
package_name: step-kms-plugin
72+
file_name_template: "{{ .PackageName }}_{{ .Version }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
73+
vendor: Smallstep Labs
74+
homepage: https://github.com/smallstep/step-kms-plugin
75+
maintainer: Smallstep <techadmin@smallstep.com>
76+
description: >
77+
step-kms-plugin is a plugin for step to manage keys and certificates on a cloud KMSs and HSMs
78+
license: Apache 2.0
79+
section: utils
80+
formats:
81+
- deb
82+
- rpm
83+
priority: optional
84+
bindir: /usr/bin
85+
contents:
86+
- dst: /usr/bin/step-kms-plugin
87+
type: ghost
88+
- src: completions/bash_completion
89+
dst: /usr/share/bash-completion/completions/step-kms-plugin
90+
- src: completions/zsh_completion
91+
dst: /usr/share/zsh/vendor-completions/_step-kms-plugin
92+
packager: deb
93+
- src: completions/zsh_completion
94+
dst: /usr/share/zsh/site-functions/_step-kms-plugin
95+
packager: rpm
96+
97+
checksum:
98+
name_template: "checksums.txt"
99+
100+
snapshot:
101+
name_template: "{{ .Tag }}"
102+
103+
changelog:
104+
sort: asc
105+
106+
release:
107+
github:
108+
owner: goreleaser
109+
name: step-kms-plugin
110+
prerelease: auto
111+
draft: false

Makefile

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PKG?=github.com/smallstep/step-kms-plugin
22
BINNAME?=step-kms-plugin
3-
3+
GOLANG_CROSS_VERSION?=v1.18.3
44

55
# Set V to 1 for verbose output from the Makefile
66
Q=$(if $V,,@)
@@ -10,6 +10,10 @@ GOOS_OVERRIDE ?=
1010
OUTPUT_ROOT=output/
1111
RELEASE=./.releases
1212

13+
#########################################
14+
# Default
15+
#########################################
16+
1317
all: lint test build
1418

1519
ci: test build
@@ -70,12 +74,12 @@ generate: build
7074
$Q bin/step-kms-plugin completion powershell > completions/powershell_completion
7175
$Q bin/step-kms-plugin completion zsh > completions/zsh_completion
7276

73-
7477
.PHONY: generate
7578

7679
#########################################
7780
# Test
7881
#########################################
82+
7983
test:
8084
$Q go test -coverprofile=coverage.out ./...
8185

@@ -93,6 +97,32 @@ lint:
9397

9498
.PHONY: fmt lint
9599

100+
#########################################
101+
# Release
102+
#########################################
103+
104+
release-dry-run:
105+
$Q @docker run --rm --privileged -e CGO_ENABLED=1 \
106+
-v /var/run/docker.sock:/var/run/docker.sock \
107+
-v `pwd`:/go/src/$(PKG) \
108+
-w /go/src/$(PKG) \
109+
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
110+
--rm-dist --skip-validate --skip-publish
111+
112+
release:
113+
@if [ ! -f ".release-env" ]; then \
114+
echo "\033[91m.release-env is required for release\033[0m";\
115+
exit 1;\
116+
fi
117+
$Q @docker run --rm --privileged -e CGO_ENABLED=1 --env-file .release-env \
118+
-v /var/run/docker.sock:/var/run/docker.sock \
119+
-v `pwd`:/go/src/$(PKG) \
120+
-w /go/src/$(PKG) \
121+
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
122+
release --rm-dist
123+
124+
.PHONY: release-dry-run release
125+
96126
#########################################
97127
# Install
98128
#########################################

0 commit comments

Comments
 (0)