-
Notifications
You must be signed in to change notification settings - Fork 6
281 lines (246 loc) · 9.29 KB
/
release-crate.yml
File metadata and controls
281 lines (246 loc) · 9.29 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
name: Crates.io CLI Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
tag:
description: "Release tag (e.g. v0.3.39)"
required: true
permissions:
contents: read
actions: write
env:
CARGO_TERM_COLOR: always
CLI_CLIENT_SECRET: ${{ secrets.CLI_CLIENT_SECRET }}
jobs:
publish:
name: Publish workspace crates to crates.io
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.release.outputs.tag }}
published_count: ${{ steps.plan.outputs.count }}
publish_cli_sdk_pypi: ${{ steps.downstream.outputs.publish_cli_sdk_pypi }}
publish_cli_sdk_npm: ${{ steps.downstream.outputs.publish_cli_sdk_npm }}
publish_cli_sdk_gem: ${{ steps.downstream.outputs.publish_cli_sdk_gem }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.inputs.tag || github.ref }}
- name: Set the release version
id: release
shell: bash
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
release_tag="${GITHUB_REF_NAME}"
release_version="${GITHUB_REF_NAME#v}"
else
release_tag="${{ github.event.inputs.tag }}"
release_tag="${release_tag#refs/tags/}"
release_version="${release_tag#v}"
fi
echo "RELEASE_TAG=${release_tag}" >> "$GITHUB_ENV"
echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
echo "tag=${release_tag}" >> "$GITHUB_OUTPUT"
echo "version=${release_version}" >> "$GITHUB_OUTPUT"
- name: Read Rust toolchain
shell: bash
run: |
rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)"
if [ -z "$rust_toolchain" ]; then
echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2
exit 1
fi
echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV"
- name: Install toolkit
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
key: publish
- name: Install cargo-workspaces
shell: bash
run: cargo install cargo-workspaces --version 0.4.2 --locked
- name: Verify workspace crate versions match tag
shell: bash
run: |
cargo metadata --no-deps --format-version 1 > metadata.json
crate_count="$(jq '[.packages[] | select(.manifest_path | contains("/crates/"))] | length' metadata.json)"
if [[ "$crate_count" == "0" ]]; then
echo "::error::No workspace crates found under /crates."
exit 1
fi
mismatches="$({
jq -r --arg release_version "${RELEASE_VERSION}" '
.packages[]
| select(.manifest_path | contains("/crates/"))
| select(.version != $release_version)
| "\(.name) \(.version)"' metadata.json
} || true)"
if [[ -n "$mismatches" ]]; then
echo "::error::These crates do not match tag version ${RELEASE_VERSION}:"
echo "$mismatches"
exit 1
fi
- name: Build unpublished crate plan
id: plan
shell: bash
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
if [[ -z "${CARGO_REGISTRY_TOKEN}" ]]; then
echo "::error::CARGO_REGISTRY_TOKEN is required."
exit 1
fi
cargo workspaces plan --skip-published --json --token "${CARGO_REGISTRY_TOKEN}" > plan.json
cat plan.json
plan_count="$(jq 'length' plan.json)"
echo "count=${plan_count}" >> "$GITHUB_OUTPUT"
- name: Derive downstream workflow triggers
id: downstream
shell: bash
run: |
publish_cli_sdk_pypi="$(jq -r 'map(.name) | any(. == "smbcloud-auth-sdk-py" or . == "smbcloud-auth-sdk" or . == "smbcloud-model" or . == "smbcloud-network")' plan.json)"
publish_cli_sdk_npm="$(jq -r 'map(.name) | any(. == "smbcloud-auth-sdk-wasm" or . == "smbcloud-auth-sdk" or . == "smbcloud-network" or . == "smbcloud-networking")' plan.json)"
publish_cli_sdk_gem="$(jq -r 'map(.name) | any(. == "smbcloud-auth-sdk" or . == "smbcloud-model" or . == "smbcloud-network")' plan.json)"
echo "publish_cli_sdk_pypi=${publish_cli_sdk_pypi}" >> "$GITHUB_OUTPUT"
echo "publish_cli_sdk_npm=${publish_cli_sdk_npm}" >> "$GITHUB_OUTPUT"
echo "publish_cli_sdk_gem=${publish_cli_sdk_gem}" >> "$GITHUB_OUTPUT"
echo "SDK PyPI trigger: ${publish_cli_sdk_pypi}"
echo "SDK npm trigger: ${publish_cli_sdk_npm}"
echo "SDK gem trigger: ${publish_cli_sdk_gem}"
- name: Publish workspace crates to crates.io
if: steps.plan.outputs.count != '0'
shell: bash
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
cargo workspaces publish \
--publish-as-is \
--yes \
--locked \
--allow-branch "*" \
--publish-interval 15 \
--token "${CARGO_REGISTRY_TOKEN}"
- name: Nothing to publish
if: steps.plan.outputs.count == '0'
run: echo "All workspace crate versions in this tag are already published."
dispatch-distributions:
name: Trigger CLI distribution workflows
needs: publish
runs-on: ubuntu-latest
steps:
- name: Trigger GitHub CLI release
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'release-github.yml',
ref: '${{ needs.publish.outputs.tag }}',
inputs: {
tag: '${{ needs.publish.outputs.tag }}'
}
})
- name: Trigger npm CLI release
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'release-npm.yml',
ref: '${{ needs.publish.outputs.tag }}',
inputs: {
tag: '${{ needs.publish.outputs.tag }}'
}
})
- name: Trigger NuGet CLI release
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'release-nuget.yml',
ref: '${{ needs.publish.outputs.tag }}',
inputs: {
tag: '${{ needs.publish.outputs.tag }}'
}
})
- name: Trigger PyPI CLI release
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'release-pypi.yml',
ref: '${{ needs.publish.outputs.tag }}',
inputs: {
tag: '${{ needs.publish.outputs.tag }}'
}
})
dispatch-sdk-pypi:
name: Trigger SDK PyPI release
needs: publish
if: needs.publish.outputs.publish_cli_sdk_pypi == 'true'
runs-on: ubuntu-latest
steps:
- name: Trigger SDK PyPI release workflow
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'release-sdk-pypi.yml',
ref: '${{ needs.publish.outputs.tag }}',
inputs: {
tag: '${{ needs.publish.outputs.tag }}'
}
})
dispatch-sdk-npm:
name: Trigger SDK npm release
needs: publish
if: needs.publish.outputs.publish_cli_sdk_npm == 'true'
runs-on: ubuntu-latest
steps:
- name: Trigger SDK npm release workflow
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'release-sdk-npm.yml',
ref: '${{ needs.publish.outputs.tag }}',
inputs: {
tag: '${{ needs.publish.outputs.tag }}'
}
})
dispatch-sdk-gem:
name: Trigger SDK Ruby gem release
needs: publish
if: needs.publish.outputs.publish_cli_sdk_gem == 'true'
runs-on: ubuntu-latest
steps:
- name: Trigger SDK Ruby gem release workflow
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'release-sdk-gem.yml',
ref: '${{ needs.publish.outputs.tag }}',
inputs: {
tag: '${{ needs.publish.outputs.tag }}'
}
})