Repository navigation
176 lines (176 loc) · 7.98 KB
/
Copy pathpublish-crates.yml
File metadata and controls
176 lines (176 loc) · 7.98 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
name: Publish reviewed crates
on:
push:
tags: ['terraphim*-v*']
workflow_dispatch:
inputs:
auth_mode:
description: 'Bootstrap is only for a crate name never published before'
required: true
default: trusted
type: choice
options: [trusted, bootstrap]
permissions:
contents: read
concurrency:
group: crates-${{ github.ref_name }}
cancel-in-progress: false
env:
PYTHONDONTWRITEBYTECODE: '1'
CARGO_TERM_COLOR: never
jobs:
qualify:
if: github.repository == 'terraphim/terraphim-core' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
timeout-minutes: 45
outputs:
crate: ${{ steps.request.outputs.crate }}
version: ${{ steps.request.outputs.version }}
toolchain: ${{ steps.request.outputs.toolchain }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
ref: ${{ github.sha }}
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
with:
python-version: '3.12'
- name: Validate tag, manifests, ownership and dependency order
id: request
env:
TAG: ${{ github.ref_name }}
MODE: ${{ inputs.auth_mode || 'trusted' }}
run: python3 scripts/crates_release.py validate --tag "$TAG" --mode "$MODE" --receipt "$RUNNER_TEMP/request.json"
- name: Install pinned toolchain
env:
TOOLCHAIN: ${{ steps.request.outputs.toolchain }}
run: |
rustup toolchain install "$TOOLCHAIN" --profile minimal --component rustfmt --component clippy
rustup target add wasm32-unknown-unknown --toolchain "$TOOLCHAIN"
- name: Verify source and build the publishable package
env:
CRATE: ${{ steps.request.outputs.crate }}
VERSION: ${{ steps.request.outputs.version }}
TOOLCHAIN: ${{ steps.request.outputs.toolchain }}
TAG: ${{ github.ref_name }}
CARGO_HOME: ${{ runner.temp }}/crates-cargo
run: |
set -euo pipefail
python3 -m unittest discover -s tests -p 'test_crates_release.py' -v
cargo +"$TOOLCHAIN" fmt --all --check
cargo +"$TOOLCHAIN" clippy --locked -p "$CRATE" --all-targets -- -D warnings
cargo +"$TOOLCHAIN" test --locked -p "$CRATE" --all-targets
cargo +"$TOOLCHAIN" check --locked -p "$CRATE" --target wasm32-unknown-unknown --lib
cargo +"$TOOLCHAIN" package --locked --registry crates-io -p "$CRATE"
python3 scripts/crates_release.py unpack --tag "$TAG" --unpack-dir "$RUNNER_TEMP/unpacked" --receipt "$RUNNER_TEMP/archive-validation.json"
cd "$RUNNER_TEMP/unpacked/$CRATE-$VERSION"
cargo +"$TOOLCHAIN" test --locked --manifest-path Cargo.toml --all-targets
cd "$GITHUB_WORKSPACE"
python3 scripts/crates_release.py package --tag "$TAG" --receipt "$RUNNER_TEMP/qualified-package.json"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: crate-qualified-${{ github.run_attempt }}
path: ${{ runner.temp }}/qualified-package.json
if-no-files-found: error
publish:
needs: qualify
if: inputs.auth_mode != 'bootstrap'
environment: crates-io
runs-on: ubuntu-latest
timeout-minutes: 45
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
ref: ${{ github.sha }}
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
with:
python-version: '3.12'
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
with:
name: crate-qualified-${{ github.run_attempt }}
path: ${{ runner.temp }}/qualified
- name: Reproduce qualified bytes before authentication
env:
CRATE: ${{ needs.qualify.outputs.crate }}
TOOLCHAIN: ${{ needs.qualify.outputs.toolchain }}
TAG: ${{ github.ref_name }}
CARGO_HOME: ${{ runner.temp }}/crates-cargo
run: |
set -euo pipefail
python3 scripts/crates_release.py validate --tag "$TAG" --mode trusted --receipt "$RUNNER_TEMP/recheck.json"
rustup toolchain install "$TOOLCHAIN" --profile minimal
cargo +"$TOOLCHAIN" package --locked --registry crates-io -p "$CRATE"
python3 scripts/crates_release.py compare --tag "$TAG" --expected "$RUNNER_TEMP/qualified/qualified-package.json" --receipt "$RUNNER_TEMP/reproduced.json"
- name: Obtain temporary crates.io publish token
id: auth
uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18
- name: Publish and verify actual registry checksum
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
CRATE: ${{ needs.qualify.outputs.crate }}
TOOLCHAIN: ${{ needs.qualify.outputs.toolchain }}
TAG: ${{ github.ref_name }}
CARGO_HOME: ${{ runner.temp }}/crates-cargo
run: |
set -euo pipefail
cargo +"$TOOLCHAIN" publish --locked --registry crates-io -p "$CRATE"
python3 scripts/crates_release.py readback --tag "$TAG" --expected "$RUNNER_TEMP/qualified/qualified-package.json" --receipt "$RUNNER_TEMP/published.json"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: crate-published-${{ github.run_attempt }}
path: ${{ runner.temp }}/published.json
if-no-files-found: error
bootstrap:
needs: qualify
if: github.event_name == 'workflow_dispatch' && inputs.auth_mode == 'bootstrap'
environment: crates-io-bootstrap
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
ref: ${{ github.sha }}
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
with:
python-version: '3.12'
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
with:
name: crate-qualified-${{ github.run_attempt }}
path: ${{ runner.temp }}/qualified
- name: Reproduce first-publication package before authentication
env:
CRATE: ${{ needs.qualify.outputs.crate }}
TOOLCHAIN: ${{ needs.qualify.outputs.toolchain }}
TAG: ${{ github.ref_name }}
CARGO_HOME: ${{ runner.temp }}/crates-cargo
run: |
set -euo pipefail
python3 scripts/crates_release.py validate --tag "$TAG" --mode bootstrap --receipt "$RUNNER_TEMP/recheck.json"
rustup toolchain install "$TOOLCHAIN" --profile minimal
cargo +"$TOOLCHAIN" package --locked --registry crates-io -p "$CRATE"
python3 scripts/crates_release.py compare --tag "$TAG" --expected "$RUNNER_TEMP/qualified/qualified-package.json" --receipt "$RUNNER_TEMP/reproduced.json"
- name: Bootstrap previously unpublished crate and verify checksum
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
CRATE: ${{ needs.qualify.outputs.crate }}
TOOLCHAIN: ${{ needs.qualify.outputs.toolchain }}
TAG: ${{ github.ref_name }}
CARGO_HOME: ${{ runner.temp }}/crates-cargo
run: |
set -euo pipefail
test -n "$CARGO_REGISTRY_TOKEN"
cargo +"$TOOLCHAIN" publish --locked --registry crates-io -p "$CRATE"
python3 scripts/crates_release.py readback --tag "$TAG" --expected "$RUNNER_TEMP/qualified/qualified-package.json" --receipt "$RUNNER_TEMP/published.json"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: crate-bootstrapped-${{ github.run_attempt }}
path: ${{ runner.temp }}/published.json
if-no-files-found: error