Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test actions #2278

Merged
merged 15 commits into from
Apr 5, 2024
111 changes: 0 additions & 111 deletions .github/workflows/test-app-build.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
skip-upload: true
# When testing build binary assets not required
lfs: false
deployment: debug
deployment-env: debug
32 changes: 20 additions & 12 deletions .github/workflows/test-preview.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand All @@ -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
37 changes: 19 additions & 18 deletions .github/workflows/test-visual.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -24,34 +20,40 @@ 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:
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
- 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:
Expand All @@ -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
###########################################################################################
Expand All @@ -83,7 +85,7 @@ jobs:
path: packages/test-visual/output/screenshots
retention-days: 90
if-no-files-found: error

###########################################################################################
# Compare
###########################################################################################
Expand Down Expand Up @@ -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
Expand Down
58 changes: 14 additions & 44 deletions .github/workflows/web-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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}}
Expand Down Expand Up @@ -161,18 +132,17 @@ 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}}
path: ".idems_app/deployments/${{env.DEPLOYMENT_NAME}}"
# 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}}
Expand Down
Loading