-
Notifications
You must be signed in to change notification settings - Fork 0
213 lines (180 loc) · 11.6 KB
/
build-and-deploy-to-alpha.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: "ALPHA stage - Build & deploy to ALPHA"
on:
workflow_dispatch:
env:
# PACKAGE_APP_NAME -> no empty spaces or special character
# APP_VERSION_NAME_POSTFIX -> must start with hyphen
APP_NAME: Hubis App
PACKAGE_APP_NAME: hubisapp
PACKAGE_ROOT_NAME: com.ocfulfillment
APP_VERSION_NAME_POSTFIX: -alpha
BRANCH_STARTS_WITH: refs/heads/release
PATH_TO_VERSION_JSON: ./app
PATH_TO_APK_RELEASE: ./app/build/outputs/apk_from_bundle/release
PATH_TO_AAB_RELEASE: ./app/build/outputs/bundle/release
PATH_TO_MAPPING_FILE: ./app/build/outputs/mapping/release
jobs:
build:
runs-on: buildjet-8vcpu-ubuntu-2204
permissions:
id-token: write
contents: write
packages: read
steps:
##############################################################################################
# SETUP
##############################################################################################
- name: Check current branch is a release branch and remember build time
id: startUpCheck
if: ${{ startsWith(github.ref, env.BRANCH_STARTS_WITH) }}
run: |
echo SUCCESS: The branch ${{ github.ref }} is a release branch.
echo "BUILD_DATE=$(TZ=Europe/Berlin date +%Y-%m-%d_%H-%M-%S)" >> $GITHUB_ENV
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
- name: Cancel build if current branch is no release branch
if: ${{ !startsWith(github.ref, env.BRANCH_STARTS_WITH) }}
run: |
echo ERROR: The branch ${{ github.ref }} is no release branch.
exit 1
- name: Sourcecode checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'adopt'
##############################################################################################
# VERSION-JSON HANDLING
##############################################################################################
- name: Increment 'versionCode' and 'releaseAutoIncrement' JSON value
run: |
cat $PATH_TO_VERSION_JSON/version.json | jq '.versionCode = .versionCode + 1' | jq '.releaseAutoIncrement = .releaseAutoIncrement + 1' | tee $PATH_TO_VERSION_JSON/version.json
git config user.name "GitHub Actions Bot"
git config user.email "<none>"
git add $PATH_TO_VERSION_JSON/version.json
git commit -m "Increment 'versionCode' and 'releaseAutoIncrement' value in 'version.json'."
git push
- name: Read version from JSON
id: version
uses: juliangruber/read-file-action@02bbba9876a8f870efd4ad64e3b9088d3fb94d4b
with:
path: ${{ env.PATH_TO_VERSION_JSON }}/version.json
- name: Save app-version-name to environment parameters
run: |
echo "App-version-name is ${{ fromJson(steps.version.outputs.content).major }}.${{ fromJson(steps.version.outputs.content).minor }}.${{ fromJson(steps.version.outputs.content).patch }}-${{ fromJson(steps.version.outputs.content).releaseAutoIncrement }}"
echo "APP_VERSION_NAME_DOTS=${{ fromJson(steps.version.outputs.content).major }}.${{ fromJson(steps.version.outputs.content).minor }}.${{ fromJson(steps.version.outputs.content).patch }}-${{ fromJson(steps.version.outputs.content).releaseAutoIncrement }}" >> $GITHUB_ENV
echo "APP_VERSION_NAME_DASH=${{ fromJson(steps.version.outputs.content).major }}-${{ fromJson(steps.version.outputs.content).minor }}-${{ fromJson(steps.version.outputs.content).patch }}-${{ fromJson(steps.version.outputs.content).releaseAutoIncrement }}" >> $GITHUB_ENV
##############################################################################################
# BUILDING
##############################################################################################
- name: Build Android Universal APK (*.apk)
id: buildAPKRelease
run: |
bash ./gradlew packageReleaseUniversalApk --stacktrace
#env:
#BRANCH_TYPE: ${{ env.BRANCH_TYPE }}
#STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
#KEY_PASSWORD_RELEASE: ${{ secrets.KEY_PASSWORD_RELEASE }}
- name: Build Android App Bundle (*.aab)
run: |
bash ./gradlew bundleRelease --stacktrace
#env:
#BRANCH_TYPE: ${{ env.BRANCH_TYPE }}
#STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
#KEY_PASSWORD_RELEASE: ${{ secrets.KEY_PASSWORD_RELEASE }}
##############################################################################################
# GIT TAG HANDLING
##############################################################################################
- name: Create GitHub release ${{ env.PACKAGE_APP_NAME }}_${{ env.APP_VERSION_NAME_DOTS }}
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
target_commitish: ${{ env.BRANCH_NAME }}
name: ${{ env.PACKAGE_APP_NAME }}_${{ env.APP_VERSION_NAME_DOTS }} [ALPHA]
tag_name: ${{ env.PACKAGE_APP_NAME }}_${{ env.APP_VERSION_NAME_DOTS }}
draft: false
prerelease: true
##############################################################################################
# RENAME FILES
##############################################################################################
- name: Rename APK & AAB files
run: |
mv ${{ env.PATH_TO_APK_RELEASE }}/*.apk ${{ env.PATH_TO_APK_RELEASE }}/${{ env.PACKAGE_APP_NAME }}_${{ env.APP_VERSION_NAME_DASH }}_release.apk
mv ${{ env.PATH_TO_AAB_RELEASE }}/*.aab ${{ env.PATH_TO_AAB_RELEASE }}/${{ env.PACKAGE_APP_NAME }}_${{ env.APP_VERSION_NAME_DASH }}_release.aab
##############################################################################################
# AUTHENTICATE TO GOOGLE CLOUD
##############################################################################################
- id: google-auth
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
create_credentials_file: 'true'
workload_identity_provider: projects/716153011929/locations/global/workloadIdentityPools/github-access-pool/providers/gh-provider
service_account: google-artifact-access@ocff-infra-app-artifacts-prd.iam.gserviceaccount.com
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
skip_install: true
##############################################################################################
# UPLOAD FILES
##############################################################################################
- name: Upload Android APK & AAB to ALPHA stage (Google Cloud Storage)
env:
VERSION_NAME: ${{ env.APP_VERSION_NAME_DOTS }}
VERSION_CODE: ${{ fromJson(steps.version.outputs.content).versionCode }}
METADATA_FILE: metadata.json
run: |
# writeMetadata.js file needs BUILD_DATE, VERSION_NAME, VERSION_CODE and METADATA_FILE parameters
node ./.github/workflows/scripts/writeMetadata.js
GS_PATH=gs://ocff-deployment-mobileapps/${{ env.PACKAGE_APP_NAME }}/android/releases/${{ env.APP_VERSION_NAME_DASH }}${{ env.APP_VERSION_NAME_POSTFIX }}/
gsutil cp -n ${{ env.PATH_TO_APK_RELEASE }}/*.apk $GS_PATH
gsutil cp -n ${{ env.PATH_TO_AAB_RELEASE }}/*.aab $GS_PATH
gsutil cp $METADATA_FILE $GS_PATH
gsutil cp $METADATA_FILE $GS_PATH
- name: Upload Application to Google Artifact Registry
run: bash ./gradlew publishDanielPublicationToMavenRepository --stacktrace
# TODO - MOVE TO TOP!
- name: Upload Android App Bundle (*.aab) to Google Play (ALPHA track)
uses: r0adkll/upload-google-play@8c2ebfdb6e1b439d3a31d35772b3f0f489d688c9
with:
serviceAccountJsonPlainText: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_JSON }}
packageName: ${{ env.PACKAGE_ROOT_NAME }}
releaseFiles: ${{ env.PATH_TO_AAB_RELEASE }}/${{ env.PACKAGE_APP_NAME }}_${{ env.APP_VERSION_NAME_DASH }}_release.aab
releaseName: ${{ env.APP_NAME }} (${{ env.APP_VERSION_NAME_DOTS }})
track: alpha
status: completed
mappingFile: ${{ env.PATH_TO_MAPPING_FILE }}/mapping.txt
##############################################################################################
# SLACK NOTIFICATIONS
##############################################################################################
# Send optional Slack notification (failure)
- name: Send optional Slack notification (failure)
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_ANDROID_ALPHA_ANIMALS }}
SLACK_USERNAME: AndroidDevelopBranch
MSG_MINIMAL: actions url,commit
SLACK_MESSAGE: "New *${{ env.APP_NAME }}* Android application with version *${{ env.APP_VERSION_NAME_DOTS }}* is available on ALPHA stage.\n\n
You want to test it, we know! You find it here:\n
- <https://play.google.com/store/apps/details?id=com.ocfulfillment.inventoryapp|Google Play Store>\n
- <https://console.cloud.google.com/storage/browser/ocff-deployment-mobileapps/${{ env.PACKAGE_APP_NAME }}/android/releases/${{ env.APP_VERSION_NAME_DASH }}${{ env.APP_VERSION_NAME_POSTFIX }}|Google Cloud Storage>\n
- <https://console.cloud.google.com/artifacts/maven/ocff-infra-app-artifacts-prd/europe-west1/android-registry/${{ env.PACKAGE_ROOT_NAME }}:${{ env.PACKAGE_APP_NAME }}/${{ env.APP_VERSION_NAME_DOTS }}${{ env.APP_VERSION_NAME_POSTFIX }}?project=ocff-infra-app-artifacts-prd|Google Artifact Registry>\n\n
:yellow_heart::yellow_heart::yellow_heart::yellow_heart::yellow_heart::yellow_heart::yellow_heart::yellow_heart::yellow_heart::sunrise_over_dom_zu_kölle::yellow_heart::yellow_heart:"
SLACK_COLOR: "#B00020"
# Send optional Slack notification (success)
- name: Send optional Slack notification (success)
if: ${{ success() }}
uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_ANDROID_ALPHA_ANIMALS }}
SLACK_USERNAME: AndroidDevelopBranch
MSG_MINIMAL: actions url,commit
SLACK_MESSAGE: "New *${{ env.APP_NAME }}* Android application with version *${{ env.APP_VERSION_NAME_DOTS }}* is available on ALPHA stage.\n\n
You want to test it, we know! You find it here:\n
- <https://play.google.com/store/apps/details?id=com.ocfulfillment.inventoryapp|Google Play Store>\n
- <https://console.cloud.google.com/storage/browser/ocff-deployment-mobileapps/${{ env.PACKAGE_APP_NAME }}/android/releases/${{ env.APP_VERSION_NAME_DASH }}${{ env.APP_VERSION_NAME_POSTFIX }}|Google Cloud Storage>\n
- <https://console.cloud.google.com/artifacts/maven/ocff-infra-app-artifacts-prd/europe-west1/android-registry/${{ env.PACKAGE_ROOT_NAME }}:${{ env.PACKAGE_APP_NAME }}/${{ env.APP_VERSION_NAME_DOTS }}${{ env.APP_VERSION_NAME_POSTFIX }}?project=ocff-infra-app-artifacts-prd|Google Artifact Registry>\n\n
:yellow_heart::yellow_heart::yellow_heart::yellow_heart::yellow_heart::yellow_heart::yellow_heart::yellow_heart::yellow_heart::sunrise_over_dom_zu_kölle::yellow_heart::yellow_heart:"
SLACK_COLOR: "#228F2C"