Skip to content

Commit 70b3499

Browse files
authored
Merge pull request #136 from beNative/codex/fix-auto-update-checksum-mismatch-ocm9i3
Fix release automation to publish verified update manifests
2 parents 8a7f5e1 + 72495c1 commit 70b3499

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

.github/workflows/release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ jobs:
236236
with:
237237
node-version: 20
238238

239+
- name: Install dependencies
240+
run: npm ci
241+
239242
- name: Generate release notes
240243
id: notes
241244
run: |
@@ -253,6 +256,37 @@ jobs:
253256
env:
254257
GITHUB_REPOSITORY: ${{ github.repository }}
255258

259+
- name: Verify auto-update manifests
260+
run: |
261+
set -euo pipefail
262+
metadata_dirs=()
263+
while IFS= read -r -d '' metadata_file; do
264+
dir=$(dirname "$metadata_file")
265+
if [[ "$metadata_file" == *"/builder-debug.yml" ]]; then
266+
continue
267+
fi
268+
skip=0
269+
for existing in "${metadata_dirs[@]}"; do
270+
if [[ "$existing" == "$dir" ]]; then
271+
skip=1
272+
break
273+
fi
274+
done
275+
if [[ $skip -eq 0 ]]; then
276+
metadata_dirs+=("$dir")
277+
fi
278+
done < <(find release-artifacts -type f -name '*.yml' -print0)
279+
280+
if [[ ${#metadata_dirs[@]} -eq 0 ]]; then
281+
echo "::error::No auto-update metadata (.yml) files were found in the release artifacts." >&2
282+
exit 1
283+
fi
284+
285+
for dir in "${metadata_dirs[@]}"; do
286+
echo "Verifying auto-update metadata in ${dir}" >&2
287+
node scripts/test-auto-update.mjs --local "$dir"
288+
done
289+
256290
- name: Display release notes
257291
run: |
258292
echo "Generated release notes:" >&2

scripts/generate-release-notes.mjs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ function isReleaseAsset(filename) {
118118
}
119119

120120
function isAutoUpdateSupportFile(filename) {
121+
if (filename === 'builder-debug.yml') {
122+
return false;
123+
}
121124
if (filename.endsWith('.blockmap')) {
122125
return true;
123126
}
@@ -156,13 +159,28 @@ async function normaliseReleaseAsset(filePath) {
156159
const fileName = path.basename(filePath);
157160
const normalisedName = normaliseInstallerFileName(fileName);
158161
if (normalisedName === fileName) {
159-
return { filePath, fileName };
162+
return { filePath, fileName, originalFileName: fileName };
160163
}
161164

162165
const targetPath = path.join(path.dirname(filePath), normalisedName);
163166
await fs.rename(filePath, targetPath);
164167
console.log(`Normalised release asset name: ${fileName} -> ${normalisedName}`);
165-
return { filePath: targetPath, fileName: normalisedName };
168+
return { filePath: targetPath, fileName: normalisedName, originalFileName: fileName };
169+
}
170+
171+
async function computeSha512(filePath) {
172+
return new Promise((resolve, reject) => {
173+
const hash = crypto.createHash('sha512');
174+
const stream = createReadStream(filePath);
175+
stream.on('data', (chunk) => hash.update(chunk));
176+
stream.on('error', reject);
177+
stream.on('end', () => resolve(hash.digest('base64')));
178+
});
179+
}
180+
181+
async function getFileSize(filePath) {
182+
const stats = await fs.stat(filePath);
183+
return stats.size;
166184
}
167185

168186
async function computeSha512(filePath) {
@@ -198,7 +216,7 @@ async function collectAssets(artifactRoot) {
198216
const arch = normaliseArch(parts.slice(1).join('-') || parts[0]);
199217
const files = await walkFiles(path.join(artifactRoot, dirName));
200218
for (const file of files) {
201-
const { filePath: normalisedPath, fileName: normalisedName } = await normaliseReleaseAsset(file);
219+
const { filePath: normalisedPath, fileName: normalisedName, originalFileName } = await normaliseReleaseAsset(file);
202220
const fileName = normalisedName;
203221
const filePath = normalisedPath;
204222
if (isAutoUpdateSupportFile(fileName)) {
@@ -220,6 +238,7 @@ async function collectAssets(artifactRoot) {
220238
arch,
221239
fileName,
222240
filePath,
241+
originalFileName,
223242
format: detectFormat(fileName),
224243
sha512,
225244
size,

scripts/test-auto-update.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,9 @@ async function runRemoteCheck({ owner, repo, tag, skipHttp, skipDownload }) {
413413
async function runLocalCheck({ directory, skipDownload }) {
414414
const resolvedDirectory = path.resolve(directory);
415415
const entries = await fs.readdir(resolvedDirectory);
416-
const metadataFiles = entries.filter((entry) => entry.endsWith('.yml'));
416+
const metadataFiles = entries.filter(
417+
(entry) => entry.endsWith('.yml') && entry !== 'builder-debug.yml',
418+
);
417419
if (metadataFiles.length === 0) {
418420
throw new Error(`No metadata files were found in ${resolvedDirectory}`);
419421
}

0 commit comments

Comments
 (0)