|
1 | | -import { readFileSync } from 'node:fs'; |
| 1 | +import { readFileSync, appendFileSync } from 'node:fs'; |
2 | 2 | import { createHash } from 'node:crypto'; |
3 | 3 |
|
4 | 4 | const lines = readFileSync('CHECKSUMS.sha256', 'utf-8').trim().split('\n'); |
| 5 | +let failed = false; |
| 6 | +let summary = '### Checksum Verification Results\n\n| File | Status | Expected | Actual |\n| --- | --- | --- | --- |\n'; |
| 7 | + |
5 | 8 | for (const line of lines) { |
6 | 9 | const [expectedHash, file] = line.trim().split(/\s+/); |
7 | 10 | if (!expectedHash || !file) continue; |
8 | | - const content = readFileSync(file); |
9 | | - const actualHash = createHash('sha256').update(content).digest('hex'); |
| 11 | + let actualHash = ''; |
| 12 | + try { |
| 13 | + const content = readFileSync(file); |
| 14 | + actualHash = createHash('sha256').update(content).digest('hex'); |
| 15 | + } catch (err: any) { |
| 16 | + actualHash = 'FILE_READ_ERROR: ' + err.message; |
| 17 | + } |
10 | 18 | if (expectedHash !== actualHash) { |
11 | | - console.error(`SHA256 mismatch for ${file}:\n expected: ${expectedHash}\n actual: ${actualHash}`); |
12 | | - process.exit(1); |
| 19 | + failed = true; |
| 20 | + console.error(`::error file=${file}::SHA256 mismatch for ${file}: expected ${expectedHash}, got ${actualHash}`); |
| 21 | + summary += `| \`${file}\` | ❌ Failed | \`${expectedHash.slice(0, 10)}...\` | \`${actualHash.slice(0, 10)}...\` |\n`; |
| 22 | + } else { |
| 23 | + summary += `| \`${file}\` | ✅ Match | \`${expectedHash.slice(0, 10)}...\` | \`${actualHash.slice(0, 10)}...\` |\n`; |
13 | 24 | } |
14 | 25 | } |
| 26 | + |
| 27 | +if (process.env.GITHUB_STEP_SUMMARY) { |
| 28 | + try { |
| 29 | + appendFileSync(process.env.GITHUB_STEP_SUMMARY, summary); |
| 30 | + } catch {} |
| 31 | +} |
| 32 | + |
| 33 | +if (failed) { |
| 34 | + process.exit(1); |
| 35 | +} |
15 | 36 | console.log(`Verified ${lines.length} release checksums successfully!`); |
0 commit comments