ALPHA stage - Build & deploy to ALPHA #82
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
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" |