Skip to content

Release - Create Branch #28

Release - Create Branch

Release - Create Branch #28

# Bump package version numbers and create a release branch
name: Release - Create Branch
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
branch:
description: "Branch or tag to create release from"
required: true
default: "main"
newVersion:
description: "New version to set"
required: true
jobs:
release:
name: Increment versions and create PR
runs-on: ubuntu-latest
steps:
# Check-out repo
- uses: actions/checkout@v3
with:
fetch-depth: 0
# Use a service account when checking out. This is to workaround the issue were GitHub
# actions, when using the default account, cannot trigger other actions. And we want this
# action to trigger the regular CI pipeline on the created branch.
# This service account is only for this PAT, pwd was created and thrown away
# If any update needed, create a new account, add access to the repo and generate a new PAT
token: ${{ secrets.SERVICE_ACCOUNT_PAT }}
# Setup bot information for creating pull request
# Here we use the id from the github actions bot: https://api.github.com/users/better-informatics%5Bbot%5D
- name: Setup bot git information
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
# Check out onto desired branch or tag to create release from
- name: Checkout tag/branch
run: git checkout ${{ github.event.inputs.branch }}
# Ensure node version is great enough
- name: Use Node.js v20.17.x
uses: actions/setup-node@v3
with:
node-version: "20.17.x"
# Increment versions
- name: Increment versions
run: node scripts/increment-version.js ${{ github.event.inputs.newVersion }}
# Update telemetry version
- name: Synchronize package version reported to telemetry
run: node scripts/sync-telemetry-package-version.js
# Retrieve version to tag and publish release with
- name: Retrieve version from package.json
id: version
run: |
clientVer=$(jq -r .version client/package.json)
echo clientversion: $clientVer
serverVer=$(jq -r .version server/package.json)
echo serverversion: $serverVer
if [ $clientVer != $serverVer ]; then (echo "client and server versions do not match"; exit 1;); fi
echo "newProjectVersion=$clientVer" >> $GITHUB_OUTPUT
# Update package-lock.json
- name: Install client dependencies
working-directory: ./client
run: npm install
- name: Install server dependencies
working-directory: ./server
run: npm install
# Commit changes
- name: Hop into new branch
run: git checkout -b release/${{ steps.version.outputs.newProjectVersion }}
- name: Commit changes
run: |
git add .
git commit -m "Increment version"
# Push changes
- name: Push branch
run: git push --set-upstream origin release/${{ steps.version.outputs.newProjectVersion }}
# Create a PR from the changes
- name: Create PR
run: |
curl \
-X POST \
-H 'Accept: application/vnd.github.v3+json' \
-H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
https://api.github.com/repos/Azure-Samples/communication-services-virtual-visits-js/pulls \
-d '{ "title":"${{ steps.version.outputs.newProjectVersion }} release branch", "head":"release/${{ steps.version.outputs.newProjectVersion }}", "base":"main", "body":"Release branch for ${{ steps.version.outputs.newProjectVersion }}. Created by the `Release - Create Branch` GitHub action. Please review." }'