CD - Validate and Create New Release #33
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: Release | |
run-name: CD - Validate and Create New Release | |
permissions: | |
contents: write | |
id-token: write | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version to release: Syntax - (*.*.*)' | |
required: true | |
type: string | |
# Ensures that only one job group runs at a time to avoid resource waste | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
deploy-release: | |
name: Deploy Release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
registry-url: 'https://registry.npmjs.org' | |
- name: Install Dependencies | |
run: npm install | |
- name: Retrieve current package version | |
id: package-version | |
run: | | |
current_version=$(jq -r '.version' package.json) | |
echo "Current version: $current_version" | |
echo "::set-output name=current_version::$current_version" | |
- name: Validate New Version | |
id: validate-version | |
run: node .github/scripts/comparePackageVersions.mjs ${{ steps.package-version.outputs.current_version }} ${{ github.event.inputs.version }} | |
- name: Update package.json file | |
run: | | |
jq --arg newVersion "${{ github.event.inputs.version }}" '.version = $newVersion' package.json > tmp.json && mv tmp.json package.json | |
- name: Commit package.json file | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Action" | |
git add package.json | |
git commit -m "Update version to ${{ github.event.inputs.version }}" | |
- name: Push changes to repository | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git push --force-with-lease origin | |
- name: Publish to NPM | |
run: | | |
npm run build | |
npm publish --provenance --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Create Release | |
id: create-release | |
uses: octokit/[email protected] | |
with: | |
route: POST /repos/{owner}/{repo}/releases | |
owner: alderwhiteford | |
repo: components | |
tag_name: ${{ github.event.inputs.version }} | |
name: v${{ github.event.inputs.version }} | |
body: "Release v${{ github.event.inputs.version }}" | |
draft: true | |
prerelease: false | |
generate_release_notes: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |