Skip to content

Commit 7074f65

Browse files
author
Miguel Medinilla
committed
Add release workflows mirroring cookie-guard setup
1 parent a13bb12 commit 7074f65

File tree

4 files changed

+128
-5
lines changed

4 files changed

+128
-5
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
description: Validates a canonical semantic version (e.g., v1.2.3) with required leading 'v' using the semver.org regex.
2+
3+
inputs:
4+
version:
5+
description: Canonical semantic version (e.g., v1.2.3 or v1.2.3-rc.1)
6+
required: true
7+
8+
runs:
9+
using: composite
10+
steps:
11+
- name: Validate semantic version
12+
shell: python
13+
env:
14+
VERSION: ${{ inputs.version }}
15+
run: |
16+
import os, re, sys
17+
version = os.environ.get("VERSION", "").strip()
18+
pattern = r'^v(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
19+
if not version or not re.fullmatch(pattern, version):
20+
print(f"Error: '{version}' is not a valid canonical SemVer (must start with 'v', e.g., v1.2.3).", file=sys.stderr)
21+
sys.exit(1)
22+
print(f"Valid canonical SemVer: {version}")

.github/workflows/release-snapshot.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Checkout
20-
uses: actions/checkout@v4
20+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2121
with:
2222
fetch-depth: 0
2323

2424
- name: Set up Go
25-
uses: actions/setup-go@v5
25+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
2626
with:
2727
go-version-file: go.mod
2828

2929
- name: Run GoReleaser (snapshot)
30-
uses: goreleaser/goreleaser-action@v6
30+
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
3131
with:
3232
distribution: goreleaser
33-
version: latest
34-
args: release --snapshot --clean --skip-publish
33+
version: "~> v2"
34+
args: release --snapshot --clean --skip=publish
3535
env:
3636
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Version to release, e.g.: v0.1.0"
8+
required: true
9+
type: string
10+
11+
concurrency:
12+
group: release-${{ github.event.inputs.version }}
13+
cancel-in-progress: false
14+
15+
jobs:
16+
validate-version:
17+
name: Validate semantic version
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
steps:
22+
- name: Check out repository
23+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
24+
with:
25+
sparse-checkout: .github/actions/validate-semver
26+
- name: Validate semantic version
27+
uses: ./.github/actions/validate-semver
28+
with:
29+
version: ${{ github.event.inputs.version }}
30+
31+
tests:
32+
uses: ./.github/workflows/tests.yml
33+
34+
release:
35+
name: Release
36+
needs: [validate-version, tests]
37+
runs-on: ubuntu-latest
38+
permissions:
39+
contents: write
40+
steps:
41+
- name: Check out repository
42+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
43+
with:
44+
fetch-depth: 0
45+
- name: Set up Go
46+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
47+
with:
48+
go-version-file: go.mod
49+
- name: Set git identity
50+
run: |
51+
git config user.name "${{ github.actor }}"
52+
git config user.email "${{ github.actor }}@users.noreply.github.com"
53+
- name: Create local tag
54+
run: |
55+
V="${{ github.event.inputs.version }}"
56+
if git rev-parse -q --verify "refs/tags/$V" >/dev/null; then
57+
git tag -d "$V"
58+
fi
59+
git tag -a "$V" -m "$V"
60+
- name: Build artifacts only
61+
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
62+
with:
63+
version: "~> v2"
64+
args: release --skip=publish --clean
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
- name: Push tag
68+
run: |
69+
V="${{ github.event.inputs.version }}"
70+
if git ls-remote --tags origin | grep -qx ".*refs/tags/$V"; then
71+
echo "Tag $V already exists on origin. Aborting." >&2
72+
exit 1
73+
fi
74+
git push origin "$V"
75+
- name: Publish release
76+
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
77+
with:
78+
version: "~> v2"
79+
args: release --clean
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tests.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Tests
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
go-test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check out repository
14+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
15+
- name: Set up Go
16+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
17+
with:
18+
go-version-file: go.mod
19+
- name: Run go test
20+
run: go test ./...

0 commit comments

Comments
 (0)