Skip to content

CD - Validate and Create New Release #20

CD - Validate and Create New Release

CD - Validate and Create New Release #20

Workflow file for this run

name: Release
run-name: CD - Validate and Create New Release
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:
create-release:
name: Create New 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: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: Install Dependencies
run: npm ci
- 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: 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.PA_TOKEN }}
- 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 checkout -b release-v${{ github.event.inputs.version }}
git add package.json
git commit -m "Update version to ${{ github.event.inputs.version }}"
- name: Push changes to repository
env:
GITHUB_TOKEN: ${{ secrets.PA_TOKEN }}
run: |
git push --set-upstream origin release-v${{ github.event.inputs.version }}
- name: Create Pull Request
id: create-pull-request
uses: octokit/[email protected]
with:
route: POST /repos/{owner}/{repo}/pulls
owner: alderwhiteford
repo: components
title: "Update version to ${{ github.event.inputs.version }}"
head: release-v${{ github.event.inputs.version }}
base: main
env:
GITHUB_TOKEN: ${{ secrets.PA_TOKEN }}