2323
2424permissions :
2525 actions : read
26- contents : read
26+ contents : write
2727
2828jobs :
2929 sync-release-assets :
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}")"
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+ });
0 commit comments