Skip to content

Commit b1cefe0

Browse files
committed
Add release workflow
1 parent f6966bc commit b1cefe0

1 file changed

Lines changed: 113 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: "Release tag (e.g. v2.0.0). Must match v<major>.<minor>.<patch>[-suffix]."
8+
required: true
9+
type: string
10+
release_notes:
11+
description: "Release notes body (markdown). Optional."
12+
required: false
13+
type: string
14+
15+
permissions:
16+
contents: write
17+
18+
concurrency:
19+
group: release-${{ inputs.tag }}
20+
cancel-in-progress: false
21+
22+
jobs:
23+
validate:
24+
name: Validate inputs
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Check tag format
29+
run: |
30+
echo "${{ inputs.tag }}" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.]+)?$' \
31+
|| { echo "Invalid tag: ${{ inputs.tag }}"; exit 1; }
32+
- name: Ensure tag does not already exist
33+
run: |
34+
if git rev-parse "refs/tags/${{ inputs.tag }}" >/dev/null 2>&1; then
35+
echo "Tag ${{ inputs.tag }} already exists — pick a new one."
36+
exit 1
37+
fi
38+
39+
build:
40+
name: Build ${{ matrix.goos }}/${{ matrix.goarch }}
41+
needs: validate
42+
runs-on: ubuntu-latest
43+
strategy:
44+
fail-fast: true
45+
matrix:
46+
include:
47+
- { goos: linux, goarch: amd64, ext: "" }
48+
- { goos: linux, goarch: arm64, ext: "" }
49+
- { goos: windows, goarch: amd64, ext: ".exe" }
50+
- { goos: windows, goarch: arm64, ext: ".exe" }
51+
- { goos: darwin, goarch: amd64, ext: "" }
52+
- { goos: darwin, goarch: arm64, ext: "" }
53+
steps:
54+
- uses: actions/checkout@v4
55+
56+
- uses: actions/setup-go@v5
57+
with:
58+
go-version-file: "go.mod"
59+
cache: true
60+
61+
- name: Build
62+
env:
63+
GOOS: ${{ matrix.goos }}
64+
GOARCH: ${{ matrix.goarch }}
65+
CGO_ENABLED: "0"
66+
run: |
67+
set -euo pipefail
68+
VERSION="${{ inputs.tag }}"
69+
VERSION_NO_V="${VERSION#v}"
70+
OUT="mssqlhound-${VERSION}-${GOOS}-${GOARCH}${{ matrix.ext }}"
71+
mkdir -p dist
72+
go build -trimpath \
73+
-ldflags "-s -w -X main.version=${VERSION_NO_V}" \
74+
-o "dist/${OUT}" ./cmd/mssqlhound
75+
ls -lh dist/
76+
77+
- uses: actions/upload-artifact@v4
78+
with:
79+
name: mssqlhound-${{ matrix.goos }}-${{ matrix.goarch }}
80+
path: dist/*
81+
if-no-files-found: error
82+
retention-days: 7
83+
84+
release:
85+
name: Create GitHub Release
86+
needs: build
87+
runs-on: ubuntu-latest
88+
steps:
89+
- uses: actions/checkout@v4
90+
91+
- uses: actions/download-artifact@v4
92+
with:
93+
path: dist
94+
merge-multiple: true
95+
96+
- name: Generate SHA256 checksums
97+
working-directory: dist
98+
run: |
99+
sha256sum * > checksums.txt
100+
echo "--- checksums.txt ---"
101+
cat checksums.txt
102+
103+
- name: Create release and upload assets
104+
uses: softprops/action-gh-release@v2
105+
with:
106+
tag_name: ${{ inputs.tag }}
107+
name: ${{ inputs.tag }}
108+
body: ${{ inputs.release_notes }}
109+
target_commitish: ${{ github.sha }}
110+
draft: false
111+
prerelease: false
112+
files: dist/*
113+
fail_on_unmatched_files: true

0 commit comments

Comments
 (0)