-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (134 loc) · 5.74 KB
/
compute-app-context.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# 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