Skip to content

Commit d923418

Browse files
committed
ci: add GitHub release automation
- run go test on pull requests and pushes to main with current stable GitHub actions - cut semantic version tags from a manual workflow and publish tagged binaries through GoReleaser - track action updates with Dependabot and generate GitHub-native release notes
1 parent bc3612e commit d923418

5 files changed

Lines changed: 205 additions & 0 deletions

File tree

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: weekly

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v6.0.2
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v6.1.0
22+
with:
23+
go-version-file: go.mod
24+
cache: true
25+
26+
- name: Run tests
27+
run: go test ./...

.github/workflows/cut-release.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Cut Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
bump:
7+
description: Semantic version increment for the next release tag
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
15+
permissions:
16+
contents: write
17+
18+
concurrency:
19+
group: cut-release
20+
cancel-in-progress: false
21+
22+
jobs:
23+
tag:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Ensure the workflow runs from main
28+
run: |
29+
if [ "${GITHUB_REF_NAME}" != "main" ]; then
30+
echo "This workflow must be run from main, got ${GITHUB_REF_NAME}." >&2
31+
exit 1
32+
fi
33+
34+
- name: Checkout
35+
uses: actions/checkout@v6.0.2
36+
with:
37+
fetch-depth: 0
38+
39+
- name: Determine next release tag
40+
id: next
41+
env:
42+
BUMP: ${{ inputs.bump }}
43+
run: |
44+
set -euo pipefail
45+
46+
latest_tag="$(git tag --list 'v*' --sort=-v:refname | awk '/^v[0-9]+\.[0-9]+\.[0-9]+$/ { print; exit }')"
47+
48+
if [ -z "${latest_tag}" ]; then
49+
next_tag="v0.1.0"
50+
else
51+
version="${latest_tag#v}"
52+
IFS='.' read -r major minor patch <<<"${version}"
53+
54+
case "${BUMP}" in
55+
patch)
56+
patch=$((patch + 1))
57+
;;
58+
minor)
59+
minor=$((minor + 1))
60+
patch=0
61+
;;
62+
major)
63+
major=$((major + 1))
64+
minor=0
65+
patch=0
66+
;;
67+
*)
68+
echo "Unsupported bump: ${BUMP}" >&2
69+
exit 1
70+
;;
71+
esac
72+
73+
next_tag="v${major}.${minor}.${patch}"
74+
fi
75+
76+
echo "tag=${next_tag}" >> "${GITHUB_OUTPUT}"
77+
78+
- name: Create annotated tag
79+
env:
80+
TAG: ${{ steps.next.outputs.tag }}
81+
run: |
82+
set -euo pipefail
83+
84+
if git rev-parse "${TAG}" >/dev/null 2>&1; then
85+
echo "Tag ${TAG} already exists." >&2
86+
exit 1
87+
fi
88+
89+
git config user.name "github-actions[bot]"
90+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
91+
git tag -a "${TAG}" -m "Release ${TAG}"
92+
git push origin "${TAG}"

.github/workflows/release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v6.0.2
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v6.1.0
23+
with:
24+
go-version-file: go.mod
25+
cache: true
26+
27+
- name: Run GoReleaser
28+
uses: goreleaser/goreleaser-action@v7.0.0
29+
with:
30+
distribution: goreleaser
31+
version: "~> v2"
32+
args: release --clean
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: 2
2+
3+
project_name: stardrive
4+
5+
builds:
6+
- id: stardrive
7+
main: .
8+
binary: stardrive
9+
env:
10+
- CGO_ENABLED=0
11+
goos:
12+
- linux
13+
- darwin
14+
- windows
15+
goarch:
16+
- amd64
17+
- arm64
18+
ldflags:
19+
- >-
20+
-s -w
21+
-X github.com/intar-dev/stardrive/internal/buildinfo.Version={{ .Version }}
22+
-X github.com/intar-dev/stardrive/internal/buildinfo.Commit={{ .Commit }}
23+
-X github.com/intar-dev/stardrive/internal/buildinfo.Date={{ .Date }}
24+
25+
archives:
26+
- id: stardrive
27+
ids:
28+
- stardrive
29+
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
30+
formats:
31+
- tar.gz
32+
format_overrides:
33+
- goos: windows
34+
formats:
35+
- zip
36+
files:
37+
- none*
38+
39+
checksum:
40+
name_template: "{{ .ProjectName }}_{{ .Version }}_checksums.txt"
41+
42+
changelog:
43+
use: github-native
44+
45+
release:
46+
draft: false

0 commit comments

Comments
 (0)