-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2161 from IDEMSInternational/actions
Added actions to be called by content repositories
- Loading branch information
Showing
6 changed files
with
677 additions
and
0 deletions.
There are no files selected for viewing
190 changes: 190 additions & 0 deletions
190
.github/workflows/contentflows/reusable-android-build.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
################################################################################## | ||
# About | ||
################################################################################## | ||
# Reuseable workflow to be called from content repos. | ||
# Build and deploy app bundle for android | ||
# | ||
# Version : 1.0 | ||
# | ||
################################################################################## | ||
# Configuration | ||
################################################################################## | ||
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}} | ||
|
47 changes: 47 additions & 0 deletions
47
.github/workflows/contentflows/reusable-android-release.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
################################################################################## | ||
# About | ||
################################################################################## | ||
# Reuseable workflow to be called from content repos. | ||
# Creates a internal release in play console | ||
# | ||
# Version : 1.0 | ||
# | ||
################################################################################## | ||
# Configuration | ||
################################################################################## | ||
env: | ||
APP_ID: ${{vars.APP_ID}} | ||
GOOGLE_PLAY_SERVICE_ACCOUNT_JSON: ${{secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON}} | ||
|
||
################################################################################## | ||
# Main Code | ||
################################################################################## | ||
name: Android - Release to Google Play | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
build: | ||
uses: ./.github/workflows/contentflows/reusable-android-build.yml | ||
secrets: inherit | ||
|
||
release: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Download Build Artifact | ||
id: download | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: release_bundle | ||
path: ./ | ||
|
||
- name: Upload to Google play | ||
uses: r0adkll/upload-google-play@v1.1.2 | ||
with: | ||
serviceAccountJsonPlainText: ${{ env.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON}} | ||
packageName: ${{env.APP_ID}} | ||
releaseFiles: ${{steps.download.outputs.download-path}}/app-release.aab | ||
track: internal |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
################################################################################## | ||
# About | ||
################################################################################## | ||
# Reuseable workflow to be called from content repos. | ||
# Allows for parent repo. | ||
# Must specify all below secrets and variables - see documentation for details | ||
# | ||
# Version : 1.0 | ||
# | ||
################################################################################## | ||
# Configuration | ||
################################################################################## | ||
env: | ||
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}} | ||
DEPLOYMENT_PRIVATE_KEY: ${{secrets.DEPLOYMENT_PRIVATE_KEY}} | ||
FIREBASE_CONFIG: ${{secrets.FIREBASE_CONFIG}} | ||
|
||
################################################################################## | ||
# Main Code | ||
################################################################################## | ||
name: Build App | ||
|
||
# Only keep one active build per ref (e.g. pr branch, push branch, triggering workflow ref) | ||
concurrency: | ||
group: app-build-${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
build-flags: | ||
description: Additional flags to pass to build command (e.g. base-href) | ||
type: string | ||
default: "" | ||
branch: | ||
description: Name of branch to build (defaults to event trigger sha) | ||
type: string | ||
default: "" | ||
|
||
outputs: | ||
artifactname: | ||
description: artifact to be given version number for readable reference | ||
default: ${{ jobs.build.outputs.artifactname }} | ||
GIT_SHA: | ||
description: "Git SHA of build head" | ||
value: ${{ jobs.build.outputs.GIT_SHA }} | ||
|
||
jobs: | ||
build: | ||
outputs: | ||
artifactname: ${{ steps.populate.outputs.artifactname }} | ||
GIT_SHA: ${{ steps.populate.outputs.GIT_SHA }} | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out app code | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: "IDEMSInternational/parenting-app-ui.git" | ||
ref: ${{env.APP_CODE_BRANCH}} | ||
|
||
- 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: | ||
ref: ${{inputs.branch}} | ||
path: ".idems_app/deployments/${{env.DEPLOYMENT_NAME}}" | ||
|
||
- name: Update artifact name to be version number | ||
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" | ||
echo "artifactname=$VERSION" >> $GITHUB_OUTPUT | ||
- name: Populate Encryption key | ||
if: env.DEPLOYMENT_PRIVATE_KEY != '' | ||
run: echo "${{env.DEPLOYMENT_PRIVATE_KEY}}" > ./.idems_app/deployments/${{env.DEPLOYMENT_NAME}}/encrypted/private.key | ||
|
||
- name: Populate Firebase Config | ||
if: env.FIREBASE_CONFIG != '' | ||
run: echo 'export const firebaseConfig = ${{env.FIREBASE_CONFIG}}' > src/environments/firebaseConfig.ts | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
|
||
- name: Cache node modules | ||
uses: actions/cache@v3 | ||
with: | ||
path: ./.yarn/cache | ||
# If cachebusting required (e.g. breaking yarn changes on update) change `v1` to another number | ||
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 | ||
|
||
- name: Set deployment | ||
run: yarn workflow deployment set $DEPLOYMENT_NAME | ||
|
||
- name: Build | ||
run: yarn build ${{inputs.build-flags}} | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v1.0.8 | ||
with: | ||
path: "www/" | ||
name: ${{outputs.artifactname}} | ||
|
Oops, something went wrong.