Skip to content

Commit 973cb49

Browse files
committed
chore(ci): move downstream release rewriting out of cargo-dist workflow
1 parent 4a5c641 commit 973cb49

File tree

2 files changed

+85
-54
lines changed

2 files changed

+85
-54
lines changed

.github/workflows/sifli-mirror-sync.yml

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ on:
2323

2424
permissions:
2525
actions: read
26-
contents: read
26+
contents: write
2727

2828
jobs:
2929
sync-release-assets:
@@ -37,7 +37,17 @@ jobs:
3737
COS_DOWNLOAD_REGION: ${{ secrets.COS_DOWNLOAD_REGION }}
3838
COS_DOWNLOAD_BUCKET: ${{ secrets.COS_DOWNLOAD_BUCKET }}
3939
COS_DOWNLOAD_FLUSH_URL: ${{ secrets.COS_DOWNLOAD_FLUSH_URL }}
40+
CDN_BASE: https://downloads.sifli.com/github_assets/${{ github.repository }}/releases/download/
4041
steps:
42+
- name: Resolve release tag
43+
run: |
44+
tag_name="${{ github.event.workflow_run.head_branch }}"
45+
if [[ -z "${tag_name}" ]]; then
46+
echo "Unable to determine tag name from workflow_run payload."
47+
exit 1
48+
fi
49+
echo "TAG_NAME=${tag_name}" >> "$GITHUB_ENV"
50+
4151
- name: Check mirror sync configuration
4252
id: config
4353
run: |
@@ -67,12 +77,15 @@ jobs:
6777
exit 1
6878
fi
6979
70-
tag_name="$(jq -r '.announcement_tag // empty' "${manifest_path}")"
71-
if [[ -z "${tag_name}" ]]; then
80+
manifest_tag="$(jq -r '.announcement_tag // empty' "${manifest_path}")"
81+
if [[ -z "${manifest_tag}" ]]; then
7282
echo "Unable to determine announcement tag from ${manifest_path}"
7383
exit 1
7484
fi
75-
echo "TAG_NAME=${tag_name}" >> "$GITHUB_ENV"
85+
if [[ "${manifest_tag}" != "${TAG_NAME}" ]]; then
86+
echo "Release tag mismatch: workflow_run=${TAG_NAME}, manifest=${manifest_tag}"
87+
exit 1
88+
fi
7689
7790
while IFS= read -r file; do
7891
name="$(basename "${file}")"
@@ -84,6 +97,33 @@ jobs:
8497
cp "${file}" "${destination}"
8598
done < <(find downloaded-artifacts -type f ! -name 'dist-manifest.json' ! -name '*-dist-manifest.json')
8699
100+
- name: Rewrite installer download URLs to SiFli CDN
101+
if: ${{ steps.config.outputs.enabled == 'true' }}
102+
uses: actions/github-script@v7
103+
with:
104+
script: |
105+
const fs = require('fs');
106+
const path = require('path');
107+
108+
const artifactsDir = 'artifacts';
109+
const cdnBase = process.env.CDN_BASE;
110+
const releasePattern = /https:\/\/github\.com\/.+?\/releases\/download\//g;
111+
112+
for (const fileName of fs.readdirSync(artifactsDir)) {
113+
if (!/installer\.(sh|ps1)$/.test(fileName)) {
114+
continue;
115+
}
116+
117+
const filePath = path.join(artifactsDir, fileName);
118+
const original = fs.readFileSync(filePath, 'utf8');
119+
const rewritten = original.replace(releasePattern, cdnBase);
120+
121+
if (rewritten !== original) {
122+
fs.writeFileSync(filePath, rewritten, 'utf8');
123+
core.info(`Rewrote ${fileName}`);
124+
}
125+
}
126+
87127
- name: Upload release assets to SiFli CDN
88128
if: ${{ steps.config.outputs.enabled == 'true' }}
89129
uses: OpenSiFli/SiFliMirrorSync@v1
@@ -97,3 +137,40 @@ jobs:
97137
delete_remote: true
98138
flush_url: ${{ env.COS_DOWNLOAD_FLUSH_URL }}
99139
working_directory: artifacts
140+
141+
- name: Update GitHub release metadata
142+
env:
143+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
144+
CDN_ENABLED: ${{ steps.config.outputs.enabled }}
145+
uses: actions/github-script@v7
146+
with:
147+
github-token: ${{ secrets.GITHUB_TOKEN }}
148+
script: |
149+
const repo = process.env.GITHUB_REPOSITORY;
150+
const tag = process.env.TAG_NAME;
151+
const cdnEnabled = process.env.CDN_ENABLED === 'true';
152+
const cdnBase = process.env.CDN_BASE;
153+
154+
const { data: release } = await github.rest.repos.getReleaseByTag({
155+
owner: context.repo.owner,
156+
repo: context.repo.repo,
157+
tag,
158+
});
159+
160+
let body = release.body ?? '';
161+
if (cdnEnabled) {
162+
body = body.replace(/https:\/\/github\.com\/.+?\/releases\/download\//g, cdnBase);
163+
}
164+
body = body.replace(/--repo probe-rs\/probe-rs/g, `--repo ${repo}`);
165+
body = body.replace(
166+
/https:\/\/github\.com\/probe-rs\/probe-rs\/attestations/g,
167+
`https://github.com/${repo}/attestations`,
168+
);
169+
170+
await github.rest.repos.updateRelease({
171+
owner: context.repo.owner,
172+
repo: context.repo.repo,
173+
release_id: release.id,
174+
body,
175+
prerelease: false,
176+
});

.github/workflows/v-release.yml

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -212,33 +212,6 @@ jobs:
212212
echo "EOF" >> "$GITHUB_OUTPUT"
213213
214214
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
215-
- name: Rewrite installer download URLs to SiFli CDN
216-
uses: actions/github-script@v7
217-
with:
218-
script: |
219-
const fs = require('fs');
220-
const manifest = JSON.parse(fs.readFileSync('dist-manifest.json', 'utf8'));
221-
const files = (manifest.upload_files || []).filter((f) => /installer\.(sh|ps1)$/.test(f));
222-
if (!files.length) {
223-
core.info('No installer scripts found to rewrite.');
224-
return;
225-
}
226-
const base = 'https://downloads.sifli.com/github_assets/OpenSiFli/probe-rs/releases/download/';
227-
const re = /https:\/\/github\.com\/.+?\/releases\/download\//g;
228-
for (const file of files) {
229-
if (!fs.existsSync(file)) {
230-
core.warning(`Installer not found: ${file}`);
231-
continue;
232-
}
233-
const text = fs.readFileSync(file, 'utf8');
234-
const replaced = text.replace(re, base);
235-
if (replaced !== text) {
236-
fs.writeFileSync(file, replaced, 'utf8');
237-
core.info(`Rewrote download base in ${file}`);
238-
} else {
239-
core.info(`No GitHub release download URLs found in ${file}`);
240-
}
241-
}
242215
- name: "Upload artifacts"
243216
uses: actions/upload-artifact@v6
244217
with:
@@ -303,34 +276,15 @@ jobs:
303276
rm -f artifacts/*-dist-manifest.json
304277
- name: Create GitHub Release
305278
env:
279+
PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}"
306280
ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}"
307281
ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}"
308282
RELEASE_COMMIT: "${{ github.sha }}"
309283
run: |
310-
export RUNNER_TEMP
311-
python3 <<'PY'
312-
import os
313-
import pathlib
314-
import re
315-
316-
body = os.environ["ANNOUNCEMENT_BODY"]
317-
body = re.sub(
318-
r"https://github\.com/.+?/releases/download/",
319-
"https://downloads.sifli.com/github_assets/OpenSiFli/probe-rs/releases/download/",
320-
body,
321-
)
322-
body = body.replace(
323-
"--repo probe-rs/probe-rs",
324-
"--repo OpenSiFli/probe-rs",
325-
)
326-
body = body.replace(
327-
"https://github.com/probe-rs/probe-rs/attestations",
328-
"https://github.com/OpenSiFli/probe-rs/attestations",
329-
)
330-
pathlib.Path(os.environ["RUNNER_TEMP"], "notes.txt").write_text(body, encoding="utf-8")
331-
PY
284+
# Write and read notes from a file to avoid quoting breaking things
285+
echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
332286
333-
gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*
287+
gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*
334288
335289
announce:
336290
needs:

0 commit comments

Comments
 (0)