QA-2320: App versioning golden path #22
This file contains 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
# 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*'.*'" | |
jobs: | |
bumper-job: | |
if: "github.event.head_commit.committer.name != 'bumptagbot'" | |
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 }} | |
- 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 |