-
Notifications
You must be signed in to change notification settings - Fork 7
218 lines (192 loc) · 7.6 KB
/
release.yml
File metadata and controls
218 lines (192 loc) · 7.6 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
name: Release
on:
push:
tags:
- 'sdk-v*.*.*'
- 'sdk-v*.*.*-*'
- 'macros-v*.*.*'
- 'macros-v*.*.*-*'
workflow_dispatch:
inputs:
crate:
description: 'Which crate to publish'
required: true
type: choice
options:
- aptos-sdk
- aptos-sdk-macros
- both
dry_run:
description: 'Dry run (do not actually publish)'
required: false
default: true
type: boolean
env:
CARGO_TERM_COLOR: always
jobs:
# Determine which crates to publish based on the tag or manual input
resolve:
name: Resolve Crates
runs-on: ubuntu-latest
outputs:
publish_macros: ${{ steps.resolve.outputs.publish_macros }}
publish_sdk: ${{ steps.resolve.outputs.publish_sdk }}
steps:
- name: Resolve which crates to publish
id: resolve
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
case "${{ inputs.crate }}" in
aptos-sdk-macros)
echo "publish_macros=true" >> "$GITHUB_OUTPUT"
echo "publish_sdk=false" >> "$GITHUB_OUTPUT"
;;
aptos-sdk)
echo "publish_macros=false" >> "$GITHUB_OUTPUT"
echo "publish_sdk=true" >> "$GITHUB_OUTPUT"
;;
both)
echo "publish_macros=true" >> "$GITHUB_OUTPUT"
echo "publish_sdk=true" >> "$GITHUB_OUTPUT"
;;
esac
else
TAG="${GITHUB_REF#refs/tags/}"
if [[ "$TAG" == macros-v* ]]; then
echo "publish_macros=true" >> "$GITHUB_OUTPUT"
echo "publish_sdk=false" >> "$GITHUB_OUTPUT"
elif [[ "$TAG" == sdk-v* ]]; then
echo "publish_macros=false" >> "$GITHUB_OUTPUT"
echo "publish_sdk=true" >> "$GITHUB_OUTPUT"
fi
fi
verify:
name: Verify Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Rust nightly (for docs.rs parity check)
uses: dtolnay/rust-toolchain@nightly
- name: Install Rust stable (primary toolchain)
uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.90"
components: clippy, rustfmt
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Run tests
run: cargo test --all-targets --all-features
- name: Build documentation (docs.rs parity)
env:
RUSTDOCFLAGS: --cfg docsrs -D warnings
run: cargo +nightly doc --no-deps --all-features
publish-macros:
name: Publish aptos-sdk-macros
runs-on: ubuntu-latest
needs: [resolve, verify]
if: needs.resolve.outputs.publish_macros == 'true'
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.90"
- name: Cache cargo
uses: Swatinem/rust-cache@v2
# --no-verify: The aptos-sdk dev-dependency is path-only (dropped from the
# published crate to break the circular publish dependency), so the
# verification build would fail. The verify job already runs full tests
# with workspace path resolution.
- name: Publish aptos-sdk-macros (dry run)
if: github.event_name == 'workflow_dispatch' && inputs.dry_run == true
run: cargo publish -p aptos-sdk-macros --no-verify --dry-run
- name: Publish aptos-sdk-macros
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.dry_run != true)
run: cargo publish -p aptos-sdk-macros --no-verify
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
publish-sdk:
name: Publish aptos-sdk
runs-on: ubuntu-latest
needs: [resolve, verify, publish-macros]
# Run if SDK should be published, AND either macros wasn't needed or macros succeeded
if: |
always() &&
needs.resolve.outputs.publish_sdk == 'true' &&
needs.verify.result == 'success' &&
(needs.publish-macros.result == 'success' || needs.publish-macros.result == 'skipped')
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.90"
- name: Cache cargo
uses: Swatinem/rust-cache@v2
# If macros was just published, poll crates.io until it's indexed
- name: Wait for crates.io to index aptos-sdk-macros
if: needs.publish-macros.result == 'success'
run: |
MACROS_VERSION=$(grep '^version' crates/aptos-sdk-macros/Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
echo "Waiting for aptos-sdk-macros ${MACROS_VERSION} to appear on crates.io..."
for i in $(seq 1 30); do
if curl -sf -H "User-Agent: aptos-rust-sdk-ci" \
"https://crates.io/api/v1/crates/aptos-sdk-macros/${MACROS_VERSION}" > /dev/null 2>&1; then
echo "aptos-sdk-macros ${MACROS_VERSION} is now available on crates.io"
sleep 15 # extra buffer for sparse index propagation
exit 0
fi
echo "Attempt ${i}/30: not yet indexed, waiting 10s..."
sleep 10
done
echo "ERROR: Timed out waiting for aptos-sdk-macros ${MACROS_VERSION}"
exit 1
# When publishing SDK alone, verify the macros dependency is already on crates.io
- name: Verify aptos-sdk-macros dependency is available
if: needs.publish-macros.result == 'skipped'
run: |
MACROS_VERSION=$(grep 'aptos-sdk-macros.*version' Cargo.toml | head -1 | sed 's/.*version = "\([^"]*\)".*/\1/')
echo "Checking that aptos-sdk-macros ${MACROS_VERSION} exists on crates.io..."
if ! curl -sf -H "User-Agent: aptos-rust-sdk-ci" \
"https://crates.io/api/v1/crates/aptos-sdk-macros/${MACROS_VERSION}" > /dev/null 2>&1; then
echo "ERROR: aptos-sdk-macros ${MACROS_VERSION} is not on crates.io."
echo "Publish the macros crate first (push macros-v${MACROS_VERSION} tag or use 'both')."
exit 1
fi
echo "aptos-sdk-macros ${MACROS_VERSION} is available."
- name: Verify crate can be packaged
run: cargo package -p aptos-sdk --locked
- name: Publish aptos-sdk (dry run)
if: github.event_name == 'workflow_dispatch' && inputs.dry_run == true
run: cargo publish -p aptos-sdk --locked --dry-run
- name: Publish aptos-sdk
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.dry_run != true)
run: cargo publish -p aptos-sdk --locked
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
release-notes:
name: Create Release Notes
runs-on: ubuntu-latest
needs: [resolve, publish-macros, publish-sdk]
if: |
always() &&
github.event_name == 'push' &&
(needs.publish-macros.result == 'success' || needs.publish-sdk.result == 'success')
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Generate release notes
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
draft: false
prerelease: ${{ contains(github.ref, '-') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}