-
Notifications
You must be signed in to change notification settings - Fork 2
455 lines (392 loc) · 16 KB
/
release.yml
File metadata and controls
455 lines (392 loc) · 16 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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
name: Release
on:
push:
tags:
- 'v*' # Trigger on version tags like v1.0.0
workflow_dispatch: # Allow manual triggering
permissions:
contents: write # Required for creating releases and uploading assets
env:
CARGO_TERM_COLOR: always
jobs:
create-release:
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for changelog generation
- name: Get version from tag
id: get_version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
VERSION="dev-$(git rev-parse --short HEAD)"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Generate changelog
id: changelog
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
# Get previous tag
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREV_TAG" ]; then
CHANGELOG=$(git log --pretty=format:"- %s" $PREV_TAG..HEAD)
else
CHANGELOG=$(git log --pretty=format:"- %s" HEAD)
fi
else
CHANGELOG="Development build from commit $(git rev-parse --short HEAD)"
fi
# Save changelog to environment variable
{
echo 'CHANGELOG<<EOF'
if [ -n "$CHANGELOG" ]; then
echo "$CHANGELOG"
else
echo "No changes since last release"
fi
echo EOF
} >> $GITHUB_ENV
- name: Create Release
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Determine if this is a prerelease
PRERELEASE=""
if [[ "${{ github.ref_name }}" == *"alpha"* ]] || \
[[ "${{ github.ref_name }}" == *"beta"* ]] || \
[[ "${{ github.ref_name }}" == *"rc"* ]]; then
PRERELEASE="--prerelease"
fi
# Create release using gh CLI
RELEASE_URL=$(gh release create "${{ github.ref_name }}" \
--title "SmartCrawler ${{ steps.get_version.outputs.version }}" \
--notes "$CHANGELOG" \
$PRERELEASE \
--repo "${{ github.repository }}")
echo "upload_url=$RELEASE_URL" >> $GITHUB_OUTPUT
build-release:
name: Build Release
needs: create-release
strategy:
fail-fast: false
matrix:
include:
# Linux x86_64
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: smart-crawler-linux-x64
archive: tar.gz
# Linux ARM64
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
name: smart-crawler-linux-arm64
archive: tar.gz
# macOS x86_64
- target: x86_64-apple-darwin
os: macos-latest
name: smart-crawler-macos-x64
archive: tar.gz
# macOS ARM64 (Apple Silicon)
- target: aarch64-apple-darwin
os: macos-latest
name: smart-crawler-macos-arm64
archive: tar.gz
# Windows x86_64
- target: x86_64-pc-windows-msvc
os: windows-latest
name: smart-crawler-windows-x64
archive: zip
extension: .exe
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross-compilation tools (Linux ARM64)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.target }}-cargo-
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }} --verbose
- name: Prepare binary
shell: bash
run: |
cd target/${{ matrix.target }}/release
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
BINARY="smart-crawler.exe"
else
BINARY="smart-crawler"
fi
# Strip binary on Unix systems with appropriate tool
if [[ "${{ matrix.os }}" != "windows-latest" ]]; then
echo "Stripping binary for target: ${{ matrix.target }}"
case "${{ matrix.target }}" in
aarch64-unknown-linux-gnu)
if command -v aarch64-linux-gnu-strip >/dev/null 2>&1; then
aarch64-linux-gnu-strip $BINARY
echo "Successfully stripped with aarch64-linux-gnu-strip"
else
echo "Warning: aarch64-linux-gnu-strip not found, skipping strip"
fi
;;
x86_64-unknown-linux-gnu)
strip $BINARY
echo "Successfully stripped with strip"
;;
x86_64-apple-darwin|aarch64-apple-darwin)
strip $BINARY
echo "Successfully stripped with strip"
;;
*)
echo "Warning: No strip tool configured for target ${{ matrix.target }}, skipping strip"
;;
esac
fi
# Create archive
if [[ "${{ matrix.archive }}" == "zip" ]]; then
7z a ../../../${{ matrix.name }}-${{ needs.create-release.outputs.version }}.${{ matrix.archive }} $BINARY
else
tar czf ../../../${{ matrix.name }}-${{ needs.create-release.outputs.version }}.${{ matrix.archive }} $BINARY
fi
- name: Upload Release Asset
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ github.ref_name }} \
${{ matrix.name }}-${{ needs.create-release.outputs.version }}.${{ matrix.archive }} \
--repo "${{ github.repository }}"
build-installers:
name: Build Native Installers
needs: [create-release, build-release]
strategy:
fail-fast: false
matrix:
include:
# Windows MSI installer
- target: x86_64-pc-windows-msvc
os: windows-latest
installer: msi
# macOS DMG installer
- target: x86_64-apple-darwin
os: macos-latest
installer: dmg
# Linux DEB package
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
installer: deb
# Linux RPM package
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
installer: rpm
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.target }}-cargo-
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
- name: Verify binary exists
shell: bash
run: |
BINARY_PATH="target/${{ matrix.target }}/release/smart-crawler"
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
BINARY_PATH="${BINARY_PATH}.exe"
fi
if [ ! -f "$BINARY_PATH" ]; then
echo "Error: Binary not found at $BINARY_PATH"
ls -la target/${{ matrix.target }}/release/
exit 1
else
echo "✓ Binary found at $BINARY_PATH"
ls -la "$BINARY_PATH"
fi
# Windows MSI Installer
- name: Install WiX Toolset (Windows)
if: matrix.installer == 'msi'
run: |
Invoke-WebRequest -Uri "https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip" -OutFile "wix311-binaries.zip"
Expand-Archive -Path "wix311-binaries.zip" -DestinationPath "wix311"
echo "$env:GITHUB_WORKSPACE\wix311" | Add-Content -Path $env:GITHUB_PATH
- name: Install cargo-wix (Windows)
if: matrix.installer == 'msi'
run: cargo install cargo-wix
- name: Build MSI installer
if: matrix.installer == 'msi'
run: |
echo "Building MSI installer for ${{ matrix.target }}"
# Initialize cargo-wix if no wix directory exists
if (!(Test-Path "wix")) {
echo "Initializing cargo-wix..."
cargo wix init --force
}
# Build the MSI installer
echo "Building MSI package..."
cargo wix --target ${{ matrix.target }} --output smart-crawler-${{ needs.create-release.outputs.version }}.msi
# Verify the MSI was created
if (Test-Path "smart-crawler-${{ needs.create-release.outputs.version }}.msi") {
echo "✓ MSI installer created successfully"
Get-Item "smart-crawler-${{ needs.create-release.outputs.version }}.msi"
} else {
echo "Error: MSI installer not found"
exit 1
}
# macOS DMG Installer
- name: Install create-dmg (macOS)
if: matrix.installer == 'dmg'
run: brew install create-dmg
- name: Build DMG installer
if: matrix.installer == 'dmg'
run: |
# Create DMG contents directory
mkdir -p dmg-contents
cp target/${{ matrix.target }}/release/smart-crawler dmg-contents/
# Create a simple README for installation
cat > dmg-contents/INSTALL.txt << 'EOF'
SmartCrawler Installation
To install SmartCrawler:
1. Copy the 'smart-crawler' binary to /usr/local/bin/
2. Make it executable: chmod +x /usr/local/bin/smart-crawler
3. Run from terminal: smart-crawler --help
EOF
# Create DMG without app-drop-link (not needed for CLI tools)
echo "Creating DMG package..."
create-dmg \
--volname "SmartCrawler" \
--window-pos 200 120 \
--window-size 600 400 \
--icon-size 80 \
--hide-extension "smart-crawler" \
"smart-crawler-${{ needs.create-release.outputs.version }}.dmg" \
"dmg-contents/" || {
echo "create-dmg failed, using fallback method..."
# Fallback: create simple DMG if create-dmg fails
hdiutil create -format UDZO -srcfolder dmg-contents "smart-crawler-${{ needs.create-release.outputs.version }}.dmg"
}
# Verify the DMG was created
if [ -f "smart-crawler-${{ needs.create-release.outputs.version }}.dmg" ]; then
echo "✓ DMG package created successfully"
ls -la smart-crawler-${{ needs.create-release.outputs.version }}.dmg
else
echo "Error: DMG package not found"
exit 1
fi
# Linux DEB Package
- name: Install cargo-deb (Linux DEB)
if: matrix.installer == 'deb'
run: cargo install cargo-deb
- name: Build DEB package
if: matrix.installer == 'deb'
run: |
echo "Building DEB package for ${{ matrix.target }}"
# Build the DEB package
cargo deb --target ${{ matrix.target }}
# Copy and verify the DEB package
cp target/${{ matrix.target }}/debian/*.deb smart-crawler-${{ needs.create-release.outputs.version }}.deb
if [ -f "smart-crawler-${{ needs.create-release.outputs.version }}.deb" ]; then
echo "✓ DEB package created successfully"
ls -la smart-crawler-${{ needs.create-release.outputs.version }}.deb
else
echo "Error: DEB package not found"
ls -la target/${{ matrix.target }}/debian/
exit 1
fi
# Linux RPM Package
- name: Install cargo-rpm (Linux RPM)
if: matrix.installer == 'rpm'
run: |
sudo apt-get update
sudo apt-get install -y rpm
cargo install cargo-rpm
- name: Build RPM package
if: matrix.installer == 'rpm'
run: |
echo "Building RPM package for ${{ matrix.target }}"
# Initialize cargo-rpm if no .rpm directory exists
if [ ! -d ".rpm" ]; then
echo "Initializing cargo-rpm..."
cargo rpm init
fi
# Build the RPM package
echo "Building RPM package..."
cargo rpm build --target ${{ matrix.target }}
# Find and copy the RPM package (cargo-rpm output location varies)
echo "Searching for generated RPM package..."
# List all possible locations for debugging
echo "Directory structure after build:"
find target/ -name "*.rpm" -type f 2>/dev/null || true
# Try different common cargo-rpm output locations
RPM_FILE=""
# Check standard RPM location
if [ -d "target/rpm/RPMS/x86_64" ] && [ "$(ls -A target/rpm/RPMS/x86_64/*.rpm 2>/dev/null)" ]; then
RPM_FILE=$(ls target/rpm/RPMS/x86_64/*.rpm | head -1)
echo "Found RPM in standard location: $RPM_FILE"
# Check generate-rpm location
elif [ -d "target/generate-rpm" ] && [ "$(ls -A target/generate-rpm/*.rpm 2>/dev/null)" ]; then
RPM_FILE=$(ls target/generate-rpm/*.rpm | head -1)
echo "Found RPM in generate-rpm location: $RPM_FILE"
# Check target/rpm directly
elif [ -d "target/rpm" ] && [ "$(ls -A target/rpm/*.rpm 2>/dev/null)" ]; then
RPM_FILE=$(ls target/rpm/*.rpm | head -1)
echo "Found RPM in target/rpm: $RPM_FILE"
else
# Use find as fallback to locate any .rpm file
RPM_FILE=$(find target/ -name "*.rpm" -type f | head -1)
if [ -n "$RPM_FILE" ]; then
echo "Found RPM using find: $RPM_FILE"
fi
fi
if [ -n "$RPM_FILE" ] && [ -f "$RPM_FILE" ]; then
cp "$RPM_FILE" smart-crawler-${{ needs.create-release.outputs.version }}.rpm
echo "✓ RPM package created successfully"
ls -la smart-crawler-${{ needs.create-release.outputs.version }}.rpm
else
echo "Error: RPM package not found in any expected location"
echo "Available files in target directory:"
find target/ -type f -name "*.rpm" 2>/dev/null || echo "No .rpm files found"
exit 1
fi
- name: Upload Installer
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ github.ref_name }} \
smart-crawler-${{ needs.create-release.outputs.version }}.${{ matrix.installer }} \
--repo "${{ github.repository }}"