-
-
Notifications
You must be signed in to change notification settings - Fork 15
188 lines (160 loc) · 6.03 KB
/
Copy pathrelease.yml
File metadata and controls
188 lines (160 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: Release
run-name: ${{ inputs.tag_name }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
permissions:
contents: write
packages: write
on:
workflow_dispatch:
inputs:
tag_name:
required: true
type: string
description: "Release tag (e.g. v0.1.0)"
jobs:
validate-tag:
runs-on: ubuntu-latest
steps:
- name: Validate tag format
env:
TAG_NAME: ${{ inputs.tag_name }}
run: |
if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid tag format. Must be v1.2.3"
exit 1
fi
# ── Job 1: Build MSI on Windows ──────────────────────────────────────
build-msi:
needs: validate-tag
runs-on: windows-2022
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Build Windows binary
env:
TAG_NAME: ${{ inputs.tag_name }}
shell: pwsh
run: |
$VERSION = $env:TAG_NAME -replace '^v', ''
$env:GOOS = "windows"
$env:GOARCH = "amd64"
$env:CGO_ENABLED = "0"
go build `
-ldflags "-s -w -X main.version=$VERSION -X main.commit=$env:GITHUB_SHA" `
-o build/windows/amd64/pgxcli.exe `
- name: Set up MSBuild
id: setupmsbuild
uses: microsoft/setup-msbuild@v2
- name: Build MSI (x64)
env:
TAG_NAME: ${{ inputs.tag_name }}
shell: pwsh
run: |
$VERSION = $env:TAG_NAME -replace '^v', ''
$MSBUILD = "${{ steps.setupmsbuild.outputs.msbuildPath }}\MSBuild.exe"
& $MSBUILD build/windows/pgxcli.wixproj `
-p:Configuration=Release `
-p:Platform=x64 `
-p:SourceDir="$PWD\build\windows\amd64\" `
-p:OutputPath="$PWD\dist" `
-p:OutputName="pgxcli_${VERSION}_windows_amd64" `
-p:ProductVersion="$VERSION"
- name: Upload MSI artifact
uses: actions/upload-artifact@v4
with:
name: windows-msi
if-no-files-found: error
retention-days: 7
path: dist/*.msi
# ── Job 2: GoReleaser draft release ──────────────────────────────────
goreleaser:
needs: validate-tag
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: v2.13.1
install-only: true
- name: Extract release notes
env:
TAG_NAME: ${{ inputs.tag_name }}
run: |
VERSION="${TAG_NAME#v}" # strip the 'v' → 0.1.0
# Escape dots so awk treats them as literals, not regex wildcards
ESCAPED_VERSION=$(echo "$VERSION" | sed 's/\./\\./g')
awk "/^## \[${ESCAPED_VERSION}\]/{found=1; next} /^## \[/{if(found) exit} found{print}" \
CHANGELOG.md \
| sed -e '/./,$!d' -e ':a;/^\n*$/{$d;N;ba}' \
> /tmp/release_notes.md
if [ ! -s /tmp/release_notes.md ]; then
echo "ERROR: No release notes found for version $VERSION in CHANGELOG.md"
echo "Available versions:"
grep '^## \[' CHANGELOG.md
exit 1
fi
echo "--- Release notes preview ---"
cat /tmp/release_notes.md
- name: Create temporary tag
env:
TAG_NAME: ${{ inputs.tag_name }}
run: git tag "$TAG_NAME"
- name: Run GoReleaser (creates draft)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
run: |
# Set up docker buildx for multi-arch builds
docker buildx create --name=goreleaser --use
docker run --privileged --rm tonistiigi/binfmt --install all
# Log in to GitHub Container Registry
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# Log in to Docker Hub (if secrets are provided)
if [ -n "$DOCKER_USERNAME" ] && [ -n "$DOCKER_PASSWORD" ]; then
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
fi
goreleaser release --clean --fail-fast --release-notes /tmp/release_notes.md
# ── Job 3: Upload MSI to draft + publish ─────────────────────────────
publish:
needs: [build-msi, goreleaser]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download MSI artifact
uses: actions/download-artifact@v4
with:
name: windows-msi
path: dist/
- name: Upload MSI to draft release + publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ inputs.tag_name }}
run: |
# Re-extract release notes so gh doesn't wipe the body on edit
VERSION="${TAG_NAME#v}"
ESCAPED_VERSION=$(echo "$VERSION" | sed 's/\./\\./g')
awk "/^## \[${ESCAPED_VERSION}\]/{found=1; next} /^## \[/{if(found) exit} found{print}" \
CHANGELOG.md \
| sed -e '/./,$!d' -e ':a;/^\n*$/{$d;N;ba}' \
> /tmp/release_notes.md
# upload MSI to the existing draft release
gh release upload "$TAG_NAME" dist/*.msi
# publish the draft, preserving the release body
gh release edit "$TAG_NAME" --draft=false --notes-file /tmp/release_notes.md