I'm currently writing an example set of workflows for a generic NPM based application. I'm currently working on creating a release branch which branches of Dev. This can be called via workflow_dispatch or repository_dispatch. The expected input is simply one of "Major", "Minor" or "Patch".
name: Create Release
on:
workflow_dispatch:
inputs:
version_bump:
type: choice
description: "Update Major, Minor or Patch"
options:
- Major
- Minor
- Patch
default: Patch
repository_dispatch:
types: [create_release]
env:
...
jobs:
create-release-branch:
name: Create release Branch
runs-on: [self-hosted, k8s-app-deploy]
steps:
- name: Validate Repo Dispatch inputs
if: github.event_name == 'repository_dispatch'
run: |
case "${{ github.event.client_payload.version }}"
Major)
major)
echo "VERSION=major" >> $GITHUB_ENV
;;
Minor)
minor)
echo "VERSION=minor" >> $GITHUB_ENV
;;
Patch)
patch)
echo "VERSION=patch" >> $GITHUB_ENV
;;
*)
echo
echo "::error title={Invalid Inputs}::{The inputs for the Repository Dispatch were wrong, needs to be Major, Minor or Patch}"
exit 1
- name: Validate Workflow Dispatch input
if: github.event_name == 'workflow_dispatch'
run: echo VERSION=`echo ${{ inputs.version_bump }} | tr '[:upper:]' '[:lower:]'` >> $GITHUB_ENV
- name: Check out code
uses: actions/checkout@v3
with:
ref: "Develop"
- run: git remote update
- name: Set release verison
run: |
- run: git checkout -b release/$RELEASE_VERSION origin/Develop
The bit I'm stuck on is the step Set release version. To my knowledge, npm version can't create a new branch beforehand, nor would I want it to be there anyway, as I'd like to be able to create RC versions until we actually merge into main \ master and release the version.
My thought track is to
- Extract the current version from the
package.json, - Increment the correct number and set that as the
$RELEASE_VERSION, - Create Release branch with
release/$RELEASE_VERSION - Run
npm version $VERSION - Push & create PR from release branch to main
I'll then have other workflows pickup from there.
My question is, how would you set the $RELEASE_VERSION variable?