Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment thread
homura marked this conversation as resolved.
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)