forked from anza-xyz/solana-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
290 lines (252 loc) · 8.73 KB
/
publish-rust.yml
File metadata and controls
290 lines (252 loc) · 8.73 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
name: Publish Crate
on:
workflow_dispatch:
inputs:
package_path:
description: Path to directory with package to release
required: true
type: string
level:
description: Level
required: true
default: patch
type: choice
options:
- patch
- minor
- major
- version
version:
description: Version (used with level "version")
required: false
type: string
dry_run:
description: Dry run
required: true
default: true
type: boolean
create_release:
description: Create a GitHub release
required: true
type: boolean
default: true
dependent_version:
description: |
How workspace dependencies should be handled.
- "fix": (Default) Only bumps the workspace for semver-breakage - prefer this option
- "upgrade": Bumps workspace version regardless - only use if another SDK crate requires new code
required: true
default: fix
type: choice
options:
- fix
- upgrade
run_semver:
description: |
Run semver checks.
Only disable checks if you are sure of the semver impact of your change and have a good reason
to skip it.
required: true
type: boolean
default: true
jobs:
sanity:
name: Sanity checks
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # full history to check for whitespace / conflict markers
- name: Setup Environment
uses: ./.github/actions/setup
with:
stable-toolchain: true
cargo-cache-key: cargo-stable-sanity
cargo-cache-fallback-key: cargo-stable
- name: Check repo is in porcelain state
run: ./scripts/check-porcelain.sh
- name: Check code nits
run: ./scripts/check-nits.sh
format:
name: Format
runs-on: ubuntu-latest
needs: [sanity]
steps:
- name: Git Checkout
uses: actions/checkout@v4
- name: Setup Environment
uses: ./.github/actions/setup
with:
rustfmt: true
cargo-cache-key: cargo-nightly-fmt
cargo-cache-fallback-key: cargo-nightly
- name: Check formatting
run: ./scripts/check-fmt.sh
clippy:
name: Clippy
needs: [sanity]
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4
- name: Setup Environment
uses: ./.github/actions/setup
with:
clippy: true
cargo-cache-key: cargo-nightly-clippy
cargo-cache-fallback-key: cargo-nightly
- name: Run clippy
run: ./scripts/check-clippy.sh
docsrs:
name: Docs.rs
needs: [sanity]
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4
- name: Install 'nightly' toolchain
uses: dtolnay/rust-toolchain@nightly
- name: Run docs.rs build
run: |
# Mimic docs.rs build environment
export DOCS_RS="1"
export RUSTDOCFLAGS="--cfg docsrs"
cargo +nightly doc --no-deps --all-features --manifest-path "${{ inputs.package_path }}/Cargo.toml"
detached-minimal-versions:
name: Check minimal-versions on detached crate
runs-on: ubuntu-latest
needs: [sanity]
steps:
- name: Git Checkout
uses: actions/checkout@v4
- name: Setup Environment
uses: ./.github/actions/setup
with:
nightly-toolchain: true
cargo-cache-key: cargo-nightly-minimal-versions
cargo-cache-fallback-key: cargo-nightly
- name: Install cargo-hack
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: cargo-hack
- name: Install cargo-minimal-versions
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: cargo-minimal-versions
- name: Install toml-cli
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: toml-cli
- name: Run minimal-versions check
run: ./scripts/check-detached-minimal-versions.sh "${{ inputs.package_path }}"
semver:
name: Check Semver
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v4
- name: Setup Environment
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-publish-semver-${{ inputs.package_path }}
cargo-cache-fallback-key: cargo-publish-semver
- name: Install cargo-semver-checks
uses: taiki-e/install-action@v2
with:
tool: toml-cli,cargo-semver-checks,cargo-release
- name: Check if crate is a procedural macro
id: is_proc_macro
shell: bash
run: |
set +e # toml crashes the whole shell if it fails to find the key
result=$(toml get "${{ inputs.package_path }}/Cargo.toml" lib.proc-macro)
if [[ "$result" == *"true"* ]]; then
echo "is_proc_macro=true" >> "$GITHUB_OUTPUT"
else
echo "is_proc_macro=false" >> "$GITHUB_OUTPUT"
fi
- name: Set Git Author (required for cargo-release)
if: ${{ steps.is_proc_macro.outputs.is_proc_macro == 'false' }}
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Set Version
if: ${{ steps.is_proc_macro.outputs.is_proc_macro == 'false' }}
run: |
if [ "${{ inputs.level }}" == "version" ]; then
LEVEL=${{ inputs.version }}
else
LEVEL=${{ inputs.level }}
fi
cargo release $LEVEL --manifest-path "${{ inputs.package_path }}/Cargo.toml" --no-tag --no-publish --no-push --no-confirm --execute
- name: Check semver
if: ${{ steps.is_proc_macro.outputs.is_proc_macro == 'false' && github.event.inputs.run_semver == 'true'}}
run: cargo semver-checks --manifest-path "${{ inputs.package_path }}/Cargo.toml"
publish-crate:
name: Publish crate
runs-on: ubuntu-latest
needs: [format, clippy, detached-minimal-versions, semver, docsrs]
permissions:
contents: write
steps:
- name: Git Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.ANZA_TEAM_PAT }}
fetch-depth: 0 # get the whole history for git-cliff
- name: Setup Environment
uses: ./.github/actions/setup
with:
stable-toolchain: true
cargo-cache-key: cargo-stable-publish
cargo-cache-fallback-key: cargo-stable
- name: Install cargo-release
uses: taiki-e/install-action@v2
with:
tool: cargo-release
- name: Ensure CARGO_REGISTRY_TOKEN variable is set
env:
token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
if: ${{ env.token == '' }}
run: |
echo "The CARGO_REGISTRY_TOKEN secret variable is not set"
echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"."
exit 1
- name: Set Git Author
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Rebase (in case any changes landed after)
run: git pull --rebase origin
- name: Publish Crate
id: publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
if [ "${{ inputs.level }}" == "version" ]; then
LEVEL=${{ inputs.version }}
else
LEVEL=${{ inputs.level }}
fi
if [ "${{ inputs.dry_run }}" == "true" ]; then
OPTIONS="--dry-run"
else
OPTIONS=""
fi
./scripts/publish-rust.sh "${{ inputs.package_path }}" $LEVEL "${{ inputs.dependent_version }}" $OPTIONS
- name: Generate a changelog
if: github.event.inputs.create_release == 'true'
uses: orhun/git-cliff-action@v4
with:
config: "scripts/cliff.toml"
args: ${{ steps.publish.outputs.old_git_tag }}..HEAD --include-path "${{ inputs.package_path }}/**" --github-repo ${{ github.repository }}
env:
OUTPUT: TEMP_CHANGELOG.md
GITHUB_REPO: ${{ github.repository }}
- name: Create GitHub release
if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true'
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.publish.outputs.new_git_tag }}
bodyFile: TEMP_CHANGELOG.md