Skip to content

Commit b8a0e94

Browse files
committed
feat: adopt GoReleaser with Ko integration for releases
Replace raw ko/crane/cosign CLI orchestration with GoReleaser v2, which handles binary builds, container images (via kos:), checksums, SBOMs, changelog, and GitHub releases in a single declarative config.
1 parent 2cccf2b commit b8a0e94

File tree

6 files changed

+122
-57
lines changed

6 files changed

+122
-57
lines changed

.github/actions/load-versions/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ outputs:
2929
cosign:
3030
description: 'Cosign version'
3131
value: ${{ steps.versions.outputs.cosign }}
32+
goreleaser:
33+
description: 'GoReleaser version'
34+
value: ${{ steps.versions.outputs.goreleaser }}
3235

3336
runs:
3437
using: 'composite'
@@ -51,6 +54,7 @@ runs:
5154
5255
# Build
5356
echo "registry=$(yq eval '.build.registry' .settings.yaml)" >> $GITHUB_OUTPUT
57+
echo "goreleaser=$(yq eval '.build.goreleaser' .settings.yaml)" >> $GITHUB_OUTPUT
5458
5559
# Testing
5660
echo "kind_version=$(yq eval '.testing.kind_version' .settings.yaml)" >> $GITHUB_OUTPUT
@@ -68,5 +72,6 @@ runs:
6872
echo " golangci_lint: ${{ steps.versions.outputs.golangci_lint }}"
6973
echo " scan_severity: ${{ steps.versions.outputs.scan_severity }}"
7074
echo " registry: ${{ steps.versions.outputs.registry }}"
75+
echo " goreleaser: ${{ steps.versions.outputs.goreleaser }}"
7176
echo " kind_version: ${{ steps.versions.outputs.kind_version }}"
7277
echo " k8s_version: ${{ steps.versions.outputs.k8s_version }}"

.github/workflows/on-tag.yaml

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ jobs:
1616
release:
1717
timeout-minutes: 30
1818
env:
19-
IMAGE_NAME: node-role-controller
2019
DEPLOYMENT_PATCH_FILE: deployment/overlays/dev/patch-deployment.yaml
2120
outputs:
2221
image-uri: ${{ steps.image.outputs.uri }}
@@ -26,14 +25,16 @@ jobs:
2625
source-tag: ${{ github.ref_name }}
2726
runs-on: ubuntu-latest
2827
permissions:
29-
contents: read
28+
contents: write
3029
security-events: write
3130
id-token: write
3231
packages: write
3332
attestations: write
3433
steps:
3534

3635
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
36+
with:
37+
fetch-depth: 0
3738

3839
- name: Load versions
3940
id: versions
@@ -51,55 +52,33 @@ jobs:
5152
- name: Test
5253
run: go test -count=1 -covermode=atomic -coverprofile=coverage.out ./...
5354

