Skip to content

Commit a53c34a

Browse files
authored
Added GoReleaser workflow, migrated from the old jenkins, Modified .goreleaser.yaml for templating and config (#717)
1 parent d47dfb7 commit a53c34a

File tree

2 files changed

+173
-41
lines changed

2 files changed

+173
-41
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Spot GoReleaser
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
RUN_TESTS:
7+
description: "Run tests?"
8+
required: true
9+
default: true
10+
type: boolean
11+
12+
RUN_BUILD:
13+
description: "Build the project?"
14+
required: true
15+
default: true
16+
type: boolean
17+
18+
RELEASE_TYPE:
19+
description: "Type of release"
20+
required: true
21+
default: "snapshot"
22+
type: choice
23+
options:
24+
- snapshot
25+
- full
26+
27+
BRANCH_SELECTOR:
28+
description: "Branch to build"
29+
required: false
30+
default: "feat-spot-ocean"
31+
32+
RELEASE_DESCRIPTION:
33+
description: "Description of the release"
34+
required: false
35+
default: ""
36+
37+
jobs:
38+
build:
39+
runs-on: optimized-scale-set
40+
41+
#Fetching source code into the runner
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v3
45+
with:
46+
ref: ${{ inputs.BRANCH_SELECTOR }}
47+
fetch-depth: 0
48+
fetch-tags: true
49+
50+
- name: Set up Go
51+
uses: actions/setup-go@v4
52+
with:
53+
go-version: "1.21"
54+
55+
- name: Show Go environment
56+
run: |
57+
go version
58+
go env
59+
60+
#Tools for code testing
61+
- name: Install tools
62+
if: ${{ inputs.RUN_TESTS }}
63+
run: |
64+
sudo apt-get update
65+
sudo apt-get install -y make
66+
67+
- name: Run tests
68+
if: ${{ inputs.RUN_TESTS }}
69+
run: |
70+
make lint
71+
make check-all-generated-files-up-to-date
72+
make unit-test
73+
74+
#Getting the version of eksctl for tagging the release
75+
- name: Build native eksctl for tagging
76+
if: ${{ inputs.RELEASE_TYPE == 'full' && inputs.RUN_BUILD }}
77+
run: |
78+
mkdir -p ./dist
79+
GOOS=linux GOARCH=amd64 go build -v -o dist/eksctl ./cmd/eksctl
80+
chmod +x dist/eksctl
81+
82+
- name: Extract release tag from binary
83+
if: ${{ inputs.RELEASE_TYPE == 'full' && inputs.RUN_BUILD }}
84+
id: extract_tag
85+
run: |
86+
BIN="dist/eksctl"
87+
if [[ ! -f "$BIN" ]]; then
88+
echo "Error: eksctl binary not found"
89+
exit 1
90+
fi
91+
92+
VERSION=$("$BIN" version | cut -d- -f1)
93+
EKSCTL_VERSION="v$VERSION"
94+
echo "Extracted release tag: $EKSCTL_VERSION"
95+
96+
echo "release_tag=$EKSCTL_VERSION" >> $GITHUB_OUTPUT
97+
echo "EKSCTL_RELEASE_TAG=$EKSCTL_VERSION" >> $GITHUB_ENV
98+
99+
- name: Create local git tag (required by GoReleaser)
100+
if: ${{ inputs.RELEASE_TYPE == 'full' && inputs.RUN_BUILD }}
101+
run: |
102+
git config user.name "github-actions"
103+
git config user.email "[email protected]"
104+
git tag ${{ steps.extract_tag.outputs.release_tag }}
105+
106+
#The release itself
107+
#snapshot (only bullding exporting artifacts)
108+
#full (fully releasing via GitHub Release)
109+
- name: Run GoReleaser (snapshot or full release)
110+
if: ${{ inputs.RUN_BUILD }}
111+
uses: goreleaser/goreleaser-action@v5
112+
with:
113+
version: latest
114+
args: ${{ inputs.RELEASE_TYPE == 'full' && 'release --clean --parallelism 3' || 'release --snapshot --parallelism 3' }}
115+
env:
116+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117+
GORELEASER_CURRENT_TAG: ${{ steps.extract_tag.outputs.release_tag }}
118+
RELEASE_DESCRIPTION: ${{ inputs.RELEASE_DESCRIPTION }}
119+
PRE_RELEASE_ID: dev
120+
121+
#If only building (snapshot) uploading the artifact to the workflow
122+
- name: Upload built artifacts
123+
if: ${{ inputs.RUN_BUILD && inputs.RELEASE_TYPE == 'snapshot' }}
124+
uses: actions/upload-artifact@v4
125+
with:
126+
name: built-artifacts
127+
path: dist/
128+
129+
- name: Clean up
130+
run: |
131+
rm -rf dist/
132+
rm -rf $HOME/.cache/go-build
133+
rm -rf $GOPATH/pkg/mod

.goreleaser.yml

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
11
release:
2-
name_template: "{{ .ProjectName }} {{ .Env.RELEASE_DESCRIPTION }}"
3-
prerelease: auto # this should detect a release candidate and mark it as pre-release in GitHub
2+
name_template: "{{ .Tag }}{{ with .Env.RELEASE_DESCRIPTION }} {{ . }}{{ end }}"
3+
prerelease: auto
44

55
builds:
6-
- id: default
7-
main: ./cmd/eksctl
8-
binary: eksctl
9-
flags:
10-
- -tags
11-
- netgo release
12-
- -trimpath
13-
env:
14-
- CGO_ENABLED=0
15-
ldflags:
16-
# gitTag set from a generated file (see ./tag_release.sh)
17-
- -s -w -X github.com/eksctl-io/eksctl/pkg/version.buildDate={{.Date}} -X github.com/eksctl-io/eksctl/pkg/version.gitCommit={{.ShortCommit}} -X github.com/eksctl-io/eksctl/pkg/version.PreReleaseID={{.Env.PRE_RELEASE_ID}}
18-
goos:
19-
- windows
20-
- darwin
21-
- linux
22-
goarch:
23-
- amd64
24-
- arm64
25-
- arm
26-
goarm:
27-
- 6
28-
- 7
6+
- id: default
7+
main: ./cmd/eksctl
8+
binary: eksctl
9+
flags:
10+
- -tags
11+
- netgo release
12+
- -trimpath
13+
env:
14+
- CGO_ENABLED=0
15+
- GOMAXPROCS=2
16+
ldflags:
17+
- -s -w
18+
- -X github.com/eksctl-io/eksctl/pkg/version.buildDate={{.Date}}
19+
- -X github.com/eksctl-io/eksctl/pkg/version.gitCommit={{.ShortCommit}}
20+
- -X github.com/eksctl-io/eksctl/pkg/version.PreReleaseID={{.Env.PRE_RELEASE_ID}}
21+
goos:
22+
- windows
23+
- darwin
24+
- linux
25+
goarch:
26+
- amd64
27+
- arm64
2928

3029
archives:
31-
- id: default
32-
builds:
33-
- default
34-
name_template: >-
35-
eksctl_{{- tolower .Os }}_
36-
{{- if eq .Arch "amd64" }}x86_64
37-
{{- else if eq .Arch "386" }}i386
38-
{{- else }}{{ .Arch }}{{ end }}
39-
{{- if .Arm }}v{{ .Arm }}{{ end -}}
40-
format: tar.gz
41-
format_overrides:
42-
- goos: windows
43-
format: zip
44-
files:
45-
- none*
30+
- id: default
31+
builds:
32+
- default
33+
name_template: >-
34+
eksctl_{{- tolower .Os }}_
35+
{{- if eq .Arch "amd64" }}amd64
36+
{{- else if eq .Arch "386" }}i386
37+
{{- else }}{{ .Arch }}{{ end }}
38+
{{- if .Arm }}v{{ .Arm }}{{ end -}}
39+
format: tar.gz
40+
format_overrides:
41+
- goos: windows
42+
format: zip
43+
files:
44+
- none*
4645

4746
checksum:
48-
name_template: "eksctl_checksums.txt"
47+
name_template: "eksctl_checksums.txt"

0 commit comments

Comments
 (0)