Repository navigation
324 lines (311 loc) · 11.7 KB
/
Copy pathrust.yml
File metadata and controls
324 lines (311 loc) · 11.7 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
name: Rust
on:
push:
branches: [master]
pull_request:
branches: [master]
env:
CARGO_TERM_COLOR: always
jobs:
setup:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.read.outputs.version }}
tag: ${{ steps.read.outputs.tag }}
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: Read workspace metadata
id: read
run: |
VERSION=$(grep -E '^version = ' Cargo.toml | head -1 | sed -E 's/^version = "([^"]+)".*/\1/')
BRANCH_NAME="${{ github.ref_name }}"
echo "Detected workspace version: $VERSION"
echo "Branch: $BRANCH_NAME"
if [ -z "$VERSION" ]; then
echo "Failed to read version from Cargo.toml"
exit 1
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 "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
check:
needs: setup
if: always() && (github.event_name == 'pull_request' || (github.event_name == 'push' && needs.setup.result == 'success'))
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 --all -- --check
tests:
needs: setup
if: always() && (github.event_name == 'pull_request' || (github.event_name == 'push' && needs.setup.result == 'success'))
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 --workspace --all-features -- --nocapture
clippy:
needs: setup
if: always() && (github.event_name == 'pull_request' || (github.event_name == 'push' && needs.setup.result == 'success'))
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 --workspace --all-features --all-targets
build:
needs: setup
if: always() && (github.event_name == 'pull_request' || (github.event_name == 'push' && needs.setup.result == 'success'))
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 --workspace --all-features
publish:
permissions:
contents: write
needs: [setup, check, tests, clippy, build]
if: always() && github.event_name == 'push' && github.ref_name == 'master' && needs.setup.outputs.tag != '' && needs.check.result == 'success' && needs.tests.result == 'success' && needs.clippy.result == 'success' && needs.build.result == 'success'
runs-on: ubuntu-latest
outputs:
published: ${{ steps.publish.outputs.published }}
synced_version: ${{ steps.sync_refs.outputs.synced_version }}
synced_tag: ${{ steps.sync_refs.outputs.synced_tag }}
steps:
- name: Check branch
id: check_branch
run: |
if [ "${{ needs.setup.outputs.branch_name }}" != "master" ]; then
echo "Not on master branch, 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: Install crates-cli
if: steps.check_branch.outputs.skip == 'false'
run: |
for i in 1 2 3 4 5 6 7 8; do
if cargo install crate-cli; then
break
fi
echo "Retrying..."
done
- name: Sync workspace dependency references
id: sync_refs
if: steps.check_branch.outputs.skip == 'false'
run: |
set -e
crate sync
crate fmt
if git diff --quiet; then
echo "sync_changed=false" >> $GITHUB_OUTPUT
echo "Workspace already in sync and formatted"
else
echo "sync_changed=true" >> $GITHUB_OUTPUT
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore: sync workspace member deps and apply crate fmt"
git push origin HEAD:master
echo "Committed and pushed sync + fmt"
fi
SYNCED_VERSION="$(grep -E '^version[[:space:]]*=[[:space:]]*"' Cargo.toml | head -1 | sed -E 's/^version[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/')"
SYNCED_TAG="v${SYNCED_VERSION}"
echo "synced_version=$SYNCED_VERSION" >> $GITHUB_OUTPUT
echo "synced_tag=$SYNCED_TAG" >> $GITHUB_OUTPUT
echo "Bumped version: $SYNCED_VERSION"
- name: Publish to crates.io
id: publish
if: steps.check_branch.outputs.skip == 'false'
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
set -e
echo "${{ secrets.CARGO_REGISTRY_TOKEN }}" | cargo login
crate publish
echo "published=true" >> "$GITHUB_OUTPUT"
echo "ALL PUBLISH SUCCESSFUL"
release:
needs: [setup, check, tests, clippy, build, publish]
permissions:
contents: write
packages: write
if: always() && github.event_name == 'push' && github.ref_name == 'master' && needs.publish.outputs.synced_tag != '' && needs.publish.result == 'success'
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: Check tag status
id: check_tag
run: |
if git tag -l | grep -q "^${{ needs.publish.outputs.synced_tag }}$"; then
echo "tag_exists=true" >> $GITHUB_OUTPUT
echo "Tag ${{ needs.publish.outputs.synced_tag }} exists locally"
else
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "Tag ${{ needs.publish.outputs.synced_tag }} does not exist locally"
fi
if git ls-remote --tags origin | grep -q "refs/tags/${{ needs.publish.outputs.synced_tag }}$"; then
echo "remote_tag_exists=true" >> $GITHUB_OUTPUT
echo "Tag ${{ needs.publish.outputs.synced_tag }} exists on remote"
else
echo "remote_tag_exists=false" >> $GITHUB_OUTPUT
echo "Tag ${{ needs.publish.outputs.synced_tag }} does not exist on remote"
fi
- name: Check release status
id: check_release
run: |
if gh release view "${{ needs.publish.outputs.synced_tag }}" > /dev/null 2>&1; then
echo "release_exists=true" >> $GITHUB_OUTPUT
echo "Release ${{ needs.publish.outputs.synced_tag }} already exists"
else
echo "release_exists=false" >> $GITHUB_OUTPUT
echo "Release ${{ needs.publish.outputs.synced_tag }} does not exist"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build source archive
id: build_archive
run: |
set -e
VERSION="${{ needs.publish.outputs.synced_version }}"
TAG="${{ needs.publish.outputs.synced_tag }}"
REPO_NAME="${{ github.event.repository.name }}"
echo "Building source archive for $REPO_NAME v$VERSION..."
git archive --format=tar.gz --prefix="${REPO_NAME}-${VERSION}/" HEAD > "${REPO_NAME}-${VERSION}.tar.gz"
echo "archive_path=${REPO_NAME}-${VERSION}.tar.gz" >> $GITHUB_OUTPUT
- name: Create or update release
id: release
run: |
set -e
echo "released=false" >> $GITHUB_OUTPUT
VERSION="${{ needs.publish.outputs.synced_version }}"
TAG="${{ needs.publish.outputs.synced_tag }}"
ARCHIVE="${{ steps.build_archive.outputs.archive_path }}"
PACKAGES=(
"http-compress"
"http-constant"
"http-type"
"http-request"
"hyperlane-core"
"hyperlane-macros"
"hyperlane"
"hyperlane-cli"
)
NOTES_FILE="$(mktemp)"
{
printf '## Release %s\n\n' "$TAG"
printf '| Package | crates.io | docs.rs |\n'
printf '| --- | --- | --- |\n'
for pkg in "${PACKAGES[@]}"; do
printf '| `%s` | [crates.io](https://crates.io/crates/%s/%s) | [docs.rs](https://docs.rs/%s/%s) |\n' \
"$pkg" "$pkg" "$VERSION" "$pkg" "$VERSION"
done
printf '\nCommit History: https://github.com/%s/commits/%s\n' \
"${{ github.repository }}" "$TAG"
} > "$NOTES_FILE"
TITLE="$TAG (monorepo)"
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S UTC')
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
if gh release edit "$TAG" \
--title "$TITLE (updated $TIMESTAMP)" \
--notes-file "$NOTES_FILE" \
&& gh release upload "$TAG" "$ARCHIVE" --clobber; then
echo "released=true" >> $GITHUB_OUTPUT
echo "Updated release $TAG"
else
echo "Failed to update release"
exit 1
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"
if gh release create "$TAG" \
--title "$TITLE" \
--notes-file "$NOTES_FILE" \
--latest \
&& gh release upload "$TAG" "$ARCHIVE"; then
echo "released=true" >> $GITHUB_OUTPUT
echo "Created release $TAG"
echo "Release: ${{ github.server_url }}/${{ github.repository }}/releases/tag/$TAG"
else
echo "Failed to create release"
exit 1
fi
fi
rm -f "$NOTES_FILE"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}