Bump App Version #6
This file contains hidden or 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: Bump App Version | |
permissions: | |
contents: write | |
on: | |
workflow_dispatch: | |
inputs: | |
app_version: | |
description: 'New app version (Major-Minor-Patch) such as: 1.7.1' | |
default: '' | |
required: false | |
type: string | |
jobs: | |
build: | |
name: Checkout | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 18.x | |
cache: yarn | |
cache-dependency-path: '**/yarn.lock' | |
- name: Ensure that we are running on `main` | |
if: github.ref != 'refs/heads/main' | |
run: | | |
echo "❌ This workflow can only run on the main branch! You are on: ${GITHUB_REF#refs/heads/}" | |
exit 1 | |
- name: Validate supplied app version format | |
if: ${{ github.event.inputs.app_version != '' }} | |
run: | | |
NEW_APP_VERSION="${{ github.event.inputs.app_version }}" | |
if [[ ! "${NEW_APP_VERSION}" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then | |
echo "NEW_APP_VERSION version must be specified in Major.Minor.Patch format" | |
exit 1 | |
fi | |
- name: Determine new app version | |
id: set-app-version | |
working-directory: packages/clippy | |
run: | | |
CURRENT_APP_VERSION=$(jq -r '.version' versions.json) | |
echo "CURRENT APP VERSION: ${CURRENT_APP_VERSION}" | |
if [[ "${{ github.event.inputs.app_version }}" != "" ]]; then | |
NEW_APP_VERSION="${{ github.event.inputs.app_version }}" | |
else | |
IFS='.' read -r major minor patch <<<"${CURRENT_APP_VERSION}" | |
NEW_APP_VERSION="${major}.${minor}.$((patch + 1))" | |
fi | |
echo "NEW APP VERSION = ${NEW_APP_VERSION}" | |
echo "new_app_version=${NEW_APP_VERSION}" >> "$GITHUB_OUTPUT" | |
- name: Update versions.json with new app version | |
working-directory: packages/clippy | |
run: | | |
if [[ -z "${{ steps.set-app-version.outputs.new_app_version }}" ]]; then | |
echo "Failed to determine new app version" | |
exit 1 | |
fi | |
jq --arg version "${{ steps.set-app-version.outputs.new_app_version }}" '.version = $version' versions.json > versions.temp.json | |
mv versions.temp.json versions.json | |
- name: Commit new app version to main | |
working-directory: packages/clippy | |
run: | | |
git config user.name "github-actions" | |
git config user.email "github-actions@github.com" | |
git add versions.json | |
git commit -m "chore: update app version to ${{ steps.set-app-version.outputs.new_app_version }}" | |
git pull --rebase origin main | |
git push |