diff --git a/.github/workflows/deployment-hosting.yml b/.github/workflows/deprecated/deployment-hosting.yml similarity index 100% rename from .github/workflows/deployment-hosting.yml rename to .github/workflows/deprecated/deployment-hosting.yml diff --git a/.github/workflows/test-app-build.yml b/.github/workflows/test-app-build.yml deleted file mode 100644 index 7da7db3915..0000000000 --- a/.github/workflows/test-app-build.yml +++ /dev/null @@ -1,111 +0,0 @@ -################################################################################## -# 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: - artifact-name: - description: Name of the artifact to upload - type: string - default: www - 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: - GIT_SHA: - description: "Git SHA of build head" - value: ${{ jobs.configure_build.outputs.GIT_SHA }} - -jobs: - build: - outputs: - 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: Populate Encryption key - if: env.DEPLOYMENT_PRIVATE_KEY != '' - run: echo "${{env.DEPLOYMENT_PRIVATE_KEY}}" > ./.idems_app/deployments/${{env.DEPLOYMENT_NAME}}/encrypted/private.key - - - 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: ${{inputs.artifact-name}} diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index 5c825701a7..9e8ffdcbd2 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -13,4 +13,4 @@ jobs: skip-upload: true # When testing build binary assets not required lfs: false - deployment: debug \ No newline at end of file + deployment-env: debug \ No newline at end of file diff --git a/.github/workflows/test-preview.yml b/.github/workflows/test-preview.yml index 2fccc3b6b7..61e1552aaf 100644 --- a/.github/workflows/test-preview.yml +++ b/.github/workflows/test-preview.yml @@ -1,17 +1,17 @@ -# Deploy preview url for labelled PRs -# Specifies deployment target based on pr target branch -# Master -> debug -# Deployment/{deployment_name} -> {deployment_name} +env: + # Actions environment to load for secrets and variables + # See child web-build action for vars and secrets required + FIREBASE_HOSTING_TARGET: ${{vars.FIREBASE_HOSTING_TARGET}} + FIREBASE_PROJECT_ID: ${{vars.FIREBASE_PROJECT_ID}} name: Deployment Preview on: pull_request: types: [labeled, synchronize] branches: - - deployment/* - master concurrency: - group: deployment-preview-${{ github.workflow }}-${{ github.ref }} + group: test-preview-${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: build: @@ -20,15 +20,14 @@ jobs: secrets: inherit with: build-flags: --configuration "production,preview" - # use branch name from PR target as default - # https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables - deployment: ${{ github.base_ref }} + deployment-env: debug deploy_preview: needs: build runs-on: ubuntu-latest + environment: debug steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Download Build Artifact uses: actions/download-artifact@v3 with: @@ -37,12 +36,21 @@ jobs: run: | mkdir www tar -xf artifact.tar --directory www + # HACK - although deployments set their firebase.json from config the file is + # not passed back from artifact so hardcode via action + - name: Populate firebase config + run: | + cp firebase.template.json firebase.json + sed -i 's/${FIREBASE_HOSTING_TARGET}/${{ env.FIREBASE_HOSTING_TARGET }}/g' firebase.json + cp .template.firebaserc .firebaserc + sed -i 's/${FIREBASE_HOSTING_TARGET}/${{ env.FIREBASE_HOSTING_TARGET }}/g' .firebaserc + sed -i 's/${FIREBASE_PROJECT_ID}/${{ env.FIREBASE_PROJECT_ID }}/g' .firebaserc - uses: FirebaseExtended/action-hosting-deploy@v0 with: repoToken: "${{ secrets.GITHUB_TOKEN }}" firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_PLH_TEENS_APP1 }}" - projectId: plh-teens-app1 - target: "${{needs.build.outputs.DEPLOYMENT_NAME}}" + projectId: ${{env.FIREBASE_PROJECT_ID}} + target: "${{env.FIREBASE_HOSTING_TARGET}}" expires: 14d env: FIREBASE_CLI_PREVIEWS: hostingchannels diff --git a/.github/workflows/test-visual.yml b/.github/workflows/test-visual.yml index 0ae0cab61f..35b4f688da 100644 --- a/.github/workflows/test-visual.yml +++ b/.github/workflows/test-visual.yml @@ -1,7 +1,3 @@ -env: - # TODO: create a dedicated screenshots deployment - DEPLOYMENT: debug - # Generate a set of screenshots for the current branch and compare against previously generated on master name: Test-Visual on: @@ -24,23 +20,22 @@ jobs: uses: ./.github/workflows/web-build.yml secrets: inherit with: - deployment: $DEPLOYMENT + # TODO: create a dedicated screenshots env + deployment-env: debug - test_visual_compare: + test_visual: needs: build runs-on: ubuntu-latest timeout-minutes: 60 steps: - ########################################################################################### - # Setup - ########################################################################################### - - uses: actions/checkout@v3 - + ########################################################################################### + # Setup + ########################################################################################### + - uses: actions/checkout@v4 - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 18.x - + node-version: 18.x - uses: actions/cache/restore@v3 id: cache with: @@ -48,10 +43,17 @@ jobs: 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 + - uses: actions/cache/save@v3 + if: steps.cache.outputs.cache-hit != 'true' + with: + path: ./.yarn/cache + key: ${{ runner.os }}-node-modules-yarn-v1-${{ hashFiles('yarn.lock') }} + ############################################################################# + # Download build + ############################################################################# - name: Download Build Artifact uses: actions/download-artifact@v3 with: @@ -64,10 +66,10 @@ jobs: # HACK - as lifecycle_actions block template view simply remove them all # TODO - review if still required (CC 2023-08-15) - - name : HACK - Remove lifecycle actions + - name: HACK - Remove lifecycle actions run: | rm -f -R www/assets/app_data/sheets/data_list/lifecycle_actions - + ########################################################################################### # Generate ########################################################################################### @@ -83,7 +85,7 @@ jobs: path: packages/test-visual/output/screenshots retention-days: 90 if-no-files-found: error - + ########################################################################################### # Compare ########################################################################################### @@ -141,7 +143,6 @@ jobs: **Run Details** https://github.com/IDEMSInternational/parenting-app-ui/actions/runs/${{github.run_id}} - # Alt implementation to DL artifact using action instead of download script # Download artifact populated from latest `test-visual-generate` workflow run on master branch diff --git a/.github/workflows/web-build.yml b/.github/workflows/web-build.yml index 565a90622e..e317a1535f 100644 --- a/.github/workflows/web-build.yml +++ b/.github/workflows/web-build.yml @@ -3,10 +3,9 @@ # These variables will be populated from environment ################################################################################## env: - DEPLOYMENT_NAME_DEFAULT: debug DEPLOYMENT_REPO: ${{vars.DEPLOYMENT_REPO}} - DEPLOYMENT_PRIVATE_KEY: ${{secrets.DEPLOYMENT_PRIVATE_KEY}} - FIREBASE_CONFIG_TS: ${{secrets.FIREBASE_CONFIG_TS}} + DEPLOYMENT_NAME: ${{vars.DEPLOYMENT_NAME}} + DEPLOYMENT_REPO_PRIVATE_KEY: ${{secrets.DEPLOYMENT_PRIVATE_KEY}} ################################################################################## # Main Code @@ -25,6 +24,11 @@ on: # Optional variables to configure from parent workflow via workflow_call ############################################################################# inputs: + deployment-env: + description: Name of environment to load deployment variables from + type: string + required: true + default: debug build-flags: description: Additional flags to pass to build command (e.g. base-href) type: string @@ -33,12 +37,6 @@ on: description: Name of branch to build (defaults to event trigger sha) type: string default: "" - deployment: - description: | - Target deployment name. If branch name provided will take suffix (`prod/my_deployment` -> `my_deployment`). - Will load variables from named deployment environment - type: string - default: "" include-tests: description: "Specify whether to include running workspace lint and test before build" type: boolean @@ -64,44 +62,18 @@ on: value: ${{ jobs.configure_build.outputs.GIT_SHA }} jobs: - ############################################################################# - # configure Build - # Deployment-specific variables are loaded from deployment name environment contexts - # stored on github actions. - # Determine which set of environment variables to load, depending on passed inputs, - # target branch names or default fallback - # Populate variables to use as inputs in next build job - # Pattern found in this question: https://github.com/actions/runner/issues/998#issue-817330769 - # Outputs here will also be made available to parent workflows via workflow_call outputs - ############################################################################# + configure_build: + environment: ${{inputs.deployment-env}} outputs: DEPLOYMENT_NAME: ${{ steps.populate.outputs.DEPLOYMENT_NAME }} GIT_SHA: ${{ steps.populate.outputs.GIT_SHA }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{inputs.branch}} - - name: Set named input environment - if: ${{ inputs.environment }} - run: | - echo "DEPLOYMENT_NAME=${{inputs.environment}}" >> $GITHUB_ENV; - shell: bash - - - name: Set environment from target - if: ${{inputs.deployment && inputs.deployment != 'master' && inputs.deployment!='refs/heads/master'}} - run: | - echo "DEPLOYMENT_NAME=$(echo ${{inputs.deployment}} | sed 's/.*\///')" >> $GITHUB_ENV; - shell: bash - - - name: Set default environment - if: ${{ !env.DEPLOYMENT_NAME }} - run: | - echo "DEPLOYMENT_NAME=$DEPLOYMENT_NAME_DEFAULT" >> $GITHUB_ENV; - shell: bash - # Output determined environment name alongside git SHA (for use in error logging) - name: Populate Outputs id: populate @@ -116,9 +88,8 @@ jobs: environment: ${{needs.configure_build.outputs.DEPLOYMENT_NAME}} env: GIT_SHA: ${{ needs.configure_build.outputs.GIT_SHA }} - DEPLOYMENT_NAME: ${{ needs.configure_build.outputs.DEPLOYMENT_NAME }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: lfs: ${{inputs.lfs}} ref: ${{inputs.branch}} @@ -161,8 +132,7 @@ jobs: run: echo "export const GIT_SHA = \"$GIT_SHA\";" > src/environments/sha.ts - name: Import remote deployment - if: ${{env.DEPLOYMENT_REPO}} - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: ${{env.DEPLOYMENT_REPO}} lfs: ${{inputs.lfs}} @@ -170,9 +140,9 @@ jobs: # TODO - add support for specific branch/release - name: Set deployment private key - if: ${{env.DEPLOYMENT_PRIVATE_KEY}} + if: ${{env.DEPLOYMENT_REPO_PRIVATE_KEY}} run: - echo $DEPLOYMENT_PRIVATE_KEY > .idems_app/deployments/$DEPLOYMENT_NAME/encrypted/private.key + echo $DEPLOYMENT_REPO_PRIVATE_KEY > .idems_app/deployments/$DEPLOYMENT_NAME/encrypted/private.key - name: Set deployment run: yarn workflow deployment set ${{env.DEPLOYMENT_NAME}}