Skip to content

Commit a3b8c6b

Browse files
committed
Add release and publish GHA workflows
These are copied from the govuk-cli repo, so have already been tested
1 parent 22d63e0 commit a3b8c6b

4 files changed

Lines changed: 92 additions & 1 deletion

File tree

.github/workflows/publish.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Publish Versioned Release
2+
on:
3+
workflow_dispatch:
4+
workflow_call:
5+
secrets:
6+
GOVUK_CI_GITHUB_API_TOKEN:
7+
required: true
8+
description: "GitHub token with permissions to publish to the Homebrew tap"
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
steps:
15+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
16+
with:
17+
ref: main
18+
fetch-depth: 0
19+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
20+
with:
21+
go-version-file: go.mod
22+
- uses: goreleaser/goreleaser-action@1a80836c5c9d9e5755a25cb59ec6f45a3b5f41a8 # v7.2.1
23+
with:
24+
version: "2.15.4"
25+
args: release --clean
26+
env:
27+
GITHUB_PAT_HOMEBREW: ${{ secrets.GOVUK_CI_GITHUB_API_TOKEN }}
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Create Versioned Release
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
level:
6+
description: 'The semver level of the release'
7+
required: true
8+
default: 'patch'
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
jobs:
15+
release:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
steps:
20+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
21+
with:
22+
ref: main
23+
fetch-depth: 0
24+
- run: |
25+
NEW_VERSION=$(scripts/calculate-semver.sh "${{ github.event.inputs.level }}")
26+
echo "Calculated new version: $NEW_VERSION"
27+
git tag "$NEW_VERSION"
28+
echo "Pushing new tag: $NEW_VERSION"
29+
git push --tags
30+
publish:
31+
uses: ./.github/workflows/publish.yaml
32+
needs: release
33+
permissions:
34+
contents: write
35+
secrets:
36+
GOVUK_CI_GITHUB_API_TOKEN: ${{ secrets.GOVUK_CI_GITHUB_API_TOKEN }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
# or operating system, you probably want to add a global ignore instead:
55
# git config --global core.excludesfile ~/.gitignore_global
66
/dist
7-
/bin
7+
/bin
8+
/crds

scripts/calculate-semver.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [ $# -lt 1 ]; then
5+
echo "usage: $(basename "$0") <major|minor|patch>" >&2
6+
exit 1
7+
fi
8+
9+
level=$1
10+
11+
current=$(git tag --list 'v*.*.*' --sort=-v:refname | head -n1)
12+
current=${current:-v0.0.0}
13+
14+
IFS=. read -r major minor patch <<<"${current#v}"
15+
16+
case $level in
17+
major) next="$((major + 1)).0.0" ;;
18+
minor) next="${major}.$((minor + 1)).0" ;;
19+
patch) next="${major}.${minor}.$((patch + 1))" ;;
20+
*)
21+
echo "error: unknown level '$level' (expected major, minor, or patch)" >&2
22+
exit 1
23+
;;
24+
esac
25+
26+
echo "v${next}"

0 commit comments

Comments
 (0)