-
Notifications
You must be signed in to change notification settings - Fork 1
283 lines (250 loc) · 8.41 KB
/
release.yml
File metadata and controls
283 lines (250 loc) · 8.41 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Tag to release (e.g., v1.0.0)'
required: true
type: string
permissions:
contents: write
packages: write
attestations: write
id-token: write
jobs:
# Validate and prepare release
prepare:
name: Prepare Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
previous_tag: ${{ steps.previous.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate tag format
run: |
TAG="${{ github.ref_name }}"
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then
echo "❌ Invalid tag format: $TAG"
echo "Expected format: vX.Y.Z or vX.Y.Z-suffix"
exit 1
fi
echo "✅ Valid tag format: $TAG"
- name: Extract version
id: version
run: |
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}" # Remove 'v' prefix
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "📦 Version: $VERSION"
- name: Get previous tag
id: previous
run: |
CURRENT_TAG="${{ github.ref_name }}"
PREVIOUS_TAG=$(git describe --tags --abbrev=0 "$CURRENT_TAG^" 2>/dev/null || echo "")
echo "tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
if [ -n "$PREVIOUS_TAG" ]; then
echo "📊 Previous tag: $PREVIOUS_TAG"
else
echo "🆕 This is the first release"
fi
# Run full test suite before release
test:
name: Test Release
needs: prepare
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'cli/go.mod'
cache-dependency-path: cli/go.sum
- name: Build test binary
working-directory: cli
run: |
mkdir -p build
go build -o build/ddx .
chmod +x build/ddx
echo "✅ Test binary built at $(pwd)/build/ddx"
- name: Run tests
working-directory: cli
run: |
go test -v ./...
echo "✅ All tests passed - release validated"
# Build binaries for all platforms
build-matrix:
name: Build ${{ matrix.goos }}-${{ matrix.goarch }}
needs: [prepare, test]
strategy:
matrix:
# Fizeau v0.14.32 does not currently cross-compile for Windows
# (github.com/easel/fizeau/internal/discoverycache uses syscall.Kill).
include:
- goos: linux
goarch: amd64
runner: ubuntu-latest
- goos: linux
goarch: arm64
runner: ubuntu-latest
- goos: darwin
goarch: amd64
runner: macos-latest
- goos: darwin
goarch: arm64
runner: macos-latest
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'cli/go.mod'
cache-dependency-path: cli/go.sum
- name: Build binary
working-directory: cli
shell: bash
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
VERSION: ${{ needs.prepare.outputs.version }}
run: |
# Build with version information
LDFLAGS="-X main.version=${VERSION} -X main.commit=${{ github.sha }} -X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
if [ "${{ matrix.goos }}" = "windows" ]; then
go build -ldflags "$LDFLAGS" -o build/ddx.exe .
else
go build -ldflags "$LDFLAGS" -o build/ddx .
fi
- name: Create archive
working-directory: cli/build
shell: bash
run: |
BINARY="ddx"
if [ "${{ matrix.goos }}" = "windows" ]; then
BINARY="ddx.exe"
fi
# Create archive name
ARCHIVE="ddx-${{ matrix.goos }}-${{ matrix.goarch }}"
# Add version and README to archive
echo "DDx v${{ needs.prepare.outputs.version }}" > VERSION
echo "Platform: ${{ matrix.goos }}-${{ matrix.goarch }}" >> VERSION
echo "Built: $(date -u +%Y-%m-%dT%H:%M:%SZ)" >> VERSION
echo "Commit: ${{ github.sha }}" >> VERSION
# Create appropriate archive
if [ "${{ matrix.goos }}" = "windows" ]; then
# Windows: Create ZIP
if command -v zip >/dev/null; then
zip "${ARCHIVE}.zip" "$BINARY" VERSION
else
# Fallback for Windows runner
7z a "${ARCHIVE}.zip" "$BINARY" VERSION
fi
echo "📦 Created ${ARCHIVE}.zip"
else
# Unix: Create tar.gz
tar -czf "${ARCHIVE}.tar.gz" "$BINARY" VERSION
echo "📦 Created ${ARCHIVE}.tar.gz"
fi
# Generate checksums
if [ "${{ matrix.goos }}" = "windows" ]; then
sha256sum "${ARCHIVE}.zip" > "${ARCHIVE}.zip.sha256"
else
sha256sum "${ARCHIVE}.tar.gz" > "${ARCHIVE}.tar.gz.sha256"
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
cli/build/*.tar.gz
cli/build/*.zip
cli/build/*.sha256
retention-days: 1
# Create GitHub release with all artifacts
release:
name: Create Release
needs: [prepare, build-matrix]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
pattern: release-*
path: ./artifacts
merge-multiple: true
- name: Generate changelog
id: changelog
run: |
PREVIOUS_TAG="${{ needs.prepare.outputs.previous_tag }}"
# Generate changelog
if [ -z "$PREVIOUS_TAG" ]; then
COMMITS=$(git log --pretty=format:"- %s (%an)" --no-merges)
else
COMMITS=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"- %s (%an)" --no-merges)
fi
# Categorize commits
echo "# Changelog" > CHANGELOG.md
echo "" >> CHANGELOG.md
# Features
FEATURES=$(echo "$COMMITS" | grep -E "^- (feat|feature):" || true)
if [ -n "$FEATURES" ]; then
echo "## 🚀 Features" >> CHANGELOG.md
echo "$FEATURES" | sed 's/^- feat:/- /g' | sed 's/^- feature:/- /g' >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
# Bug fixes
FIXES=$(echo "$COMMITS" | grep -E "^- (fix|bugfix):" || true)
if [ -n "$FIXES" ]; then
echo "## 🐛 Bug Fixes" >> CHANGELOG.md
echo "$FIXES" | sed 's/^- fix:/- /g' | sed 's/^- bugfix:/- /g' >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
# Documentation
DOCS=$(echo "$COMMITS" | grep -E "^- (docs|doc):" || true)
if [ -n "$DOCS" ]; then
echo "## 📚 Documentation" >> CHANGELOG.md
echo "$DOCS" | sed 's/^- docs:/- /g' | sed 's/^- doc:/- /g' >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
# Other changes
OTHERS=$(echo "$COMMITS" | grep -vE "^- (feat|feature|fix|bugfix|docs|doc):" || true)
if [ -n "$OTHERS" ]; then
echo "## 🔧 Other Changes" >> CHANGELOG.md
echo "$OTHERS" >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
# Output for release body
cat CHANGELOG.md
- name: Create checksums file
run: |
cd artifacts
find . -maxdepth 1 -type f \( -name '*.tar.gz' -o -name '*.zip' \) -print0 \
| sort -z \
| xargs -0 sha256sum > checksums.sha256
test -s checksums.sha256
echo "📝 Generated checksums for all artifacts"
- name: Create Release
uses: softprops/action-gh-release@v2
with:
name: DDx ${{ github.ref_name }}
body_path: CHANGELOG.md
files: |
artifacts/*
draft: false
prerelease: ${{ contains(github.ref_name, '-') }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update installation script
run: |
echo "✅ Release ${{ github.ref_name }} created successfully!"
echo "📦 Available at: https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}"