-
Notifications
You must be signed in to change notification settings - Fork 0
382 lines (319 loc) · 13.3 KB
/
Copy pathautomated-release.yml
File metadata and controls
382 lines (319 loc) · 13.3 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
# Automated Release Workflow - Builds and commits packages to repository
name: Automated Release
# Triggers on push to Main branch and manual dispatch
on:
push:
branches: [ Main ]
paths-ignore:
- 'releases/**' # Don't trigger on release commits
- '*.md' # Don't trigger on documentation changes
- '.gitignore'
workflow_dispatch:
inputs:
force_rebuild:
description: 'Force rebuild even if version exists'
type: boolean
default: false
jobs:
# First job: Extract version and check if we need to build
check-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
should_build: ${{ steps.check_exists.outputs.should_build }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Extract version from Cargo.toml
id: get_version
run: |
VERSION=$(grep '^version =' Cargo.toml | head -n 1 | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Detected version: $VERSION"
- name: Check if version already exists
id: check_exists
run: |
VERSION="${{ steps.get_version.outputs.version }}"
FORCE_REBUILD="${{ github.event.inputs.force_rebuild }}"
if [[ -d "releases/v$VERSION" && "$FORCE_REBUILD" != "true" ]]; then
echo "should_build=false" >> $GITHUB_OUTPUT
echo "Version v$VERSION already exists in releases and force_rebuild is not set"
else
echo "should_build=true" >> $GITHUB_OUTPUT
echo "Building version v$VERSION (force_rebuild: $FORCE_REBUILD)"
fi
# Build jobs (run in parallel if we need to build)
build-windows:
needs: check-version
if: needs.check-version.outputs.should_build == 'true'
runs-on: windows-latest
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
VCPKG_ROOT: C:\vcpkg
OPENSSL_DIR: C:/vcpkg/installed/x64-windows-static
OPENSSL_STATIC: 1
OPENSSL_LIB_DIR: C:/vcpkg/installed/x64-windows-static/lib
OPENSSL_INCLUDE_DIR: C:/vcpkg/installed/x64-windows-static/include
CMAKE_TOOLCHAIN_FILE: C:/vcpkg/scripts/buildsystems/vcpkg.cmake
steps:
- uses: actions/checkout@v3
- name: Cache vcpkg
uses: actions/cache@v3
with:
path: C:/vcpkg/installed
key: windows-vcpkg-${{ hashFiles('**/Cargo.lock') }}
restore-keys: windows-vcpkg-
- name: Install Dependencies
shell: pwsh
run: |
vcpkg integrate install
vcpkg install openssl:x64-windows-static
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: x86_64-pc-windows-msvc
profile: minimal
override: true
- name: Build Release
shell: pwsh
run: |
$env:CARGO_TARGET_DIR = Join-Path (Get-Location) "target"
cargo build --release --target x86_64-pc-windows-msvc --verbose
- name: Create Windows Release Package
shell: pwsh
run: |
$VERSION = "${{ needs.check-version.outputs.version }}"
New-Item -Path "package-windows" -ItemType Directory -Force
# Copy binary
Copy-Item "target/x86_64-pc-windows-msvc/release/DSvClient.exe" "package-windows/"
# Copy config files
Copy-Item "config.toml" "package-windows/"
Copy-Item "sources.toml" "package-windows/"
# Create version info file
@"
DSvClient Windows Release
Version: $VERSION
Platform: Windows x64
Built: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss UTC')
Commit: ${{ github.sha }}
"@ | Out-File -FilePath "package-windows/VERSION.txt" -Encoding UTF8
# Create README
@"
# DSvClient Windows Release v$VERSION
## Files included:
- DSvClient.exe - The main executable
- config.toml - Configuration file (customize as needed)
- sources.toml - Sources configuration (add your sources here)
- VERSION.txt - Build information
## Usage:
1. Edit config.toml to customize settings
2. Edit sources.toml to add your download sources
3. Run: .\DSvClient.exe <download_path>
For more information, visit: https://github.com/MichaelRyom/DSvClient
"@ | Out-File -FilePath "package-windows/README.md" -Encoding UTF8
- name: Upload Windows Package
uses: actions/upload-artifact@v4
with:
name: windows-package
path: package-windows/
retention-days: 1
build-linux:
needs: check-version
if: needs.check-version.outputs.should_build == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libssl-dev
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: x86_64-unknown-linux-gnu
profile: minimal
override: true
- name: Build Release
uses: houseabsolute/actions-rust-cross@v0
with:
target: x86_64-unknown-linux-gnu
args: "--release"
strip: true
- name: Create Linux Release Package
run: |
VERSION="${{ needs.check-version.outputs.version }}"
mkdir -p package-linux
# Copy binary
cp target/x86_64-unknown-linux-gnu/release/DSvClient package-linux/
chmod +x package-linux/DSvClient
# Copy config files
cp config.toml package-linux/
cp sources.toml package-linux/
# Create version info file
cat > package-linux/VERSION.txt << EOF
DSvClient Linux Release
Version: $VERSION
Platform: Linux x64
Built: $(date -u '+%Y-%m-%d %H:%M:%S UTC')
Commit: ${{ github.sha }}
EOF
# Create README
cat > package-linux/README.md << EOF
# DSvClient Linux Release v$VERSION
## Files included:
- DSvClient - The main executable
- config.toml - Configuration file (customize as needed)
- sources.toml - Sources configuration (add your sources here)
- VERSION.txt - Build information
## Usage:
1. Make executable: \`chmod +x DSvClient\`
2. Edit config.toml to customize settings
3. Edit sources.toml to add your download sources
4. Run: \`./DSvClient <download_path>\`
For more information, visit: https://github.com/MichaelRyom/DSvClient
EOF
- name: Upload Linux Package
uses: actions/upload-artifact@v4
with:
name: linux-package
path: package-linux/
retention-days: 1
# Job to commit all packages to the repository
commit-releases:
needs: [check-version, build-windows, build-linux]
if: needs.check-version.outputs.should_build == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Download all packages
uses: actions/download-artifact@v4
with:
path: artifacts/
- name: Organize releases
run: |
VERSION="${{ needs.check-version.outputs.version }}"
# Create version-specific directory
mkdir -p "releases/v$VERSION"
# Copy each platform package
if [ -d "artifacts/windows-package" ]; then
mkdir -p "releases/v$VERSION/windows"
cp -r artifacts/windows-package/* "releases/v$VERSION/windows/"
fi
if [ -d "artifacts/linux-package" ]; then
mkdir -p "releases/v$VERSION/linux"
cp -r artifacts/linux-package/* "releases/v$VERSION/linux/"
fi
if [ -d "artifacts/macos-package" ]; then
mkdir -p "releases/v$VERSION/macos"
cp -r artifacts/macos-package/* "releases/v$VERSION/macos/"
fi
# Create release info
cat > "releases/v$VERSION/RELEASE_INFO.md" << EOF
# DSvClient Release v$VERSION
**Release Date:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')
**Commit:** ${{ github.sha }}
**Branch:** ${{ github.ref_name }}
## Available Platforms
EOF
# Add platform info
for platform in windows linux macos; do
if [ -d "releases/v$VERSION/$platform" ]; then
echo "- **$platform**: \`releases/v$VERSION/$platform/\`" >> "releases/v$VERSION/RELEASE_INFO.md"
fi
done
echo "" >> "releases/v$VERSION/RELEASE_INFO.md"
echo "## Usage" >> "releases/v$VERSION/RELEASE_INFO.md"
echo "Download the appropriate platform package and follow the README.md instructions in each platform folder." >> "releases/v$VERSION/RELEASE_INFO.md"
- name: Update latest symlink
run: |
VERSION="${{ needs.check-version.outputs.version }}"
# Remove old latest directory if it exists
rm -rf releases/latest
# Create new latest directory as a copy (not symlink for better GitHub compatibility)
cp -r "releases/v$VERSION" releases/latest
# Update the release info for latest
sed "s/v$VERSION/latest (v$VERSION)/" "releases/v$VERSION/RELEASE_INFO.md" > releases/latest/RELEASE_INFO.md
- name: Create releases index
run: |
echo "# DSvClient Releases" > releases/README.md
echo "" >> releases/README.md
echo "This directory contains all released versions of DSvClient." >> releases/README.md
echo "" >> releases/README.md
echo "## Available Releases" >> releases/README.md
echo "" >> releases/README.md
# List all version directories
for version_dir in releases/v*; do
if [ -d "$version_dir" ]; then
version=$(basename "$version_dir")
echo "- **$version**: [\`releases/$version/\`](./$version/)" >> releases/README.md
fi
done
echo "" >> releases/README.md
echo "## Latest Release" >> releases/README.md
echo "" >> releases/README.md
echo "- **latest**: [\`releases/latest/\`](./latest/) - Points to the most recent release" >> releases/README.md
echo "" >> releases/README.md
echo "## Platform Support" >> releases/README.md
echo "" >> releases/README.md
echo "Each release includes packages for:" >> releases/README.md
echo "- Windows (x64)" >> releases/README.md
echo "- Linux (x64)" >> releases/README.md
- name: Commit and push releases
run: |
VERSION="${{ needs.check-version.outputs.version }}"
git add releases/
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "🚀 Release v$VERSION - Add build artifacts for Windows and Linux
- Windows x64 package: releases/v$VERSION/windows/
- Linux x64 package: releases/v$VERSION/linux/
- Updated latest symlink to point to v$VERSION
Built from commit: ${{ github.sha }}"
# Retry push with pull if needed (handle race conditions)
for i in {1..3}; do
if git push origin Main; then
echo "Successfully pushed on attempt $i"
break
else
echo "Push failed on attempt $i, trying to pull and rebase..."
if [ $i -lt 3 ]; then
git pull --rebase origin Main
# Check if rebase was successful
if [ $? -ne 0 ]; then
echo "Rebase failed, aborting and retrying from scratch"
git rebase --abort
git reset --hard HEAD~1
git pull origin Main
git add releases/
git commit -m "🚀 Release v$VERSION - Add build artifacts for Windows and Linux
- Windows x64 package: releases/v$VERSION/windows/
- Linux x64 package: releases/v$VERSION/linux/
- Updated latest symlink to point to v$VERSION
Built from commit: ${{ github.sha }}"
fi
sleep 5
else
echo "Failed to push after 3 attempts"
exit 1
fi
fi
done