QA-2320: App versioning golden path #1
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 | |
# - App Branch | |
# - App SHA | |
# - App Short SHA | |
# - PART | |
# | |
# This workflow computes the App Context and uploads the results as a dotenv file to artifacts. | |
# | |
name: Compute App Context | |
on: | |
pull_request: | |
branches: | |
- main | |
paths-ignore: [ '**.md' ] | |
types: [opened, synchronize, reopened] | |
push: | |
branches: | |
- main | |
paths-ignore: [ '**.md' ] | |
env: | |
DEFAULT_BUMP: patch | |
MAINLINE: main | |
jobs: | |
bumper-job: | |
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 }} | |
app_short_sha=${app_sha:0:7} | |
echo "app_sha=${app_sha}" >> $GITHUB_OUTPUT | |
echo "app_short_sha=${app_short_sha}" >> $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: build.gradle | |
VERSION_LINE_MATCH: "^\\s*version\\s*=\\s*'.*'" | |
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 }} | |
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 |