-
-
Notifications
You must be signed in to change notification settings - Fork 15
148 lines (127 loc) · 4.24 KB
/
Copy pathrelease.yml
File metadata and controls
148 lines (127 loc) · 4.24 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
name: Release
run-name: ${{ inputs.tag_name }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
permissions:
contents: 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 `
./cmd/pgxcli
- 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
id: extract-release-notes
uses: ffurrer2/extract-release-notes@v3
- name: Write release notes to file
run: |
echo "${{ steps.extract-release-notes.outputs.release_notes }}" > /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 }}
run: 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: |
# upload MSI to the existing draft release
gh release upload "$TAG_NAME" dist/*.msi
# now publish the draft
gh release edit "$TAG_NAME" --draft=false