-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add an action to generate checksum table from release draft (#2962)
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
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
b1347f2
There was a problem hiding this comment.
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