From ce2d76293da45b1c90e13fe0bac9c7407254fc18 Mon Sep 17 00:00:00 2001 From: Chris Marsh Date: Mon, 11 Dec 2023 11:41:18 +0000 Subject: [PATCH] Added actions to be called by content repositories --- .../contentflows/reusable-android-build.yml | 190 ++++++++++++++++++ .../contentflows/reusable-android-release.yml | 47 +++++ .../contentflows/reusable-app-build.yml | 127 ++++++++++++ .../contentflows/reusable-content-sync.yml | 99 +++++++++ .../reusable-deploy-pr-preview.yml | 95 +++++++++ .../reusable-deploy-web-preview.yml | 119 +++++++++++ 6 files changed, 677 insertions(+) create mode 100644 .github/workflows/contentflows/reusable-android-build.yml create mode 100644 .github/workflows/contentflows/reusable-android-release.yml create mode 100644 .github/workflows/contentflows/reusable-app-build.yml create mode 100644 .github/workflows/contentflows/reusable-content-sync.yml create mode 100644 .github/workflows/contentflows/reusable-deploy-pr-preview.yml create mode 100644 .github/workflows/contentflows/reusable-deploy-web-preview.yml diff --git a/.github/workflows/contentflows/reusable-android-build.yml b/.github/workflows/contentflows/reusable-android-build.yml new file mode 100644 index 0000000000..a08c83ba11 --- /dev/null +++ b/.github/workflows/contentflows/reusable-android-build.yml @@ -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}} + \ No newline at end of file diff --git a/.github/workflows/contentflows/reusable-android-release.yml b/.github/workflows/contentflows/reusable-android-release.yml new file mode 100644 index 0000000000..59be2beba3 --- /dev/null +++ b/.github/workflows/contentflows/reusable-android-release.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/contentflows/reusable-app-build.yml b/.github/workflows/contentflows/reusable-app-build.yml new file mode 100644 index 0000000000..f8bd22ab6e --- /dev/null +++ b/.github/workflows/contentflows/reusable-app-build.yml @@ -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}} + \ No newline at end of file diff --git a/.github/workflows/contentflows/reusable-content-sync.yml b/.github/workflows/contentflows/reusable-content-sync.yml new file mode 100644 index 0000000000..74f1a644a5 --- /dev/null +++ b/.github/workflows/contentflows/reusable-content-sync.yml @@ -0,0 +1,99 @@ +################################################################################## +# About +################################################################################## +# Reuseable workflow to be called from content repos. +# Syncs assests and data from google sheets and creates a PR with changes + +################################################################################## +# 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}} + + + name: Perform content sync and create a PR + + +################################################################################## +# Main Code +################################################################################## +on: + workflow_call: + + jobs: + build: + runs-on: ubuntu-latest + steps: + + - name: Check out app code + uses: actions/checkout@v3 + with: + lfs: true + 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: + lfs: true + 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: + lfs: true + path: ".idems_app/deployments/${{env.DEPLOYMENT_NAME}}" + - name: Populate Encryption key + if: env.DEPLOYMENT_PRIVATE_KEY != '' + run: echo "${{env.DEPLOYMENT_PRIVATE_KEY}}" > ./.idems_app/deployments/${{env.DEPLOYMENT_NAME}}/encrypted/private.key + + # TODO - populate firebase as part of deployment set + - 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 parent deployment + run: yarn workflow deployment set $PARENT_DEPLOYMENT_NAME + + - name: Build parent + run: yarn build + + - name: Set deployment + run: yarn workflow deployment set $DEPLOYMENT_NAME + + - name: Build + run: yarn build + + - name: Sync sheets + run: yarn workflow sync + + - name: Create pull request + uses: peter-evans/create-pull-request@v5.0.2 + with: + path: ".idems_app/deployments/${{env.DEPLOYMENT_NAME}}" + title: "Testing" + body: "Automated content sync" \ No newline at end of file diff --git a/.github/workflows/contentflows/reusable-deploy-pr-preview.yml b/.github/workflows/contentflows/reusable-deploy-pr-preview.yml new file mode 100644 index 0000000000..65fcb3a07b --- /dev/null +++ b/.github/workflows/contentflows/reusable-deploy-pr-preview.yml @@ -0,0 +1,95 @@ +################################################################################## +# About +################################################################################## +# Reuseable workflow to be called from content repos. +# Deploy preview url for labelled PRs +# Specifies deployment target based on pr target branch +# Must specify all below secrets and variables - see documentation for details +# +# Version : 1.0 +# +################################################################################## +# Configuration +################################################################################## +env: + FIREBASE_PROJECT_ID: ${{vars.FIREBASE_PROJECT_ID}} # | ID of firebase project used (in case of multiple deployment targets just specify default) + FIREBASE_HOSTING_CHANNEL: ${{vars.FIREBASE_HOSTING_CHANNEL}} # | Name of channel to deploy to (default 'live' is main site, any other word, e.g. 'pr' will create random temp preview site) + FIREBASE_HOSTING_TARGET: ${{vars.FIREBASE_HOSTING_TARGET}} # | Optional override if using multiple hosting target sites (default target project ID) + FIREBASE_SERVICE_ACCOUNT: ${{secrets.FIREBASE_SERVICE_ACCOUNT}} # | JSON export of firebase service account (from console) + +################################################################################## +# Main Code +################################################################################## +name: Deploy PR Preview +concurrency: + group: deploy-pr-preview-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +on: + workflow_call: + +jobs: + build: + if: contains(github.event.pull_request.labels.*.name, 'test - preview') + uses: ./.github/workflows/contentflows/reusable-app-build.yml + with: + build-flags: --configuration "production,preview" + secrets: inherit + + deploy_preview: + needs: build + runs-on: ubuntu-latest + outputs: + urls: ${{ steps.deploy.outputs.urls }} + steps: + - uses: actions/checkout@v3 + + - 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: Populate Firebase Targets + run: | + FIREBASE_RC_TARGETS=$(jq -n \ + --argjson "${{env.FIREBASE_PROJECT_ID}}" \ + '{"hosting":{"${{env.FIREBASE_HOSTING_TARGET}}":["${{env.FIREBASE_HOSTING_TARGET}}"]}}' \ + '$ARGS.named' + ) + FIREBASE_RC=$(jq -n \ + --argjson projects '{"default":"${{env.FIREBASE_PROJECT_ID}}"}' \ + --argjson targets "$FIREBASE_RC_TARGETS" \ + '$ARGS.named' + ) + echo $FIREBASE_RC | jq '.' + echo $FIREBASE_RC > .firebaserc + + - name: Populate Firebase JSON + run: | + FIREBASE_JSON_HOSTING=$(jq -n \ + --arg target "${{ env.FIREBASE_HOSTING_TARGET }}" \ + --arg public "www" \ + --argjson ignore '["firebase.json"]' \ + --argjson rewrites '[{"source": "**","destination": "/index.html"}]' \ + '$ARGS.named' + ) + FIREBASE_JSON=$(jq -n \ + --argjson hosting "[$FIREBASE_JSON_HOSTING]" \ + '$ARGS.named' + ) + echo $FIREBASE_JSON | jq '.' + echo $FIREBASE_JSON > firebase.json + + - uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: "${{ secrets.GITHUB_TOKEN }}" + firebaseServiceAccount: "${{ env.FIREBASE_SERVICE_ACCOUNT }}" + projectId: "${{ env.FIREBASE_PROJECT_ID }}" + target: "${{ env.FIREBASE_HOSTING_TARGET }}" + expires: 14d + env: + FIREBASE_CLI_PREVIEWS: hostingchannels \ No newline at end of file diff --git a/.github/workflows/contentflows/reusable-deploy-web-preview.yml b/.github/workflows/contentflows/reusable-deploy-web-preview.yml new file mode 100644 index 0000000000..a468db2e63 --- /dev/null +++ b/.github/workflows/contentflows/reusable-deploy-web-preview.yml @@ -0,0 +1,119 @@ +################################################################################## +# About +################################################################################## +# Reuseable workflow to be called from content repos. +# Build and deploy app to firebase +# Supports deploying to custom hosting channel for long-lived preview urls (30d) +# Or using custom hosting target +# +# Version : 1.0 +# +################################################################################## +# Configuration +################################################################################## + +env: + FIREBASE_PROJECT_ID: ${{vars.FIREBASE_PROJECT_ID}} # | ID of firebase project used (in case of multiple deployment targets just specify default) + FIREBASE_HOSTING_CHANNEL: ${{vars.FIREBASE_HOSTING_CHANNEL}} # | Name of channel to deploy to (default 'live' is main site, any other word, e.g. 'pr' will create random temp preview site) + FIREBASE_HOSTING_TARGET: ${{vars.FIREBASE_HOSTING_TARGET}} # | Optional override if using multiple hosting target sites (default target project ID) + FIREBASE_SERVICE_ACCOUNT: ${{secrets.FIREBASE_SERVICE_ACCOUNT}} # | JSON export of firebase service account (from console) + + + +################################################################################## +# Main Code +################################################################################## +name: Deploy Web Preview +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +concurrency: + group: "deploy_preview" + cancel-in-progress: true + +on: + workflow_call: + +jobs: + build_action: + uses: ./.github/workflows/contentflows/reusable-app-build.yml + secrets: inherit + + deploy: + needs: build_action + runs-on: ubuntu-latest + outputs: + urls: ${{ steps.deploy.outputs.urls }} + steps: + # Extract build artifact + - uses: actions/checkout@v3 + + - 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 + + # Ensure FIREBASE_HOSTING_TARGET set (default fallback to projectId) + - name: Populate Env + if: ${{env.FIREBASE_HOSTING_TARGET == ''}} + run: echo "FIREBASE_HOSTING_TARGET=${{env.FIREBASE_PROJECT_ID}}" >> "$GITHUB_ENV" + + # Create a .firebaserc file mapping any firebase deployment host targets (required if multi-host projects) + # e.g. {"projects": {"default": "my_app"},"targets": {"my_app": {"hosting": {"my_app_dev":["my_app_dev"]} } } + - name: Populate Firebase Targets + run: | + FIREBASE_RC_TARGETS=$(jq -n \ + --argjson "${{env.FIREBASE_PROJECT_ID}}" \ + '{"hosting":{"${{env.FIREBASE_HOSTING_TARGET}}":["${{env.FIREBASE_HOSTING_TARGET}}"]}}' \ + '$ARGS.named' + ) + FIREBASE_RC=$(jq -n \ + --argjson projects '{"default":"${{env.FIREBASE_PROJECT_ID}}"}' \ + --argjson targets "$FIREBASE_RC_TARGETS" \ + '$ARGS.named' + ) + echo $FIREBASE_RC | jq '.' + echo $FIREBASE_RC > .firebaserc + + # Create a firebase.json file to handle single-page-app hosting redirects + # e.g. {"hosting": [{"target": "app","public": "www","ignore": ["firebase.json"], "rewrites": [{"source": "**","destination": "/index.html"}] }]} + - name: Populate Firebase JSON + run: | + FIREBASE_JSON_HOSTING=$(jq -n \ + --arg target "${{ env.FIREBASE_HOSTING_TARGET }}" \ + --arg public "www" \ + --argjson ignore '["firebase.json"]' \ + --argjson rewrites '[{"source": "**","destination": "/index.html"}]' \ + '$ARGS.named' + ) + FIREBASE_JSON=$(jq -n \ + --argjson hosting "[$FIREBASE_JSON_HOSTING]" \ + '$ARGS.named' + ) + echo $FIREBASE_JSON | jq '.' + echo $FIREBASE_JSON > firebase.json + + # Deploy to firebase + - id: deploy + uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: "${{ secrets.GITHUB_TOKEN }}" + firebaseServiceAccount: "${{ env.FIREBASE_SERVICE_ACCOUNT }}" + projectId: "${{ env.FIREBASE_PROJECT_ID }}" + channelId: "${{ env.FIREBASE_HOSTING_CHANNEL }}" + target: "${{ env.FIREBASE_HOSTING_TARGET }}" + expires: "30d" +################################################################################## +# Useful Links +################################################################################## +# https://firebase.google.com/docs/hosting/full-config +# https://firebase.google.com/docs/cli/targets + +# https://www.baeldung.com/linux/jq-command-json +# https://jqlang.github.io/jq/manual/ +# https://jqplay.org/ + +# echo $FIREBASE_JSON | jq '.hosting[0]' \ No newline at end of file