Skip to content

Version Bump

Version Bump #97

Workflow file for this run

# From https://github.com/backstage/demo/blob/master/.github/workflows/version-bump.yml
# Create a pull request if the backstage-cli has an updated version
name: 'Version Bump'
on:
workflow_dispatch:
# Run at midnight every Monday
schedule:
- cron: '0 0 * * 1'
env:
HUSKY: 0
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
version-bump:
runs-on: ubuntu-latest
steps:
- name: 'Checkout backstage'
uses: actions/checkout@v4
with:
fetch-depth: 0
# Beginning of yarn setup
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18.x
registry-url: https://registry.npmjs.org/ # Needed for auth
- name: cache all node_modules
id: cache-modules
uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
- name: find location of global yarn cache
id: yarn-cache
if: steps.cache-modules.outputs.cache-hit != 'true'
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- name: cache global yarn cache
uses: actions/cache@v4
if: steps.cache-modules.outputs.cache-hit != 'true'
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
run: yarn install --frozen-lockfile
# End of yarn setup
- name: 'Set release name'
id: set_release_name
run: node ./.github/scripts/set-release-name.js
- name: 'Configure git'
# From https://github.com/orgs/community/discussions/26560#discussioncomment-3531273
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: 'Does branch exist'
id: branch_exists
run: |
BRANCH=$(git branch -r --list origin/topic/v${{ steps.set_release_name.outputs.release_version }})
echo "Existing branch is: $BRANCH"
if [ ! -z "$BRANCH" ]; then
echo "Branch exists"
echo "BRANCH_EXISTS=1" >> $GITHUB_OUTPUT
else
echo "branch does NOT exist"
echo "BRANCH_EXISTS=0" >> $GITHUB_OUTPUT
fi
- name: 'Create branch'
id: branch_created
if: ${{ steps.branch_exists.outputs.BRANCH_EXISTS == 0 }}
run: |
git checkout -b topic/v${{ steps.set_release_name.outputs.release_version }}
echo "CREATED_BRANCH=1" >> $GITHUB_OUTPUT
- name: 'Run backstage-cli versions command'
if: ${{ steps.branch_created.outputs.CREATED_BRANCH == 1 }}
run: yarn backstage-cli versions:bump --release 'main'
- name: 'Check for changes'
if: ${{ steps.branch_created.outputs.CREATED_BRANCH == 1 }}
id: check_for_changes
run: |
CHANGES=$(git status --porcelain)
if [ -z "$CHANGES" ]; then
echo "No changes"
echo "HAS_CHANGES=0" >> $GITHUB_OUTPUT
else
echo "Has changes"
echo "HAS_CHANGES=1" >> $GITHUB_OUTPUT
fi
- name: 'Commit changes'
if: ${{ steps.check_for_changes.outputs.HAS_CHANGES == 1 }}
run: |
git status
git add -A -- :!.npmrc
git commit -m "v${{ steps.set_release_name.outputs.release_version }} version bump"
git push origin topic/v${{ steps.set_release_name.outputs.release_version }}
- name: 'Create Pull Request'
if: ${{ steps.check_for_changes.outputs.HAS_CHANGES == 1 }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.pulls.create({
title: 'v${{ steps.set_release_name.outputs.release_version }} version bump',
owner: context.repo.owner,
repo: context.repo.repo,
head: 'topic/v${{ steps.set_release_name.outputs.release_version }}',
base: 'main',
body: [
'Backstage release v${{ steps.set_release_name.outputs.release_version }} has been published, this Pull Request contains the changes to upgrade to this new release',
' ',
'Please review the changelog before approving, there may be manual changes needed to enable new features:',
' ',
'- Changelog: [v${{ steps.set_release_name.outputs.release_version }}](https://github.com/backstage/backstage/blob/master/docs/releases/v${{ steps.set_release_name.outputs.release_version }}-changelog.md)',
'- Upgrade Helper: [From ${{ steps.set_release_name.outputs.current_version }} to ${{ steps.set_release_name.outputs.release_version }}](https://backstage.github.io/upgrade-helper/?from=${{ steps.set_release_name.outputs.current_version }}&to=${{ steps.set_release_name.outputs.release_version }})',
' ',
'Created by [Version Bump ${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})',
' '
].join('\n')
});