forked from sxhxliang/arp
-
Notifications
You must be signed in to change notification settings - Fork 0
293 lines (246 loc) · 8.92 KB
/
ci.yml
File metadata and controls
293 lines (246 loc) · 8.92 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
name: CI
on:
push:
branches: [ "main", "master"]
pull_request:
branches: [ "main", "master"]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- 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 }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run clippy
run: cargo clippy --all-targets --all-features
- name: Check cargo
run: cargo check --all-features
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- 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 }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Run tests
run: cargo test --all-features
build:
name: Build
strategy:
matrix:
include:
# Linux builds
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
use_cross: false
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
use_cross: true
# macOS builds
- os: macos-latest
target: x86_64-apple-darwin
use_cross: false
- os: macos-latest
target: aarch64-apple-darwin
use_cross: false
# Windows builds (client only)
- os: windows-latest
target: x86_64-pc-windows-msvc
use_cross: false
client_only: true
- os: windows-latest
target: aarch64-pc-windows-msvc
use_cross: false
client_only: true
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- 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
# Verify build output
echo "Build completed. Checking output files..."
ls -lh target/${{ matrix.target }}/release/ | grep -E "(arps|arpc)" || true
shell: bash
- name: Prepare artifacts (Unix)
if: runner.os != 'Windows'
run: |
mkdir -p artifacts
cp target/${{ matrix.target }}/release/arps artifacts/ || true
cp target/${{ matrix.target }}/release/arpc artifacts/
chmod +x artifacts/*
shell: bash
- name: Prepare artifacts (Windows)
if: runner.os == 'Windows'
run: |
echo "Checking build output..."
dir target\${{ matrix.target }}\release\*.exe
if not exist "artifacts" mkdir artifacts
if exist "target\${{ matrix.target }}\release\arpc.exe" (
echo "Copying arpc.exe..."
copy target\${{ matrix.target }}\release\arpc.exe artifacts\
) else (
echo "ERROR: arpc.exe not found!"
exit /b 1
)
echo "Contents of artifacts directory:"
dir artifacts
shell: cmd
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: arp-${{ matrix.target }}
path: artifacts/*
if-no-files-found: error
upload-to-r2:
name: Upload to Cloudflare R2
needs: build
runs-on: ubuntu-latest
# Only upload on push to main branches, not on PRs
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Verify AWS CLI
run: |
aws --version
echo "AWS CLI is already installed"
- name: Configure AWS CLI for R2
env:
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
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: Create archive and upload to R2
env:
R2_BUCKET: ${{ secrets.R2_BUCKET }}
R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
COMMIT_SHA: ${{ github.sha }}
run: |
# Get short commit hash
SHORT_SHA=$(echo $COMMIT_SHA | cut -c1-7)
# Create timestamped directory
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
VERSION="${TIMESTAMP}-${SHORT_SHA}"
# Compress each platform's artifacts
cd artifacts
for dir in */; do
platform=$(basename "$dir")
echo "Processing $platform..."
cd "$dir"
# Create tar.gz for Unix platforms, zip for Windows
if [[ $platform == *"windows"* ]]; then
zip -r "../${platform}-${VERSION}.zip" .
UPLOAD_FILE="../${platform}-${VERSION}.zip"
else
tar czf "../${platform}-${VERSION}.tar.gz" .
UPLOAD_FILE="../${platform}-${VERSION}.tar.gz"
fi
cd ..
# Upload to R2
echo "Uploading $UPLOAD_FILE to R2..."
aws s3 cp "$(basename $UPLOAD_FILE)" \
"s3://${R2_BUCKET}/builds/${VERSION}/$(basename $UPLOAD_FILE)" \
--endpoint-url "https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com"
# Also upload as 'latest' for each platform
aws s3 cp "$(basename $UPLOAD_FILE)" \
"s3://${R2_BUCKET}/builds/latest/$(basename $UPLOAD_FILE | sed "s/-${VERSION}//")" \
--endpoint-url "https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com"
done
# Create and upload manifest file
cat > manifest.json <<EOF
{
"version": "${VERSION}",
"commit": "${COMMIT_SHA}",
"timestamp": "${TIMESTAMP}",
"branch": "${GITHUB_REF_NAME}",
"artifacts": [
$(ls *.tar.gz *.zip 2>/dev/null | sed 's/.*/"&"/' | paste -sd,)
]
}
EOF
aws s3 cp manifest.json \
"s3://${R2_BUCKET}/builds/${VERSION}/manifest.json" \
--endpoint-url "https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com"
echo "✅ All artifacts uploaded successfully!"
echo "Version: ${VERSION}"