Skip to content

Moved workflows to top level folder #1

Moved workflows to top level folder

Moved workflows to top level folder #1

##################################################################################
# About
##################################################################################
# Reuseable workflow to be called from content repos.
# Build and deploy app bundle for android
#
# Version : 1.0
#
##################################################################################
# Configuration
##################################################################################

Check failure on line 11 in .github/workflows/reusable-android-build.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/reusable-android-build.yml

Invalid workflow file

You have an error in your yaml syntax on line 11
env:
APP_ID: ${{vars.APP_ID}}
APP_NAME: ${{vars.APP_NAME}}
DEPLOYMENT_NAME: ${{vars.DEPLOYMENT_NAME}}
APP_CODE_BRANCH: ${{vars.APP_CODE_BRANCH}}
PARENT_DEPLOYMENT_REPO: ${{vars.PARENT_DEPLOYMENT_REPO}}
PARENT_DEPLOYMENT_NAME: ${{vars.PARENT_DEPLOYMENT_NAME}}
PARENT_DEPLOYMENT_BRANCH: ${{vars.PARENT_DEPLOYMENT_BRANCH}}
GOOGLE_SERVICES_JSON: ${{secrets.GOOGLE_SERVICES_JSON}}
SIGNING_KEY: ${{secrets.SIGNING_KEY}}
ALIAS: ${{secrets.ALIAS}}
KEY_STORE_PASSWORD: ${{secrets.KEY_STORE_PASSWORD}}
KEY_PASSWORD: ${{secrets.KEY_PASSWORD}}
##################################################################################
# Main Code
##################################################################################
name: Android Build
# Only keep one active build per ref (e.g. pr branch, push branch, triggering workflow ref)
concurrency:
group: android-build-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
workflow_call:
jobs:
build_action:
uses: ./.github/workflows/contentflows/reusable-app-build.yml
secrets: inherit
build_android:
runs-on: ubuntu-latest
needs: build_action
env:
GIT_SHA: ${{ needs.web_build.outputs.GIT_SHA }}
steps:
- name: Check out app code
uses: actions/checkout@v3
with:
repository: "IDEMSInternational/parenting-app-ui.git"
ref: ${{env.APP_CODE_BRANCH}}
lfs: true
- name: Checkout parent repo if needed
if: env.PARENT_DEPLOYMENT_REPO != ''
uses: actions/checkout@v3
with:
path: ".idems_app/deployments/${{env.PARENT_DEPLOYMENT_NAME}}"
repository: ${{env.PARENT_DEPLOYMENT_REPO}}
ref: ${{env.PARENT_DEPLOYMENT_BRANCH}}
- name: Checkout deployment
uses: actions/checkout@v3
with:
path: ".idems_app/deployments/${{env.DEPLOYMENT_NAME}}"
- name: Populate google-services.json
env:
GOOGLE_SERVICES_JSON: ${{ env.GOOGLE_SERVICES_JSON }}
run: echo $GOOGLE_SERVICES_JSON > android/app/google-services.json
#############################################################################
# Sync web files
# Setup node same way as web build to allow calling `npx cap sync` command
#############################################################################
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
- uses: actions/cache/restore@v3
id: cache
with:
path: ./.yarn/cache
key: ${{ runner.os }}-node-modules-yarn-v1-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-modules-yarn-v1-
- name: Install node modules
run: yarn install --immutable
- name: Set deployment
run: yarn workflow deployment set $DEPLOYMENT_NAME
- name: Populate android assets
run: yarn workflow populate_android_assets
- name: Update config names in android files
run: |
sed -i -e "s/international.idems.plh_teens/$APP_ID/g" -e "s/PLH Teens/$APP_NAME/g" ./capacitor.config.ts ./android/app/src/main/assets/capacitor.config.json ./android/app/src/main/res/values/strings.xml ./android/app/src/main/AndroidManifest.xml ./android/app/src/main/java/international/idems/plh_teens/MainActivity.java ./android/app/build.gradle
- name: Add version number to build.gradle
run: |
# Define the path to the file
FILE_PATH="./.idems_app/deployments/${{env.DEPLOYMENT_NAME}}/config.ts"
# Extract the version number
VERSION=$(grep 'content_tag_latest:' $FILE_PATH | sed 's/content_tag_latest: *"\(.*\)",/\1/')
echo "Extracted Version: $VERSION"
# Split the version into major, minor, and patch components
IFS='.' read -ra VERSION_PARTS <<< "$VERSION"
if [[ ${#VERSION_PARTS[@]} -ne 3 ]]; then
echo "Error: Version format is not as expected."
exit 1
fi
# Convert minor and patch segment to 3-digit representation
MINOR=$(printf "%03d" "${VERSION_PARTS[1]}")
PATCH=$(printf "%03d" "${VERSION_PARTS[2]}")
# Construct the new version
VERSION_CODE="${VERSION_PARTS[0]}${MINOR}${PATCH}"
echo "Version Code: $VERSION_CODE"
echo "Version: $VERSION"
# This will need to change currently looking for specific version and not place holder
sed -i -e "s/16023/$VERSION_CODE/g" -e "s/0.16.23/$VERSION/g" ./android/app/build.gradle
- name: Download Build Artifact
uses: actions/download-artifact@v3
with:
name: needs.build.outputs.artifactname
- name: Extract Build folder
run: |
mkdir www
tar -xf artifact.tar --directory www
- name: Sync Android Files
run: npx cap sync
#############################################################################
# Android Build
#############################################################################
# Java version mapping: https://stackoverflow.com/a/47457251/5693245
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "17"
java-package: jdk
cache: "gradle"
- name: Setup Android SDK
uses: android-actions/setup-android@v2
# Debug APK
- name: Build Android Debug APK
working-directory: android
run: ./gradlew :app:assembleDebug
- name: Upload debug apk
uses: actions/upload-artifact@v3
with:
name: debug_apk
path: android/app/build/outputs/apk/debug/app-debug.apk
# Signed Release Bundle
- name: Build Android Release Bundle
working-directory: android
run: ./gradlew :app:bundleRelease
- name: Sign Android Release
id: sign_aab
uses: r0adkll/sign-android-release@v1
with:
releaseDirectory: ./android/app/build/outputs/bundle/release
signingKeyBase64: ${{ env.SIGNING_KEY }}
alias: ${{ env.ALIAS }}
keyStorePassword: ${{ env.KEY_STORE_PASSWORD }}
keyPassword: ${{ env.KEY_PASSWORD }}
- name: Upload release bundle
uses: actions/upload-artifact@v3
with:
name: release_bundle
path: ${{steps.sign_aab.outputs.signedReleaseFile}}