forked from sxhxliang/arp
-
Notifications
You must be signed in to change notification settings - Fork 0
286 lines (247 loc) · 8.77 KB
/
release.yml
File metadata and controls
286 lines (247 loc) · 8.77 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: "Version tag to build (e.g. v1.2.3)"
required: true
permissions:
contents: write # Required for creating releases and uploading assets
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
# First job: Build binaries for all platforms
build:
name: Build ${{ matrix.target }}
strategy:
fail-fast: false
matrix:
include:
# Linux builds
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
use_cross: false
archive_ext: tar.gz
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
use_cross: true
archive_ext: tar.gz
# macOS builds
- os: macos-latest
target: x86_64-apple-darwin
use_cross: false
archive_ext: tar.gz
- os: macos-latest
target: aarch64-apple-darwin
use_cross: false
archive_ext: tar.gz
# Windows builds (client only)
- os: windows-latest
target: x86_64-pc-windows-msvc
use_cross: false
client_only: true
archive_ext: zip
- os: windows-latest
target: aarch64-pc-windows-msvc
use_cross: false
client_only: true
archive_ext: zip
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Resolve version
id: version
run: |
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
echo "value=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
elif [ -n "${INPUT_VERSION}" ]; then
echo "value=${INPUT_VERSION}" >> "$GITHUB_OUTPUT"
else
echo "value=dev" >> "$GITHUB_OUTPUT"
fi
shell: bash
env:
INPUT_VERSION: ${{ github.event.inputs.version }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Install cross
if: matrix.use_cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build for ${{ matrix.target }}
run: |
if [ "${{ matrix.client_only }}" = "true" ]; then
echo "Building client only (arpc) for ${{ matrix.target }}..."
if [ "${{ matrix.use_cross }}" = "true" ]; then
cross build --release --target ${{ matrix.target }} -p arpc
else
cargo build --release --target ${{ matrix.target }} -p arpc
fi
else
echo "Building all workspace members for ${{ matrix.target }}..."
if [ "${{ matrix.use_cross }}" = "true" ]; then
cross build --release --target ${{ matrix.target }}
else
cargo build --release --target ${{ matrix.target }}
fi
fi
echo "Build completed. Checking output files..."
ls -lh target/${{ matrix.target }}/release/ | grep -E "(arps|arpc)" || true
shell: bash
- name: Package binaries (Unix)
if: runner.os != 'Windows'
run: |
VERSION="${{ steps.version.outputs.value }}"
TARGET="${{ matrix.target }}"
mkdir -p release-package
cd release-package
# Copy binaries
if [ -f ../target/${TARGET}/release/arps ]; then
cp ../target/${TARGET}/release/arps .
fi
if [ -f ../target/${TARGET}/release/arpc ]; then
cp ../target/${TARGET}/release/arpc .
fi
# Copy README if exists
if [ -f ../README.md ]; then
cp ../README.md .
fi
# Make binaries executable
chmod +x arps arpc 2>/dev/null || true
# Create archive
cd ..
ARCHIVE_NAME="arp-${VERSION}-${TARGET}.tar.gz"
tar czf "${ARCHIVE_NAME}" -C release-package .
# Generate checksum
sha256sum "${ARCHIVE_NAME}" > "${ARCHIVE_NAME}.sha256"
echo "Created archive: ${ARCHIVE_NAME}"
ls -lh "${ARCHIVE_NAME}"*
shell: bash
- name: Package binaries (Windows)
if: runner.os == 'Windows'
run: |
$VERSION = "${{ steps.version.outputs.value }}"
$TARGET = "${{ matrix.target }}"
New-Item -ItemType Directory -Force -Path release-package
if (Test-Path "target\${TARGET}\release\arpc.exe") {
Copy-Item "target\${TARGET}\release\arpc.exe" release-package\
}
if (Test-Path "README.md") {
Copy-Item "README.md" release-package\
}
# Create zip archive
$ARCHIVE_NAME = "arp-${VERSION}-${TARGET}.zip"
Compress-Archive -Path release-package\* -DestinationPath $ARCHIVE_NAME
# Generate checksum
$hash = (Get-FileHash -Path $ARCHIVE_NAME -Algorithm SHA256).Hash
"${hash} ${ARCHIVE_NAME}" | Out-File -FilePath "${ARCHIVE_NAME}.sha256" -Encoding ASCII
Write-Host "Created archive: ${ARCHIVE_NAME}"
Get-Item $ARCHIVE_NAME*
shell: powershell
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: arp-${{ matrix.target }}
path: |
arp-*.tar.gz
arp-*.tar.gz.sha256
arp-*.zip
arp-*.zip.sha256
if-no-files-found: error
# Second job: Create GitHub release and upload all assets
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: List artifacts
run: |
echo "Downloaded artifacts:"
ls -lh artifacts/
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
files: artifacts/*
generate_release_notes: true
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Optional: Upload to R2 storage
upload-to-r2:
name: Upload to Cloudflare R2
needs: build
runs-on: ubuntu-latest
# Only run if pushing tags (secrets checked in step)
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- name: Check R2 configuration
id: check-r2
run: |
if [ -n "${{ secrets.R2_BUCKET }}" ] && [ -n "${{ secrets.R2_ACCESS_KEY_ID }}" ]; then
echo "configured=true" >> "$GITHUB_OUTPUT"
else
echo "configured=false" >> "$GITHUB_OUTPUT"
echo "⚠️ R2 secrets not configured, skipping R2 upload"
fi
- name: Download all artifacts
if: steps.check-r2.outputs.configured == 'true'
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Configure AWS CLI for R2
if: steps.check-r2.outputs.configured == 'true'
env:
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
run: |
aws configure set aws_access_key_id $R2_ACCESS_KEY_ID
aws configure set aws_secret_access_key $R2_SECRET_ACCESS_KEY
aws configure set region auto
- name: Upload to R2
if: steps.check-r2.outputs.configured == 'true'
env:
R2_BUCKET: ${{ secrets.R2_BUCKET }}
R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
VERSION: ${{ github.ref_name }}
run: |
cd artifacts
for file in arp-*; do
echo "Uploading ${file} to R2..."
aws s3 cp "${file}" \
"s3://${R2_BUCKET}/releases/${VERSION}/${file}" \
--endpoint-url "https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com"
done
echo "✅ All artifacts uploaded to R2 successfully!"