-
Notifications
You must be signed in to change notification settings - Fork 2
308 lines (256 loc) · 9.15 KB
/
Copy pathrelease.yml
File metadata and controls
308 lines (256 loc) · 9.15 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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: "Release version (e.g., 1.0.0)"
required: true
type: string
prerelease:
description: "Mark as pre-release"
required: false
type: boolean
default: false
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
validate:
name: Validate Release
runs-on: macos-15
outputs:
version: ${{ steps.version.outputs.version }}
is_prerelease: ${{ steps.version.outputs.is_prerelease }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine version
id: version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
IS_PRERELEASE="${{ github.event.inputs.prerelease }}"
else
VERSION=${GITHUB_REF#refs/tags/v}
if [[ $VERSION == *"alpha"* ]] || [[ $VERSION == *"beta"* ]] || [[ $VERSION == *"rc"* ]]; then
IS_PRERELEASE=true
else
IS_PRERELEASE=false
fi
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "is_prerelease=$IS_PRERELEASE" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
echo "Is pre-release: $IS_PRERELEASE"
- name: Setup Xcode
if: runner.os == 'macOS'
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "26.1"
- name: Setup Swift
run: |
if [[ "$RUNNER_OS" == "Linux" ]]; then
# Install dependencies for Swiftly
sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev pkg-config python3-lldb-13
# Install Swiftly
curl -O https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz
tar zxf swiftly-$(uname -m).tar.gz
./swiftly init --verbose --assume-yes --skip-install
. ~/.local/share/swiftly/env.sh
# Install Swift
swiftly install 6.2
echo "$(dirname $(which swift))" >> $GITHUB_PATH
else
# macOS - use Xcode's Swift
echo "Using Xcode's Swift on macOS"
xcode-select --print-path
fi
swift --version
- name: Build and test
run: |
swift build --configuration release
swift test
build-artifacts:
name: Build Release Artifacts
needs: validate
strategy:
matrix:
include:
- os: macos-15
arch: arm64
platform: macos
- os: macos-15
arch: x86_64
platform: macos
- os: ubuntu-22.04
arch: x86_64
platform: linux
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Xcode
if: runner.os == 'macOS'
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "26.1"
- name: Setup Swift
run: |
if [[ "$RUNNER_OS" == "Linux" ]]; then
# Install dependencies for Swiftly
sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev pkg-config python3-lldb-13
# Install Swiftly
curl -O https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz
tar zxf swiftly-$(uname -m).tar.gz
./swiftly init --verbose --assume-yes --skip-install
. ~/.local/share/swiftly/env.sh
# Install Swift
swiftly install 6.2
echo "$(dirname $(which swift))" >> $GITHUB_PATH
else
# macOS - use Xcode's Swift
echo "Using Xcode's Swift on macOS"
xcode-select --print-path
fi
swift --version
- name: Build for ${{ matrix.platform }}-${{ matrix.arch }}
run: |
if [ "${{ matrix.platform }}" = "macos" ]; then
swift build \
--configuration release \
--arch ${{ matrix.arch }} \
--product SwiftComplexityCLI
else
swift build \
--configuration release \
--product SwiftComplexityCLI
fi
- name: Create archive
run: |
PRODUCT_NAME="SwiftComplexityCLI"
VERSION="${{ needs.validate.outputs.version }}"
ARCH="${{ matrix.arch }}"
PLATFORM="${{ matrix.platform }}"
ARCHIVE_NAME="${PRODUCT_NAME}-${VERSION}-${PLATFORM}-${ARCH}"
mkdir -p "artifacts/${ARCHIVE_NAME}"
# Copy binary
cp ".build/release/${PRODUCT_NAME}" "artifacts/${ARCHIVE_NAME}/"
# Copy documentation
cp README.md "artifacts/${ARCHIVE_NAME}/"
cp -r docs "artifacts/${ARCHIVE_NAME}/"
# Create install script
cat > "artifacts/${ARCHIVE_NAME}/install.sh" << 'EOF'
#!/bin/bash
set -e
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
cp SwiftComplexityCLI "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/SwiftComplexityCLI"
echo "SwiftComplexityCLI installed to $INSTALL_DIR"
echo "Make sure $INSTALL_DIR is in your PATH"
EOF
chmod +x "artifacts/${ARCHIVE_NAME}/install.sh"
# Create tarball
cd artifacts
tar -czf "${ARCHIVE_NAME}.tar.gz" "${ARCHIVE_NAME}"
# Generate checksums
shasum -a 256 "${ARCHIVE_NAME}.tar.gz" > "${ARCHIVE_NAME}.tar.gz.sha256"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: swift-complexity-${{ matrix.platform }}-${{ matrix.arch }}
path: artifacts/*.tar.gz*
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [validate, build-artifacts]
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: swift-complexity-*-*
merge-multiple: true
path: ./artifacts
- name: Generate release notes
id: release_notes
run: |
VERSION="${{ needs.validate.outputs.version }}"
# Generate changelog from git commits
# Get the previous tag, excluding the current release tag
PREVIOUS_TAG=$(git tag --list "v*" --sort=-version:refname | grep -v "^v${VERSION}$" | head -1)
if [[ -n "$PREVIOUS_TAG" ]]; then
COMMITS=$(git log --pretty=format:"- %s (%h)" ${PREVIOUS_TAG}..HEAD)
else
# No previous tags found, use recent commits
COMMITS=$(git log --pretty=format:"- %s (%h)" HEAD~10..HEAD)
fi
cat > release_notes.md << EOF
## What's Changed
${COMMITS}
## Installation
### Download Pre-built Binary
1. Download the appropriate binary for your platform and architecture:
- **macOS Apple Silicon (M1/M2/M3)**: \`swift-complexity-${VERSION}-macos-arm64.tar.gz\`
- **macOS Intel**: \`swift-complexity-${VERSION}-macos-x86_64.tar.gz\`
- **Linux x86_64**: \`swift-complexity-${VERSION}-linux-x86_64.tar.gz\`
2. Extract and install:
\`\`\`bash
# Extract the downloaded archive
tar -xzf swift-complexity-${VERSION}-*.tar.gz
cd swift-complexity-${VERSION}-*
./install.sh
\`\`\`
### Build from Source
\`\`\`bash
git clone https://github.com/\${{ github.repository }}.git
cd swift-complexity
git checkout v${VERSION}
swift build -c release
\`\`\`
## Verification
All binaries are signed and checksums are provided for verification.
\`\`\`bash
# Verify checksum (example for macOS)
shasum -a 256 -c swift-complexity-${VERSION}-*.tar.gz.sha256
\`\`\`
EOF
echo "Generated release notes:"
cat release_notes.md
- name: Create release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.validate.outputs.version }}
name: v${{ needs.validate.outputs.version }}
body_path: release_notes.md
draft: false
prerelease: ${{ needs.validate.outputs.is_prerelease == 'true' }}
files: |
artifacts/*.tar.gz
artifacts/*.sha256
generate_release_notes: true
notify:
name: Notify Release
runs-on: ubuntu-latest
needs: [validate, create-release]
if: always()
steps:
- name: Notify on success
if: needs.create-release.result == 'success'
run: |
echo "✅ Release v${{ needs.validate.outputs.version }} created successfully!"
- name: Notify on failure
if: needs.create-release.result == 'failure'
run: |
echo "❌ Release v${{ needs.validate.outputs.version }} failed!"
exit 1