Repository navigation
225 lines (219 loc) · 10.8 KB
/
Copy pathplugins.yml
File metadata and controls
225 lines (219 loc) · 10.8 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
name: Plugins
# Official bytes live in COS. Every app download goes through the statistics API.
on:
push:
branches: [dev]
# Only plugin-relevant inputs launch this pipeline: app releases, lockfile
# churn and build-tool edits must not republish unchanged online plugins.
paths:
- 'market/**'
- 'packages/plugin-ui-sdk/**'
- 'packages/plugin-build/**'
- 'crates/tf-plugin-api/**'
- 'crates/tf-plugin-guest/**'
- 'wit/**'
- 'scripts/publish-plugins.sh'
- 'scripts/cos-setup.sh'
- 'scripts/migrate-plugin-assets.sh'
- '.github/workflows/plugins.yml'
workflow_dispatch:
inputs:
bootstrap:
description: 'Allow first COS catalog initialization after checking existing assets'
type: boolean
default: false
permissions:
contents: read
concurrency:
group: plugins-production
cancel-in-progress: false
env:
CARGO_TERM_COLOR: always
RELEASE_TAG: plugins
PLUGIN_ASSET_BASE_URL: https://plugins.toolforge.devlive.org
PLUGIN_STATS_BASE_URL: https://stats.toolforge.devlive.org
jobs:
build:
if: github.ref == 'refs/heads/dev'
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 22
- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
- name: Install WASM target and build trusted tools without signing secrets
run: |
# Pin a specific toolchain: a channel name (stable) makes rustup sync
# channel updates on every shim call, and a mid-build sync replaced
# rustc while cargo was compiling (run 39738297419).
rustup toolchain install 1.99.1 --profile minimal --target wasm32-wasip2
rustup default 1.99.1
cargo build --locked --release -p xtask
pnpm install --frozen-lockfile
shellcheck scripts/cos-setup.sh scripts/publish-plugins.sh scripts/migrate-plugin-assets.sh
cargo test --locked -p xtask
- name: Read complete GitHub history without changing historical bytes
env:
GH_TOKEN: ${{ github.token }}
run: scripts/migrate-plugin-assets.sh dist/plugins
- name: Install COSCLI and write its temporary credentials configuration
env:
COS_SECRET_ID: ${{ secrets.COS_SECRET_ID }}
COS_SECRET_KEY: ${{ secrets.COS_SECRET_KEY }}
COS_SESSION_TOKEN: ${{ secrets.COS_SESSION_TOKEN }}
COS_REGION: ${{ vars.COS_REGION || 'ap-singapore' }}
COS_BUCKET: toolforge-1258585472
run: scripts/cos-setup.sh
- name: Read existing COS catalog and find unpublished versions
env:
BOOTSTRAP: ${{ inputs.bootstrap || false }}
COS_BUCKET: toolforge-1258585472
COSCLI_BIN: ${{ runner.temp }}/coscli
COS_CONFIG_PATH: ${{ runner.temp }}/cos.yaml
run: |
set -euo pipefail
# The bucket is private: read through authenticated COSCLI, never anonymous HTTP.
if "$COSCLI_BIN" cp "cos://$COS_BUCKET/release-catalog.json" "$RUNNER_TEMP/prior-catalog.json" -c "$COS_CONFIG_PATH" --disable-log --fail-output=false --process-log=false; then
jq -e '.schemaVersion == 1 and (.sourceCommit | test("^[a-f0-9]{40}$"))' "$RUNNER_TEMP/prior-catalog.json" >/dev/null
elif [[ $BOOTSTRAP == true ]]; then
rm -f "$RUNNER_TEMP/prior-catalog.json"
else
echo '::error::Cannot read COS catalog through COSCLI; first publication requires a bootstrap run'; exit 1
fi
python3 - <<'PY'
import hashlib, json, os, pathlib, re, subprocess
root = pathlib.Path('dist/plugins')
assets = {a['name'] for a in json.loads((root / 'previous-release.json').read_text())['assets']}
prior_path = pathlib.Path(os.environ['RUNNER_TEMP']) / 'prior-catalog.json'
prior = json.loads(prior_path.read_text()) if prior_path.exists() else None
# A previous run may have published COS but only partially mirrored GitHub.
# Recover its exact signed bytes rather than rebuilding an existing version.
if prior:
for item in prior['plugins']:
name = f"{item['id']}-{item['version']}.tfp"
if name in assets:
continue
key = f"packages/{item['id']}/{item['version']}/{item['sha256']}.tfp"
if item['objectKey'] != key or not re.fullmatch(r'[a-z0-9][a-z0-9.+-]*\.tfp', name) or not re.fullmatch(r'[a-f0-9]{64}', item['sha256']):
raise SystemExit('Unsafe existing COS catalog metadata')
target = root / 'previous' / name
target.parent.mkdir(parents=True, exist_ok=True)
target.unlink(missing_ok=True)
subprocess.run([os.environ['COSCLI_BIN'], 'cp', f"cos://{os.environ['COS_BUCKET']}/{key}", str(target), '-c', os.environ['COS_CONFIG_PATH'], '--disable-log', '--fail-output=false', '--process-log=false'], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
if target.stat().st_size != item['size'] or hashlib.sha256(target.read_bytes()).hexdigest() != item['sha256']:
raise SystemExit('Cannot recover verified historical COS bytes')
assets.add(name)
PY
# Same check authors run locally and PR CI runs against the merge-base.
# Without a prior catalog (bootstrap) HEAD is the base: only pending is computed.
base=HEAD
if [[ -f $RUNNER_TEMP/prior-catalog.json ]]; then
base=$(jq -r .sourceCommit "$RUNNER_TEMP/prior-catalog.json")
fi
target/release/xtask plugin versions --base "$base" \
--published dist/plugins/previous-release.json --published dist/plugins/previous \
--pending dist/plugins/pending.txt
- name: Build unsigned candidates without signing credentials
run: |
mkdir -p dist/unsigned
while IFS= read -r slug; do
target/release/xtask plugin pack "$slug" --unsigned --out dist/unsigned
done < dist/plugins/pending.txt
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: plugin-candidates-${{ github.run_id }}
path: |
dist/unsigned/
dist/plugins/
if-no-files-found: error
retention-days: 7
overwrite: true
publish:
needs: build
if: github.ref == 'refs/heads/dev'
runs-on: ubuntu-24.04
environment: plugins-production
permissions:
contents: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Build the trusted signing tool on a clean runner
run: |
cargo build --locked --release -p xtask
cargo test --locked -p xtask
shellcheck scripts/cos-setup.sh scripts/publish-plugins.sh scripts/migrate-plugin-assets.sh
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: plugin-candidates-${{ github.run_id }}
path: dist
- name: Install COSCLI and write its temporary credentials configuration
env:
COS_SECRET_ID: ${{ secrets.COS_SECRET_ID }}
COS_SECRET_KEY: ${{ secrets.COS_SECRET_KEY }}
COS_SESSION_TOKEN: ${{ secrets.COS_SESSION_TOKEN }}
COS_REGION: ${{ vars.COS_REGION || 'ap-singapore' }}
COS_BUCKET: toolforge-1258585472
run: scripts/cos-setup.sh
- name: Independently read current history with the publishing identity
env:
GH_TOKEN: ${{ github.token }}
BOOTSTRAP: ${{ inputs.bootstrap || false }}
COS_BUCKET: toolforge-1258585472
run: |
scripts/migrate-plugin-assets.sh dist/verified-history
cp dist/verified-history/previous-release.json dist/plugins/previous-release.json
cp -a dist/verified-history/previous/. dist/plugins/previous/
# The bucket is private: read through authenticated COSCLI, never anonymous HTTP.
if "$RUNNER_TEMP/coscli" cp "cos://$COS_BUCKET/release-catalog.json" "$RUNNER_TEMP/prior-catalog.json" -c "$RUNNER_TEMP/cos.yaml" --disable-log --fail-output=false --process-log=false; then
jq -e '.schemaVersion == 1 and (.sourceCommit | test("^[a-f0-9]{40}$"))' "$RUNNER_TEMP/prior-catalog.json" >/dev/null
elif [[ $BOOTSTRAP == true ]]; then
rm -f "$RUNNER_TEMP/prior-catalog.json"
else
echo '::error::Cannot read COS catalog through COSCLI; first publication requires a bootstrap run'; exit 1
fi
- name: Independently sign candidates using the precompiled tool
env:
TOOLFORGE_PLUGIN_KEY: ${{ secrets.TOOLFORGE_PLUGIN_KEY }}
run: |
set -euo pipefail
shopt -s nullglob
for package in dist/unsigned/*.tfp; do
target/release/xtask plugin sign "$package" --out dist/plugins
done
- name: Validate complete inventory and generate registry and catalog
run: |
target/release/xtask plugin verify dist/plugins
previous=()
if [[ -f "$RUNNER_TEMP/prior-catalog.json" ]]; then
previous=(--merge-catalog "$RUNNER_TEMP/prior-catalog.json")
fi
target/release/xtask plugin index dist/plugins "$PLUGIN_STATS_BASE_URL" --source-commit "$GITHUB_SHA" --generation "$GITHUB_RUN_NUMBER" "${previous[@]}"
- name: Publish verified objects, import catalog, then publish registry
env:
GH_TOKEN: ${{ github.token }}
COS_BUCKET: toolforge-1258585472
PLUGIN_CATALOG_SSH_TARGET: ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}
PLUGIN_CATALOG_SSH_KEY: ${{ secrets.SSH_KEY }}
run: |
set -euo pipefail
umask 077
task_dir=$(mktemp -d "$RUNNER_TEMP/plugin-publish.XXXXXX")
trap 'rm -rf "$task_dir"' EXIT
export COSCLI_BIN="$RUNNER_TEMP/coscli" COS_CONFIG_PATH="$RUNNER_TEMP/cos.yaml" XTASK_BIN=target/release/xtask
export PLUGIN_SSH_KEY_PATH="$task_dir/id"
python3 - <<'PY'
import os, pathlib
if not os.environ.get('PLUGIN_CATALOG_SSH_KEY'):
raise SystemExit('Missing protected publishing configuration: PLUGIN_CATALOG_SSH_KEY')
pathlib.Path(os.environ['PLUGIN_SSH_KEY_PATH']).write_text(os.environ['PLUGIN_CATALOG_SSH_KEY'] + '\n')
PY
unset PLUGIN_CATALOG_SSH_KEY
scripts/publish-plugins.sh dist/plugins