Prerelease #16
Workflow file for this run
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
name: Prerelease | |
on: | |
workflow_dispatch: | |
inputs: | |
description: | |
description: 'Release notes' | |
type: string | |
default: '' | |
required: false | |
version-update: | |
description: 'Version update' | |
required: true | |
default: 'no update' | |
type: choice | |
options: | |
- major | |
- minor | |
- patch | |
- no update | |
env: | |
NODE_VERSION: "18.20.3" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: false | |
permissions: | |
contents: write | |
jobs: | |
prerelease: | |
name: Create prerelease | |
runs-on: ubuntu-20.04 | |
outputs: | |
release_id: ${{ steps.update_release.outputs.result }} | |
steps: | |
- name: Checkout the repo | |
uses: actions/checkout@v4 | |
with: | |
ref: main | |
lfs: false | |
- name: Install NodeJS | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
registry-url: 'https://registry.npmjs.org' | |
- name: Install dependencies | |
run: cd krait-ui && npm ci | |
- name: Configure github user | |
run: | | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config user.name "github-actions[bot]" | |
- name: Update package version | |
if: github.event.inputs.version-update != 'no update' | |
run: | |
npm version $VERSION_UPDATE --no-git-tag-version | |
env: | |
VERSION_UPDATE: ${{ github.event.inputs.version-update }} | |
- name: Update the beta version | |
id: create_tag | |
run: | | |
cd krait-ui | |
TAG=$(npm version prerelease --preid=beta -m "[GHA] Update package version to %s") | |
cd ../ | |
git push | |
echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
git push --tags | |
- name: Set release tag | |
id: update_release | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const {TAG_NAME, USER, DESCRIPTION} = process.env | |
const releases = await github.rest.repos.listReleases({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag_name: "unreleased", | |
}) | |
const filtered = releases.data.filter(release => release.draft == true && release.tag_name === 'unreleased'); | |
let release; | |
if (filtered.length === 0) { | |
console.log("Creating a new untagged release") | |
release = await github.rest.repos.createRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag_name: "unreleased", | |
name: "Unreleased", | |
draft: true, | |
generate_release_notes: true, | |
}) | |
} else { | |
release = filtered[0]; | |
} | |
let releaseNotes = `${USER} released version ${TAG_NAME}.`; | |
if (DESCRIPTION) { | |
releaseNotes += `\n\n Release Notes:\n${DESCRIPTION}`; | |
} | |
github.rest.repos.updateRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
release_id: release.id, | |
name: TAG_NAME, | |
tag_name: TAG_NAME, | |
draft: false, | |
prerelease: true, | |
body: releaseNotes, | |
}); | |
return release.id | |
env: | |
TAG_NAME: ${{ steps.create_tag.outputs.tag }} | |
USER: ${{ github.event.sender.login }} | |
DESCRIPTION: ${{ github.event.inputs.description }} | |
build_ui: | |
name: Build UI Library | |
needs: [prerelease] | |
runs-on: ubuntu-20.04 | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout the repo | |
uses: actions/checkout@v4 | |
with: | |
ref: main | |
lfs: false | |
- name: Install NodeJS | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
registry-url: 'https://registry.npmjs.org' | |
- name: Retrieve the npm dependencies cache | |
uses: actions/cache@v4 | |
id: node-modules-cache | |
with: | |
path: node_modules | |
key: npm-dependencies-${{ runner.os }}-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
npm-dependencies-${{ hashFiles('package-lock.json') }} | |
npm-dependencies- | |
- name: Install npm dependencies | |
if: steps.node-modules-cache.outputs.cache-hit != 'true' | |
run: cd krait-ui && npm ci | |
- name: Build FE assets | |
run: cd krait-ui && npm run build | |
- name: Zip the distribution build | |
run: cd krait-ui && zip -9qry "distribution-package.zip" "./" -i "dist/*" "package.json" "package-lock.json" | |
- name: Upload an Asset in GitHub Release | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const {RELEASE_ID} = process.env | |
const fs = require('fs').promises; | |
await github.rest.repos.uploadReleaseAsset({ | |
name: 'README.md', | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
release_id: ${{ env.RELEASE_ID }}, | |
data: await fs.readFile('./krait-ui/distribution-package.zip') | |
}); | |
env: | |
RELEASE_ID: ${{ needs.prerelease.outputs.release_id }} | |
- name: Publish the NPM package | |
run: cd krait-ui && npm publish --access public --tag dev | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} |