|
| 1 | +name: Post-Release SHA-256 Hash Calculation |
| 2 | +on: |
| 3 | + release: |
| 4 | + types: [published] |
| 5 | +jobs: |
| 6 | + calculate-hash: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + steps: |
| 9 | + - name: Checkout Repository |
| 10 | + uses: actions/checkout@v2 |
| 11 | + - name: Fetch Release Assets |
| 12 | + id: fetch-assets |
| 13 | + uses: actions/github-script@v5 |
| 14 | + env: |
| 15 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 16 | + with: |
| 17 | + script: | |
| 18 | + const fs = require('fs'); |
| 19 | +
|
| 20 | + const response = await github.rest.repos.listReleaseAssets({ |
| 21 | + owner: context.repo.owner, |
| 22 | + repo: context.repo.repo, |
| 23 | + release_id: context.payload.release.id |
| 24 | + }); |
| 25 | +
|
| 26 | + const assets = response.data.map(asset => ({ url: asset.url, name: asset.name })); |
| 27 | + fs.writeFileSync('assets.json', JSON.stringify(assets)); |
| 28 | +
|
| 29 | + - name: Download and Calculate SHA-256 Hashes |
| 30 | + run: | |
| 31 | + mkdir -p downloads |
| 32 | + echo "File Name | SHA-256 Hash" >> SHA256SUMS.txt |
| 33 | + echo "--------- | ------------" >> SHA256SUMS.txt |
| 34 | + jq -c '.[]' assets.json | while read -r asset; do |
| 35 | + url=$(echo $asset | jq -r '.url') |
| 36 | + name=$(echo $asset | jq -r '.name') |
| 37 | + curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/octet-stream" -o "downloads/$name" "$url" |
| 38 | + echo "Calculating SHA-256 for $name" |
| 39 | + hash=$(sha256sum "downloads/$name" | awk '{print $1}') |
| 40 | + echo "$name | $hash" >> SHA256SUMS.txt |
| 41 | + done |
| 42 | + - name: Update Release Description with SHA-256 Hashes |
| 43 | + uses: actions/github-script@v5 |
| 44 | + with: |
| 45 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + script: | |
| 47 | + const fs = require('fs'); |
| 48 | + const sha256sums = fs.readFileSync('SHA256SUMS.txt', 'utf8'); |
| 49 | + const { owner, repo } = context.repo; |
| 50 | + const release = context.payload.release; |
| 51 | + const newBody = release.body + '\n\n### SHA-256 Hashes\n' + sha256sums; |
| 52 | + await github.rest.repos.updateRelease({ |
| 53 | + owner, |
| 54 | + repo, |
| 55 | + release_id: release.id, |
| 56 | + body: newBody |
| 57 | + }); |
0 commit comments