-
Notifications
You must be signed in to change notification settings - Fork 92
ci: add an action to generate checksum table from release draft #2962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Keith-CY
merged 2 commits into
develop
from
add-action-to-generate-checksum-table-of-release-draft
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.