54-
- uses: ko-build/setup-ko@d006021bd0c28d1ce33a07e7943d48b079944c8d # v0.9
55-
- uses: imjasonh/setup-crane@31b88efe9de28ae0ffa220711af4b60be9435f6e # v0.4
56-
- uses: sigstore/cosign-installer@d7543c93d881b35a8faa02e8e3605f69b7a1ce62 # v3.10.0
57-
58-
- name: Authenticate
59-
run: |
60-
echo ${{ secrets.GITHUB_TOKEN }} | ko login ghcr.io -u ${{ github.actor }} --password-stdin
61-
echo ${{ secrets.GITHUB_TOKEN }} | crane auth login ghcr.io -u ${{ github.actor }} --password-stdin
62-
echo ${{ secrets.GITHUB_TOKEN }} | cosign login ghcr.io -u ${{ github.actor }} --password-stdin
63-
64-
- name: Build Image
65-
id: image
66-
env:
67-
KO_DOCKER_REPO: ${{ steps.versions.outputs.registry }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
68-
KO_DEFAULTBASEIMAGE: cgr.dev/chainguard/static:latest
69-
run: |
70-
set -euo pipefail
71-
ko build main.go \
72-
--platform linux/amd64,linux/arm64 \
73-
--image-refs .refs \
74-
--bare \
75-
--tags latest \
76-
--tags ${{ github.ref_name }}
77-
cat .refs
78-
DIGEST="$(crane digest ${KO_DOCKER_REPO}:${{ github.ref_name }})"
79-
echo "uri=${KO_DOCKER_REPO}:${{ github.ref_name }}@${DIGEST}" >> "$GITHUB_OUTPUT"
80-
echo "digest=${DIGEST}" >> "$GITHUB_OUTPUT"
81-
echo "name=${KO_DOCKER_REPO}" >> "$GITHUB_OUTPUT"
55+
- name: Install GoReleaser
56+
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
57+
with:
58+
install-only: true
59+
version: ${{ steps.versions.outputs.goreleaser }}
8260

83-
- name: Attest
84-
uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3.0.0
61+
- name: Login to GHCR
62+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
8563
with:
86-
subject-name: ${{ steps.image.outputs.name }}
87-
subject-digest: ${{ steps.image.outputs.digest }}
88-
push-to-registry: true
64+
registry: ghcr.io
65+
username: ${{ github.actor }}
66+
password: ${{ secrets.GITHUB_TOKEN }}
8967

90-
- name: Publish Attestation
68+
- name: Release
9169
env:
92-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93-
IMAGE: "${{ steps.image.outputs.name }}@${{ steps.image.outputs.digest }}"
94-
BUNDLE: "${{ steps.image.outputs.digest }}.jsonl"
95-
COSIGN_EXPERIMENTAL: "1"
96-
ATTEST_TYPE: "https://slsa.dev/provenance/v1"
97-
PREDICATE: "predicate.json"
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
run: make release
72+
73+
- name: Extract Image Metadata
74+
id: image
9875
run: |
9976
set -euo pipefail
100-
gh attestation download "oci://$IMAGE" -R ${{ github.repository }} --predicate-type $ATTEST_TYPE --limit 1
101-
jq -r '.dsseEnvelope.payload | @base64d | fromjson | .predicate' $BUNDLE > $PREDICATE
102-
cosign attest -y --type $ATTEST_TYPE --predicate $PREDICATE $IMAGE
77+
IMAGE_NAME=$(jq -r '[.[] | select(.type == "Docker Manifest")] | first | .name' dist/artifacts.json)
78+
DIGEST=$(jq -r '[.[] | select(.type == "Docker Manifest")] | first | .extra.Digest' dist/artifacts.json)
79+
echo "uri=${IMAGE_NAME}@${DIGEST}" >> "$GITHUB_OUTPUT"
80+
echo "digest=${DIGEST}" >> "$GITHUB_OUTPUT"
81+
echo "name=${IMAGE_NAME%%:*}" >> "$GITHUB_OUTPUT"
10382
10483
- name: Setup KinD Cluster
10584
uses: chainguard-dev/actions/setup-kind@eab208ef2d05b13404296a5e194a6b237e8bb213 # v1.6.4

.goreleaser.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
version: 2
2+
3+
project_name: node-role-controller
4+
5+
builds:
6+
- id: node-role-controller
7+
binary: node-role-controller
8+
main: main.go
9+
mod_timestamp: '{{ .CommitTimestamp }}'
10+
env:
11+
- CGO_ENABLED=0
12+
flags:
13+
- -trimpath
14+
ldflags:
15+
- -w
16+
- -s
17+
- -extldflags "-static"
18+
goos:
19+
- linux
20+
goarch:
21+
- amd64
22+
- arm64
23+
24+
gomod:
25+
proxy: false
26+
27+
kos:
28+
- id: node-role-controller
29+
build: node-role-controller
30+
repositories:
31+
- ghcr.io/mchmarny/node-role-controller
32+
base_image: cgr.dev/chainguard/static:latest
33+
platforms:
34+
- linux/amd64
35+
- linux/arm64
36+
tags:
37+
- latest
38+
- "{{.Tag}}"
39+
preserve_import_paths: false
40+
bare: true
41+
42+
sboms:
43+
- artifacts: binary
44+
45+
checksum:
46+
name_template: "{{ .ProjectName }}_checksums.txt"
47+
algorithm: sha256
48+
49+
snapshot:
50+
version_template: "{{ .Tag }}-next"
51+
52+
report_sizes: true
53+
54+
metadata:
55+
mod_timestamp: "{{ .CommitTimestamp }}"
56+
57+
release:
58+
github:
59+
owner: mchmarny
60+
name: rolesetter
61+
draft: false
62+
63+
changelog:
64+
sort: asc
65+
use: github
66+
filters:
67+
exclude:
68+
- "^build:"
69+
- "^docs:"
70+
- "^test:"
71+
- "^lint:"
72+
- "^chore: readme"
73+
- "^chore: bump version"
74+
groups:
75+
- title: Features
76+
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
77+
order: 0
78+
- title: Tasks
79+
regexp: '^.*?chore(\([[:word:]]+\))??!?:.+$'
80+
order: 1
81+
- title: Bug fixes
82+
regexp: '^.*?(fix|bug)(\([[:word:]]+\))??!?:.+$'
83+
order: 2
84+
- title: Others
85+
order: 999

.settings.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ linting:
1717
# Build Configuration
1818
build:
1919
registry: 'ghcr.io'
20+
goreleaser: 'v2.14.1'
2021

2122
# Testing Configuration
2223
testing:

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ GO_ENV := \
1616
GO111MODULE=$(GO111MODULE) \
1717
CGO_ENABLED=$(CGO_ENABLED)
1818

19-
.PHONY: all build lint clean test help tidy upgrade tag pre helm-lint helm-publish
19+
.PHONY: all build lint clean test help tidy upgrade tag pre helm-lint helm-publish release build-snapshot
2020

2121
all: help
2222

@@ -25,6 +25,12 @@ pre: tidy lint test vet helm-lint ## Run all quality checks
2525
build: ## Build the Go binary locally
2626
$(GO_ENV) go build -v -o bin/$(APP_NAME) main.go
2727

28+
release: ## Run GoReleaser release
29+
goreleaser release --clean --fail-fast --timeout 30m
30+
31+
build-snapshot: ## Run GoReleaser snapshot build (local dev)
32+
goreleaser build --clean --single-target --snapshot
33+
2834
clean: ## Clean the build artifacts
2935
$(GO_ENV) go clean -x; \
3036
rm -f bin/$(APP_NAME)

ko.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)