Skip to content

QA-2320: App versioning golden path #18

QA-2320: App versioning golden path

QA-2320: App versioning golden path #18

# App Context Definition:
#
# The App Context includes the following information derived from GitHub Context:
#
# - App Version:
# - Version tag recorded in Git / version file when code is integrated into mainline.
# - App Branch:
# - Name of the branch that runs this workflow.
# - App SHA:
# - Git hash recorded in history.
# - For PRs: This is the commit hash of the PR changes when the PR is opened, updated with merge commit, or updated with rebase.
# - For Push: This is the commit hash that results from merging the PR changes into the base (mainline) branch.
# - App Short SHA:
# - First 7 characters of App SHA.
# - PART:
# - The part of the version which was bumped.
#
# This workflow computes the App Context and uploads the results as a dotenv file
name: Compute App Context
on:
pull_request:
branches:
- main
paths-ignore: [ '**.md' ]
# By default, a workflow only runs when a pull_request event's activity type is opened, synchronize, or reopened.
# types: [opened, synchronize, reopened]
push:
branches:
- main
paths-ignore: [ '**.md' ]
env:
DEFAULT_BUMP: patch
MAINLINE: main
VERSION_FILE_PATH: build.gradle
VERSION_LINE_MATCH: "^\\s*version\\s*=\\s*'.*'"
VERSION_FILE_BUMP_COMMIT_MSG: '^bump\s+([vV]?)([0-9]+)\.([0-9]+)\.([0-9]+)$'
jobs:
ignore-version-file-bump:
runs-on: ubuntu-latest
outputs:
match: ${{ steps.version-file-bump.outputs.match }}
V: ${{ steps.version-file-bump.outputs.group1 }}
major: ${{ steps.version-file-bump.outputs.group2 }}
minor: ${{ steps.version-file-bump.outputs.group3 }}
patch: ${{ steps.version-file-bump.outputs.group4 }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- id: last-commit
run: |
LAST_COMMIT_MSG=$(git log -1 --pretty=format:%s)
echo "$LAST_COMMIT_MSG"
echo "msg=$LAST_COMMIT_MSG" >> $GITHUB_OUTPUT
- uses: actions-ecosystem/action-regex-match@v2
id: version-file-bump
with:
text: ${{ steps.last-commit.outputs.msg }}
regex: ${{ env.VERSION_FILE_BUMP_COMMIT_MSG }}
- run: |
echo "match=${{ steps.version-file-bump.outputs.match }}"
echo "V=${{ steps.version-file-bump.outputs.group1 }}"
echo "major=${{ steps.version-file-bump.outputs.group2 }}"
echo "minor=${{ steps.version-file-bump.outputs.group3 }}"
echo "patch=${{ steps.version-file-bump.outputs.group4 }}"
bumper-job:
needs: [ ignore-version-file-bump ]
if: "!startsWith(github.event.head_commit.message, 'bump ')"
runs-on: ubuntu-latest
concurrency:
group: ${{ github.repository_owner }}-${{ github.event.repository.name }}-${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || 'main' }}-bumper
cancel-in-progress: false
outputs:
# new_tag - The value of the newly created tag.
# tag - The value of the latest tag after running this action.
# part - The part of version which was bumped.
new_tag: ${{ steps.bumper.outputs.new_tag }}
tag: ${{ steps.bumper.outputs.tag }}
part: ${{ steps.bumper.outputs.part }}
app_branch: ${{ steps.ghctx.outputs.app_branch }}
app_sha: ${{ steps.ghctx.outputs.app_sha }}
app_short_sha: ${{ steps.ghctx.outputs.app_short_sha }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
token: ${{ secrets.BROADBOT_TOKEN }}
- id: ghctx
name: Useful GitHub Context
run: |
echo "Action Type: ${{ github.event.action }}"
echo "app_branch=${{ github.event_name == 'pull_request' && github.head_ref || env.MAINLINE }}" >> $GITHUB_OUTPUT
app_sha=${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
echo "app_sha=${app_sha}" >> $GITHUB_OUTPUT
echo "app_short_sha=${app_sha:0:7}" >> $GITHUB_OUTPUT
- id: bumper
# https://github.com/DataBiosphere/github-actions/tree/master/actions/bumper
uses: databiosphere/github-actions/actions/bumper@bumper-0.4.0
env:
GITHUB_TOKEN: ${{ secrets.BROADBOT_TOKEN }}
HOTFIX_BRANCHES: hotfix.*
DEFAULT_BUMP: ${{ env.DEFAULT_BUMP }}
DRY_RUN: ${{ github.event_name == 'pull_request' }}
RELEASE_BRANCHES: ${{ env.MAINLINE }}
VERSION_FILE_PATH: ${{ env.VERSION_FILE_PATH }}
VERSION_LINE_MATCH: ${{ env.VERSION_LINE_MATCH }}
VERSION_SUFFIX: SNAPSHOT
upload-app-context-dotenv:
runs-on: ubuntu-latest
needs: [ bumper-job ]
steps:
- name: Assemble App Context DOTENV
id: assemble-app-context-dotenv
run: |
# App Context related info is stored in .env file
short_sha=${{ needs.bumper-job.outputs.app_short_sha }}
dotenv="${short_sha}.env"
cat <<EOF > $dotenv
APP_VERSION=${{ needs.bumper-job.outputs.new_tag }}
APP_BRANCH=${{ needs.bumper-job.outputs.app_branch }}
APP_SHA=${{ needs.bumper-job.outputs.app_sha }}
APP_SHORT_SHA=${short_sha}
PART=${{ env.DEFAULT_BUMP }}
VERSION_FILE_PATH=${{ env.VERSION_FILE_PATH }}
VERSION_LINE_MATCH=${{ env.VERSION_LINE_MATCH }}
EOF
cat $dotenv
echo "dotenv_path=$dotenv" >> $GITHUB_OUTPUT
- name: Upload App Context DOTENV
uses: actions/upload-artifact@v4
with:
name: ${{ needs.bumper-job.outputs.app_sha }}
path: ${{ steps.assemble-app-context-dotenv.outputs.dotenv_path }}
retention-days: 1