-
Notifications
You must be signed in to change notification settings - Fork 8
478 lines (464 loc) · 19.2 KB
/
Copy pathrust.yml
File metadata and controls
478 lines (464 loc) · 19.2 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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
name: Rust
on:
push:
branches:
- '**'
env:
CARGO_TERM_COLOR: always
jobs:
setup:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.read.outputs.version }}
tag: ${{ steps.read.outputs.tag }}
package_name: ${{ steps.read.outputs.package_name }}
branch_name: ${{ steps.read.outputs.branch_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install rust-toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt, clippy
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Cache toml-cli
id: cache_toml_cli
uses: actions/cache@v3
with:
path: ~/.cargo/bin/toml
key: toml-cli-${{ runner.os }}
- name: Install toml-cli
if: steps.cache_toml_cli.outputs.cache-hit != 'true'
run: |
for i in 1 2 3 4 5 6 7 8; do
if cargo install toml-cli; then
break
fi
echo "🔁 Retrying..."
done
- name: Read cargo metadata
id: read
run: |
VERSION=$(toml get Cargo.toml package.version --raw)
PACKAGE_NAME=$(toml get Cargo.toml package.name --raw)
BRANCH_NAME="${{ github.ref_name }}"
echo "📦 Detected package: $PACKAGE_NAME v$VERSION"
echo "🌿 Branch: $BRANCH_NAME"
if [ -z "$VERSION" ] || [ -z "$PACKAGE_NAME" ]; then
echo "❌ Failed to read package info from Cargo.toml"
fi
if [ "$BRANCH_NAME" = "master" ]; then
TAG="v$VERSION"
else
TAG="v$VERSION-$BRANCH_NAME"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "package_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
sync_workspace_version:
permissions:
contents: write
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Restore toml-cli
id: cache_toml_cli
uses: actions/cache@v3
with:
path: ~/.cargo/bin/toml
key: toml-cli-${{ runner.os }}
- name: Install toml-cli
if: steps.cache_toml_cli.outputs.cache-hit != 'true'
run: |
for i in 1 2 3 4 5 6 7 8; do
if cargo install toml-cli; then
break
fi
echo "🔁 Retrying..."
done
- name: Sync workspace version
run: |
VERSION="${{ needs.setup.outputs.version }}"
ROOT_DIR=$(pwd)
echo "🔧 Syncing all versions to $VERSION"
# Collect all workspace member directory names
MEMBER_PKG_NAMES=""
MEMBERS=$(toml get Cargo.toml workspace.members --raw | tr -d '[]"' | sed 's/,/\n/g' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | grep -v '^$')
echo "📋 Found workspace members: $MEMBERS"
for member in $MEMBERS; do
SUB_TOML="${ROOT_DIR}/${member}/Cargo.toml"
if [ -f "$SUB_TOML" ]; then
PKG_NAME=$(toml get "$SUB_TOML" package.name --raw)
MEMBER_PKG_NAMES="$MEMBER_PKG_NAMES $PKG_NAME"
echo "📋 Member: $member -> package: $PKG_NAME"
else
echo "⚠️ $SUB_TOML not found, skipping"
fi
done
# Also include the root package itself
ROOT_PKG_NAME=$(toml get Cargo.toml package.name --raw)
MEMBER_PKG_NAMES="$MEMBER_PKG_NAMES $ROOT_PKG_NAME"
# Also include all sub-table format workspace.dependencies entries
SUB_TABLE_PKGS=$(grep -oP '^\[workspace\.dependencies\.\K[^\]]+' Cargo.toml || true)
for pkg_name in $SUB_TABLE_PKGS; do
if ! echo "$MEMBER_PKG_NAMES" | grep -qw "$pkg_name"; then
MEMBER_PKG_NAMES="$MEMBER_PKG_NAMES $pkg_name"
fi
done
echo "📋 All package names to sync:$MEMBER_PKG_NAMES"
# Sync workspace.dependencies.<pkg_name>.version for all member packages using sed
for pkg_name in $MEMBER_PKG_NAMES; do
if grep -q "^${pkg_name}[[:space:]]*=" Cargo.toml && grep -q "^${pkg_name}[[:space:]]*=.*version" Cargo.toml; then
sed -i -E "s|^(${pkg_name}[[:space:]]*=[[:space:]]*\{.*version[[:space:]]*=[[:space:]]*\")([^\"]+)(\".*)|\1${VERSION}\3|" Cargo.toml
echo "🔧 workspace.dependencies.${pkg_name}.version -> $VERSION (inline)"
elif grep -q "^\[workspace\.dependencies\.${pkg_name}\]" Cargo.toml; then
sed -i -E "/^\[workspace\.dependencies\.${pkg_name}\]/,/^\[/ s|^(version[[:space:]]*=[[:space:]]*\")([^\"]+)(\")|\1${VERSION}\3|" Cargo.toml
echo "🔧 workspace.dependencies.${pkg_name}.version -> $VERSION (sub-table)"
else
echo "⏭️ workspace.dependencies.${pkg_name} not found, skipping"
fi
done
# Sync each sub-crate's own package.version
for member in $MEMBERS; do
SUB_TOML="${ROOT_DIR}/${member}/Cargo.toml"
if [ -f "$SUB_TOML" ]; then
sed -i -E "s|^(version[[:space:]]*=[[:space:]]*\")([^\"]+)(\")|\1${VERSION}\3|" "$SUB_TOML"
echo "🔧 ${member}/Cargo.toml package.version -> $VERSION"
else
echo "⚠️ ${member}/Cargo.toml not found, skipping"
fi
done
# Sync the root package.version itself
sed -i -E "0,/^(version[[:space:]]*=[[:space:]]*\")([^\"]+)(\")/s|^(version[[:space:]]*=[[:space:]]*\")([^\"]+)(\")|\1${VERSION}\3|" Cargo.toml
echo "🔧 Cargo.toml package.version -> $VERSION"
- name: Update Cargo.lock
run: cargo generate-lockfile
- name: Commit and push
run: |
git config user.name "eastspire"
git config user.email "root@ltpp.vip"
git add -A
git diff --cached --quiet || git commit -m "chore: sync all package versions to ${{ needs.setup.outputs.version }}"
git push
check:
needs: sync_workspace_version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Setup rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt
- name: Format check
run: cargo fmt -- --check
tests:
needs: sync_workspace_version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Prepare environment
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Run tests
run: cargo test --all-features -- --nocapture
clippy:
needs: sync_workspace_version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Load clippy
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: clippy
- name: Run clippy
run: cargo clippy --all-features
build:
needs: sync_workspace_version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Setup build
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Build release
run: cargo check --release --all-features
publish:
permissions:
contents: write
needs: [setup, sync_workspace_version, check, tests, clippy, build]
if: needs.setup.outputs.tag != ''
runs-on: ubuntu-latest
outputs:
published: ${{ steps.publish.outputs.published }}
steps:
- name: Check branch
id: check_branch
run: |
if [ "${{ needs.setup.outputs.branch_name }}" != "master" ]; then
echo "⚠️ Not on master branch (current: ${{ needs.setup.outputs.branch_name }}), skipping publish"
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "✅ On master branch, proceeding with publish"
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Checkout
if: steps.check_branch.outputs.skip == 'false'
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Restore toml-cli
if: steps.check_branch.outputs.skip == 'false'
uses: actions/cache@v3
with:
path: ~/.cargo/bin/toml
key: toml-cli-${{ runner.os }}
- name: Install cargo-release
if: steps.check_branch.outputs.skip == 'false'
run: |
for i in 1 2 3 4 5 6 7 8; do
if cargo install cargo-release; then
break
fi
echo "🔁 Retrying..."
done
- name: Configure git
if: steps.check_branch.outputs.skip == 'false'
run: |
git config user.name "eastspire"
git config user.email "root@ltpp.vip"
- name: Publish to crates.io
id: publish
if: steps.check_branch.outputs.skip == 'false'
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
echo "published=false" >> $GITHUB_OUTPUT
echo "${{ secrets.CARGO_REGISTRY_TOKEN }}" | cargo login
VERSION="${{ needs.setup.outputs.version }}"
PUBLISH_ORDER=("hyperlane_resources" "hyperlane_config" "hyperlane_plugin" "hyperlane_application" "hyperlane_bootstrap" "hyperlane-quick-start")
SKIP_PACKAGES=()
MAIN_PACKAGE="hyperlane-quick-start"
declare -A PUBLISH_RESULT
for PKG_NAME in "${PUBLISH_ORDER[@]}"; do
for SKIP in "${SKIP_PACKAGES[@]}"; do
if [ "$PKG_NAME" = "$SKIP" ]; then
echo "⏭️ Skipping $PKG_NAME (publish = false)"
continue 2
fi
done
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📦 Publishing $PKG_NAME v$VERSION"
PKG_PUBLISHED=false
for ((i=1; i<=36; i++)); do
echo "🚀 Attempt $i/36: publishing $PKG_NAME v$VERSION"
set +e
PUBLISH_OUTPUT=$(cargo publish -p "$PKG_NAME" --allow-dirty --no-verify 2>&1)
PUBLISH_EXIT_CODE=$?
set -e
echo "$PUBLISH_OUTPUT"
if [ $PUBLISH_EXIT_CODE -eq 0 ]; then
echo "✅ $PKG_NAME v$VERSION publish exited with code 0"
PKG_PUBLISHED=true
break
fi
if echo "$PUBLISH_OUTPUT" | grep -q "is already published"; then
echo "📦 $PKG_NAME v$VERSION is already published to crates.io"
PKG_PUBLISHED=true
break
fi
if echo "$PUBLISH_OUTPUT" | grep -q "already been uploaded"; then
echo "📦 $PKG_NAME v$VERSION is already uploaded to crates.io"
PKG_PUBLISHED=true
break
fi
echo "⚠️ Attempt $i failed for $PKG_NAME (exit code: $PUBLISH_EXIT_CODE)"
if echo "$PUBLISH_OUTPUT" | grep -qi "unauthorized\|forbidden\|token\|credential"; then
echo "🚫 Authentication error detected, aborting $PKG_NAME"
break
fi
if [ "$i" -lt "36" ]; then
echo "🔁 Retrying..."
fi
done
PUBLISH_RESULT[$PKG_NAME]=$PKG_PUBLISHED
if [ "$PKG_PUBLISHED" = "true" ]; then
VERIFY_HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -H "User-Agent: hyperlane-quick-start" "https://crates.io/api/v1/crates/$PKG_NAME/$VERSION")
if [ "$VERIFY_HTTP_CODE" = "200" ]; then
echo "✅ $PKG_NAME v$VERSION verified on crates.io (HTTP 200)"
else
echo "⚠️ $PKG_NAME v$VERSION could not be verified (HTTP $VERIFY_HTTP_CODE), but publish reported success - continuing"
fi
else
echo "❌ $PKG_NAME v$VERSION failed to publish, continuing with next package"
fi
done
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📋 Publish Summary:"
for PKG_NAME in "${PUBLISH_ORDER[@]}"; do
if [ "${PUBLISH_RESULT[$PKG_NAME]:-false}" = "true" ]; then
echo " ✅ $PKG_NAME v$VERSION"
else
echo " ❌ $PKG_NAME v$VERSION"
fi
done
if [ "${PUBLISH_RESULT[$MAIN_PACKAGE]:-false}" = "true" ]; then
echo "published=true" >> "$GITHUB_OUTPUT"
echo "🎉🎉🎉 PUBLISH SUCCESSFUL 🎉🎉🎉"
echo "✅ Main package $MAIN_PACKAGE v$VERSION published to crates.io"
echo "📦 Crates.io: https://crates.io/crates/$MAIN_PACKAGE/$VERSION"
echo "📚 Docs.rs: https://docs.rs/$MAIN_PACKAGE/$VERSION"
else
echo "❌ Main package $MAIN_PACKAGE v$VERSION failed to publish"
fi
release:
needs: [setup, sync_workspace_version, check, tests, clippy, build, publish]
permissions:
contents: write
packages: write
if: needs.setup.outputs.tag != ''
runs-on: ubuntu-latest
outputs:
released: ${{ steps.release.outputs.released }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Get package name and branch info
id: package_info
run: |
echo "package_name=${{ needs.setup.outputs.package_name }}" >> $GITHUB_OUTPUT
echo "branch_name=${{ needs.setup.outputs.branch_name }}" >> $GITHUB_OUTPUT
- name: Check tag status
id: check_tag
run: |
if git tag -l | grep -q "^${{ needs.setup.outputs.tag }}$"; then
echo "tag_exists=true" >> $GITHUB_OUTPUT
echo "🏷️ Tag ${{ needs.setup.outputs.tag }} exists locally"
else
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "🏷️ Tag ${{ needs.setup.outputs.tag }} does not exist locally"
fi
if git ls-remote --tags origin | grep -q "refs/tags/${{ needs.setup.outputs.tag }}$"; then
echo "remote_tag_exists=true" >> $GITHUB_OUTPUT
echo "🌐 Tag ${{ needs.setup.outputs.tag }} exists on remote"
else
echo "remote_tag_exists=false" >> $GITHUB_OUTPUT
echo "🌐 Tag ${{ needs.setup.outputs.tag }} does not exist on remote"
fi
- name: Check release status
id: check_release
run: |
if gh release view "${{ needs.setup.outputs.tag }}" > /dev/null 2>&1; then
echo "release_exists=true" >> $GITHUB_OUTPUT
echo "📦 Release ${{ needs.setup.outputs.tag }} already exists"
else
echo "release_exists=false" >> $GITHUB_OUTPUT
echo "📦 Release ${{ needs.setup.outputs.tag }} does not exist"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create or update release
id: release
run: |
set -e
echo "released=false" >> $GITHUB_OUTPUT
PACKAGE_NAME="${{ steps.package_info.outputs.package_name }}"
VERSION="${{ needs.setup.outputs.version }}"
TAG="${{ needs.setup.outputs.tag }}"
echo "📦 Building source archives..."
git archive --format=zip --prefix="${PACKAGE_NAME}-${VERSION}/" HEAD > "${PACKAGE_NAME}-${VERSION}.zip"
git archive --format=tar.gz --prefix="${PACKAGE_NAME}-${VERSION}/" HEAD > "${PACKAGE_NAME}-${VERSION}.tar.gz"
if [ "${{ steps.check_release.outputs.release_exists }}" = "true" ]; then
echo "🔄 Updating existing release: $TAG"
gh release view "$TAG" --json assets --jq '.assets[].name' | while read asset; do
if [ -n "$asset" ]; then
echo "🗑️ Deleting asset: $asset"
gh release delete-asset "$TAG" "$asset" --yes || true
fi
done
BRANCH_NAME="${{ steps.package_info.outputs.branch_name }}"
TITLE="[$BRANCH_NAME]($TAG updated $(date '+%Y-%m-%d %H:%M:%S'))"
if gh release edit "$TAG" \
--title "$TITLE" \
--notes "[$BRANCH_NAME] - release $TAG updated at $(date '+%Y-%m-%d %H:%M:%S UTC')
## Changes
- Branch: $BRANCH_NAME
- Version: $VERSION
- Package: $PACKAGE_NAME
## Links
📦 [Crate on crates.io](https://crates.io/crates/$PACKAGE_NAME/$VERSION)
📚 [Documentation on docs.rs](https://docs.rs/$PACKAGE_NAME/$VERSION)
📋 [Commit History](https://github.com/${{ github.repository }}/commits/$TAG)" && \
gh release upload "$TAG" "${PACKAGE_NAME}-${VERSION}.zip" "${PACKAGE_NAME}-${VERSION}.tar.gz" --clobber; then
echo "released=true" >> $GITHUB_OUTPUT
echo "✅ Updated release $TAG"
echo "🔖 Tag: $TAG"
echo "🚀 Release: [GitHub Release](${{ github.server_url }}/${{ github.repository }}/releases/tag/$TAG)"
else
echo "❌ Failed to update release"
fi
else
if [ "${{ steps.check_tag.outputs.remote_tag_exists }}" = "false" ]; then
echo "🏷️ Creating and pushing tag: $TAG"
git tag "$TAG"
git push origin "$TAG"
fi
echo "🆕 Creating new release: $TAG"
BRANCH_NAME="${{ steps.package_info.outputs.branch_name }}"
TITLE="[$BRANCH_NAME]($TAG created $(date '+%Y-%m-%d %H:%M:%S'))"
if gh release create "$TAG" \
--title "$TITLE" \
--notes "[$BRANCH_NAME] - release $TAG created at $(date '+%Y-%m-%d %H:%M:%S UTC')
## Changes
- Branch: $BRANCH_NAME
- Version: $VERSION
- Package: $PACKAGE_NAME
## Links
📦 [Crate on crates.io](https://crates.io/crates/$PACKAGE_NAME/$VERSION)
📚 [Documentation on docs.rs](https://docs.rs/$PACKAGE_NAME/$VERSION)
📋 [Commit History](https://github.com/${{ github.repository }}/commits/$TAG)" \
--latest && \
gh release upload "$TAG" "${PACKAGE_NAME}-${VERSION}.zip" "${PACKAGE_NAME}-${VERSION}.tar.gz"; then
echo "released=true" >> $GITHUB_OUTPUT
echo "✅ Created release $TAG"
echo "🔖 Tag: $TAG"
echo "🚀 Release: [GitHub Release](${{ github.server_url }}/${{ github.repository }}/releases/tag/$TAG)"
else
echo "❌ Failed to create release"
fi
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}