Skip to content

Commit

Permalink
ci: add an action to generate checksum table from release draft (#2962)
Browse files Browse the repository at this point in the history
This commit adds an action to generate checksum table from
release draft.

The action runs a script to download assets into a temporary
directory, then run a script to load binaries to generate
the checksum table and print it in console.

Ref: Magickbase/neuron-public-issues#326
  • Loading branch information
Keith-CY authored Nov 28, 2023
1 parent c530736 commit b1347f2
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/checksums-of-release-draft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Checksums of release draft

on:
workflow_run:
workflows:
- Package Neuron for Release Draft
types:
- completed

jobs:
checksums:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 'latest'

- name: Download binaries
run: |
mkdir -p /tmp/Neuron
node ./scripts/download-binaries-from-release-draft.js /tmp/Neuron
shell: pwsh
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}

- name: Checksums
run: node ./scripts/generate-checksum-table.js /tmp/Neuron
shell: pwsh
57 changes: 57 additions & 0 deletions scripts/download-binaries-from-release-draft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const { pipeline } = require('node:stream/promises')
const { existsSync, createWriteStream } = require('node:fs')

const { REPO, TOKEN } = process.env
const GITHUB_API_URL = 'https://api.github.com'

const download = async (directory) => {
if (!existsSync(directory)) {
throw new Error(`Directory ${directory} does not exist`)
}

const releases = await fetch(`${GITHUB_API_URL}/repos/${REPO}/releases`, {
headers: { Authorization: `Bearer ${TOKEN}` },
}).then((res) => res.json())

const draft = releases.find((r) => r.draft)

if (!draft) {
throw new Error('No release draft found')
}

const assetList = await fetch(`${GITHUB_API_URL}/repos/${REPO}/releases/${draft.id}/assets`, {
headers: { Authorization: `Bearer ${TOKEN}` },
})
.then((res) => res.json())
.then((res) => res.map(({ name, url }) => ({ name, url })))

assetList.forEach(async ({ name, url }) => {
const path = `${directory}/${name}`

await pipeline(
await fetch(url, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/octet-stream',
Accept: 'application/octet-stream',
},
})
.then(async (res) => res.body)
.catch(() => {
throw new Error('Fail to fetch asset')
}),

createWriteStream(path)
)
})
}

if (process.argv.length < 3) {
throw new Error(
`Directory for binaries is required, use command as 'node ./download-binaries-from-release-draft.js ./binaries`
)
}

const directory = process.argv[2]

download(directory)

1 comment on commit b1347f2

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 7020505974

Please sign in to comment.