ci: add more automation to release and asset creation
This commit is contained in:
parent
2e9af3a5a8
commit
fbac6b2ddf
135
.github/workflows/build-all.yml
vendored
135
.github/workflows/build-all.yml
vendored
@ -2,6 +2,11 @@ name: Build All Latest Assets
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
newRelease:
|
||||
description: 'Upload assets to new draft release?'
|
||||
default: true
|
||||
type: boolean
|
||||
|
||||
jobs:
|
||||
build-alpine:
|
||||
@ -16,33 +21,113 @@ jobs:
|
||||
uses: ./.github/workflows/build-windows.yml
|
||||
|
||||
collect-artifacts:
|
||||
permissions:
|
||||
contents: write
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build-alpine, build-linux, build-linuxstatic, build-macos, build-windows]
|
||||
steps:
|
||||
- run: echo Finished with builds
|
||||
- name: Download workflow artifacts
|
||||
uses: dawidd6/action-download-artifact@v2.24.3
|
||||
- run: echo Is making new release? '${{ inputs.newRelease }}'
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
workflow: build-alpine.yml
|
||||
path: artifacts
|
||||
- name: Download workflow artifacts
|
||||
uses: dawidd6/action-download-artifact@v2.24.3
|
||||
path: downloaded-artifacts
|
||||
|
||||
- name: Get previous release tag
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
id: get_previous_release
|
||||
run: |
|
||||
PREV_RELEASE=$(gh release list --limit 1 --exclude-drafts --exclude-pre-releases | cut -f3)
|
||||
echo "Using release ${PREV_RELEASE}"
|
||||
echo "prev_release=${PREV_RELEASE}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Get previously released artifacts
|
||||
if: ${{ inputs.newRelease }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
gh release download ${{ steps.get_previous_release.outputs.prev_release }} --dir release-artifacts
|
||||
|
||||
- name: Create artifact folders
|
||||
run: mkdir artifact-binaries && mkdir artifact-shas
|
||||
|
||||
- name: Copy previous release artifacts to artifact folders
|
||||
if: ${{ inputs.newRelease }}
|
||||
run: |
|
||||
pushd release-artifacts
|
||||
pwd
|
||||
ls -la
|
||||
mv *.sha256sum ../artifact-shas/.
|
||||
mv * ../artifact-binaries/.
|
||||
popd
|
||||
|
||||
- name: Copy current workflow artifacts to artifact folders
|
||||
run: |
|
||||
pushd downloaded-artifacts
|
||||
pwd
|
||||
ls -la
|
||||
for f in $(ls); do
|
||||
mv $f/*.sha256sum ../artifact-shas/.
|
||||
mv $f/* ../artifact-binaries/.
|
||||
done
|
||||
popd
|
||||
|
||||
- name: Check SHAs
|
||||
run: |
|
||||
cd artifact-binaries
|
||||
ls ../artifact-shas/*.sha256sum | xargs sha256sum --check
|
||||
|
||||
- name: Generate SHA summary
|
||||
id: generate_sha_file
|
||||
run: |
|
||||
echo "---" >> $GITHUB_STEP_SUMMARY
|
||||
echo "Update $(date -u +%F) $(date -u +%T) GMT/UTC" >> $GITHUB_STEP_SUMMARY
|
||||
echo "### SHAs of produced and carried forward binaries by this workflow" >> $GITHUB_STEP_SUMMARY
|
||||
echo " - $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_STEP_SUMMARY
|
||||
echo '```' >> $GITHUB_STEP_SUMMARY
|
||||
sha_output_file=${GITHUB_SHA}_${RANDOM}_shas.txt
|
||||
echo "sha_output_file=${sha_output_file}" >> $GITHUB_OUTPUT
|
||||
cat artifact-shas/*.sha256sum > ${sha_output_file}
|
||||
cat artifact-shas/*.sha256sum >> $GITHUB_STEP_SUMMARY
|
||||
echo '```' >> $GITHUB_STEP_SUMMARY
|
||||
# Get a random string of characters to represent the EOF delimiter
|
||||
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
|
||||
echo "sha_summary<<$EOF" >> $GITHUB_ENV
|
||||
cat $GITHUB_STEP_SUMMARY >> $GITHUB_ENV
|
||||
echo "$EOF" >> $GITHUB_ENV
|
||||
|
||||
- name: Determine release tag to upload assets to and draft type
|
||||
run: |
|
||||
if [[ "${{ inputs.newRelease }}" == "false" ]]; then
|
||||
echo "use_release_tag=${{ steps.get_previous_release.outputs.prev_release }}" >> $GITHUB_ENV
|
||||
echo "create_draft=false" >> $GITHUB_ENV
|
||||
else
|
||||
echo "use_release_tag=draft_release_${{ github.sha }}" >> $GITHUB_ENV
|
||||
echo "create_draft=true" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Add binaries to release
|
||||
id: create_release
|
||||
uses: softprops/action-gh-release@d4e8205d7e959a9107da6396278b2f1f07af0f9b
|
||||
with:
|
||||
workflow: build-linux.yml
|
||||
path: artifacts
|
||||
- name: Download workflow artifacts
|
||||
uses: dawidd6/action-download-artifact@v2.24.3
|
||||
with:
|
||||
workflow: build-linuxstatic.yml
|
||||
path: artifacts
|
||||
- name: Download workflow artifacts
|
||||
uses: dawidd6/action-download-artifact@v2.24.3
|
||||
with:
|
||||
workflow: build-macos.yml
|
||||
path: artifacts
|
||||
- name: Download workflow artifacts
|
||||
uses: dawidd6/action-download-artifact@v2.24.3
|
||||
with:
|
||||
workflow: build-windows.yml
|
||||
path: artifacts
|
||||
- run: ls -laR artifacts
|
||||
token: ${{ github.token }}
|
||||
draft: ${{ env.create_draft }}
|
||||
tag_name: ${{ env.use_release_tag }}
|
||||
files: |
|
||||
artifact-shas/*
|
||||
artifact-binaries/*
|
||||
body: "${{ env.sha_summary }}"
|
||||
generate_release_notes: true
|
||||
append_body: true
|
||||
|
||||
- name: Add release url to summary
|
||||
run: echo "Release created/updated at ${{ steps.create_release.outputs.url }}" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
- name: Print diff for future PR submission
|
||||
run: |
|
||||
yarn install
|
||||
yarn build
|
||||
yarn run updateExpected --input ${{ steps.generate_sha_file.outputs.sha_output_file }}
|
||||
git diff
|
||||
|
||||
40
lib/generate-expected-shas.ts
Normal file
40
lib/generate-expected-shas.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import yargs from 'yargs';
|
||||
import { readFileSync, writeFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { log } from './log';
|
||||
import { version } from '../package.json';
|
||||
|
||||
async function main() {
|
||||
const { argv } = yargs
|
||||
.option('input', { alias: 'i', default: 'shas.txt', type: 'string' })
|
||||
.version(version)
|
||||
.alias('v', 'version')
|
||||
.help()
|
||||
.alias('h', 'help');
|
||||
|
||||
const shaFileContent = readFileSync(argv.input).toString();
|
||||
const shaMap: { [id: string]: string } = {};
|
||||
for (const line of shaFileContent.split('\n')) {
|
||||
const lineParts = line.split(/\s+/);
|
||||
if (lineParts.length === 2) {
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
shaMap[lineParts[1]] = lineParts[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Sort map
|
||||
const sortedShaMap: { [id: string]: string } = {};
|
||||
for (const nodeVersion of Object.keys(shaMap).sort()) {
|
||||
sortedShaMap[nodeVersion] = shaMap[nodeVersion];
|
||||
}
|
||||
|
||||
writeFileSync(join(__dirname, '../lib/expected-shas.json'),
|
||||
`${JSON.stringify(sortedShaMap, null, 2)}\n`);
|
||||
// console.log(JSON.stringify(sortedShaMap, null, 2));
|
||||
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
if (!error.wasReported) log.error(error);
|
||||
process.exit(2);
|
||||
});
|
||||
11
lib/print-hashes.ts
Normal file
11
lib/print-hashes.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { EXPECTED_HASHES } from './expected';
|
||||
|
||||
/* eslint-disable no-console */
|
||||
|
||||
function main() {
|
||||
for (const nodeVersion of Object.keys(EXPECTED_HASHES).sort()) {
|
||||
console.log(`${nodeVersion} ${EXPECTED_HASHES[nodeVersion]}`);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
@ -51,7 +51,9 @@
|
||||
"prepare": "npm run build",
|
||||
"prepublishOnly": "npm run lint",
|
||||
"start": "node lib-es5/bin.js",
|
||||
"applyPatches": "node lib-es5/apply-patches.js"
|
||||
"applyPatches": "node lib-es5/apply-patches.js",
|
||||
"printHashes": "node lib-es5/print-hashes.js",
|
||||
"updateExpected": "node lib-es5/generate-expected-shas.js"
|
||||
},
|
||||
"prettier": {
|
||||
"singleQuote": true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user