Skip to content

Commit 5203508

Browse files
authored
Merge pull request #2278 from IDEMSInternational/refactor/debug-gh-actions
fix: test actions
2 parents 2faf3b4 + bf79c59 commit 5203508

File tree

6 files changed

+54
-186
lines changed

6 files changed

+54
-186
lines changed

.github/workflows/test-app-build.yml

-111
This file was deleted.

.github/workflows/test-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ jobs:
1313
skip-upload: true
1414
# When testing build binary assets not required
1515
lfs: false
16-
deployment: debug
16+
deployment-env: debug

.github/workflows/test-preview.yml

+20-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# Deploy preview url for labelled PRs
2-
# Specifies deployment target based on pr target branch
3-
# Master -> debug
4-
# Deployment/{deployment_name} -> {deployment_name}
1+
env:
2+
# Actions environment to load for secrets and variables
3+
# See child web-build action for vars and secrets required
4+
FIREBASE_HOSTING_TARGET: ${{vars.FIREBASE_HOSTING_TARGET}}
5+
FIREBASE_PROJECT_ID: ${{vars.FIREBASE_PROJECT_ID}}
56

67
name: Deployment Preview
78
on:
89
pull_request:
910
types: [labeled, synchronize]
1011
branches:
11-
- deployment/*
1212
- master
1313
concurrency:
14-
group: deployment-preview-${{ github.workflow }}-${{ github.ref }}
14+
group: test-preview-${{ github.workflow }}-${{ github.ref }}
1515
cancel-in-progress: true
1616
jobs:
1717
build:
@@ -20,15 +20,14 @@ jobs:
2020
secrets: inherit
2121
with:
2222
build-flags: --configuration "production,preview"
23-
# use branch name from PR target as default
24-
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
25-
deployment: ${{ github.base_ref }}
23+
deployment-env: debug
2624

2725
deploy_preview:
2826
needs: build
2927
runs-on: ubuntu-latest
28+
environment: debug
3029
steps:
31-
- uses: actions/checkout@v3
30+
- uses: actions/checkout@v4
3231
- name: Download Build Artifact
3332
uses: actions/download-artifact@v3
3433
with:
@@ -37,12 +36,21 @@ jobs:
3736
run: |
3837
mkdir www
3938
tar -xf artifact.tar --directory www
39+
# HACK - although deployments set their firebase.json from config the file is
40+
# not passed back from artifact so hardcode via action
41+
- name: Populate firebase config
42+
run: |
43+
cp firebase.template.json firebase.json
44+
sed -i 's/${FIREBASE_HOSTING_TARGET}/${{ env.FIREBASE_HOSTING_TARGET }}/g' firebase.json
45+
cp .template.firebaserc .firebaserc
46+
sed -i 's/${FIREBASE_HOSTING_TARGET}/${{ env.FIREBASE_HOSTING_TARGET }}/g' .firebaserc
47+
sed -i 's/${FIREBASE_PROJECT_ID}/${{ env.FIREBASE_PROJECT_ID }}/g' .firebaserc
4048
- uses: FirebaseExtended/action-hosting-deploy@v0
4149
with:
4250
repoToken: "${{ secrets.GITHUB_TOKEN }}"
4351
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_PLH_TEENS_APP1 }}"
44-
projectId: plh-teens-app1
45-
target: "${{needs.build.outputs.DEPLOYMENT_NAME}}"
52+
projectId: ${{env.FIREBASE_PROJECT_ID}}
53+
target: "${{env.FIREBASE_HOSTING_TARGET}}"
4654
expires: 14d
4755
env:
4856
FIREBASE_CLI_PREVIEWS: hostingchannels

.github/workflows/test-visual.yml

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
env:
2-
# TODO: create a dedicated screenshots deployment
3-
DEPLOYMENT: debug
4-
51
# Generate a set of screenshots for the current branch and compare against previously generated on master
62
name: Test-Visual
73
on:
@@ -24,34 +20,40 @@ jobs:
2420
uses: ./.github/workflows/web-build.yml
2521
secrets: inherit
2622
with:
27-
deployment: $DEPLOYMENT
23+
# TODO: create a dedicated screenshots env
24+
deployment-env: debug
2825

29-
test_visual_compare:
26+
test_visual:
3027
needs: build
3128
runs-on: ubuntu-latest
3229
timeout-minutes: 60
3330
steps:
34-
###########################################################################################
35-
# Setup
36-
###########################################################################################
37-
- uses: actions/checkout@v3
38-
31+
###########################################################################################
32+
# Setup
33+
###########################################################################################
34+
- uses: actions/checkout@v4
3935
- name: Setup Node
4036
uses: actions/setup-node@v3
4137
with:
42-
node-version: 18.x
43-
38+
node-version: 18.x
4439
- uses: actions/cache/restore@v3
4540
id: cache
4641
with:
4742
path: ./.yarn/cache
4843
key: ${{ runner.os }}-node-modules-yarn-v1-${{ hashFiles('yarn.lock') }}
4944
restore-keys: |
5045
${{ runner.os }}-node-modules-yarn-v1-
51-
5246
- name: Install node modules
5347
run: yarn install --immutable
48+
- uses: actions/cache/save@v3
49+
if: steps.cache.outputs.cache-hit != 'true'
50+
with:
51+
path: ./.yarn/cache
52+
key: ${{ runner.os }}-node-modules-yarn-v1-${{ hashFiles('yarn.lock') }}
5453

54+
#############################################################################
55+
# Download build
56+
#############################################################################
5557
- name: Download Build Artifact
5658
uses: actions/download-artifact@v3
5759
with:
@@ -64,10 +66,10 @@ jobs:
6466
6567
# HACK - as lifecycle_actions block template view simply remove them all
6668
# TODO - review if still required (CC 2023-08-15)
67-
- name : HACK - Remove lifecycle actions
69+
- name: HACK - Remove lifecycle actions
6870
run: |
6971
rm -f -R www/assets/app_data/sheets/data_list/lifecycle_actions
70-
72+
7173
###########################################################################################
7274
# Generate
7375
###########################################################################################
@@ -83,7 +85,7 @@ jobs:
8385
path: packages/test-visual/output/screenshots
8486
retention-days: 90
8587
if-no-files-found: error
86-
88+
8789
###########################################################################################
8890
# Compare
8991
###########################################################################################
@@ -141,7 +143,6 @@ jobs:
141143
**Run Details**
142144
https://github.com/IDEMSInternational/parenting-app-ui/actions/runs/${{github.run_id}}
143145
144-
145146
# Alt implementation to DL artifact using action instead of download script
146147

147148
# Download artifact populated from latest `test-visual-generate` workflow run on master branch

.github/workflows/web-build.yml

+14-44
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
# These variables will be populated from environment
44
##################################################################################
55
env:
6-
DEPLOYMENT_NAME_DEFAULT: debug
76
DEPLOYMENT_REPO: ${{vars.DEPLOYMENT_REPO}}
8-
DEPLOYMENT_PRIVATE_KEY: ${{secrets.DEPLOYMENT_PRIVATE_KEY}}
9-
FIREBASE_CONFIG_TS: ${{secrets.FIREBASE_CONFIG_TS}}
7+
DEPLOYMENT_NAME: ${{vars.DEPLOYMENT_NAME}}
8+
DEPLOYMENT_REPO_PRIVATE_KEY: ${{secrets.DEPLOYMENT_PRIVATE_KEY}}
109

1110
##################################################################################
1211
# Main Code
@@ -25,6 +24,11 @@ on:
2524
# Optional variables to configure from parent workflow via workflow_call
2625
#############################################################################
2726
inputs:
27+
deployment-env:
28+
description: Name of environment to load deployment variables from
29+
type: string
30+
required: true
31+
default: debug
2832
build-flags:
2933
description: Additional flags to pass to build command (e.g. base-href)
3034
type: string
@@ -33,12 +37,6 @@ on:
3337
description: Name of branch to build (defaults to event trigger sha)
3438
type: string
3539
default: ""
36-
deployment:
37-
description: |
38-
Target deployment name. If branch name provided will take suffix (`prod/my_deployment` -> `my_deployment`).
39-
Will load variables from named deployment environment
40-
type: string
41-
default: ""
4240
include-tests:
4341
description: "Specify whether to include running workspace lint and test before build"
4442
type: boolean
@@ -64,44 +62,18 @@ on:
6462
value: ${{ jobs.configure_build.outputs.GIT_SHA }}
6563

6664
jobs:
67-
#############################################################################
68-
# configure Build
69-
# Deployment-specific variables are loaded from deployment name environment contexts
70-
# stored on github actions.
71-
# Determine which set of environment variables to load, depending on passed inputs,
72-
# target branch names or default fallback
73-
# Populate variables to use as inputs in next build job
74-
# Pattern found in this question: https://github.com/actions/runner/issues/998#issue-817330769
75-
# Outputs here will also be made available to parent workflows via workflow_call outputs
76-
#############################################################################
65+
7766
configure_build:
67+
environment: ${{inputs.deployment-env}}
7868
outputs:
7969
DEPLOYMENT_NAME: ${{ steps.populate.outputs.DEPLOYMENT_NAME }}
8070
GIT_SHA: ${{ steps.populate.outputs.GIT_SHA }}
8171
runs-on: ubuntu-latest
8272
steps:
83-
- uses: actions/checkout@v3
73+
- uses: actions/checkout@v4
8474
with:
8575
ref: ${{inputs.branch}}
8676

87-
- name: Set named input environment
88-
if: ${{ inputs.environment }}
89-
run: |
90-
echo "DEPLOYMENT_NAME=${{inputs.environment}}" >> $GITHUB_ENV;
91-
shell: bash
92-
93-
- name: Set environment from target
94-
if: ${{inputs.deployment && inputs.deployment != 'master' && inputs.deployment!='refs/heads/master'}}
95-
run: |
96-
echo "DEPLOYMENT_NAME=$(echo ${{inputs.deployment}} | sed 's/.*\///')" >> $GITHUB_ENV;
97-
shell: bash
98-
99-
- name: Set default environment
100-
if: ${{ !env.DEPLOYMENT_NAME }}
101-
run: |
102-
echo "DEPLOYMENT_NAME=$DEPLOYMENT_NAME_DEFAULT" >> $GITHUB_ENV;
103-
shell: bash
104-
10577
# Output determined environment name alongside git SHA (for use in error logging)
10678
- name: Populate Outputs
10779
id: populate
@@ -116,9 +88,8 @@ jobs:
11688
environment: ${{needs.configure_build.outputs.DEPLOYMENT_NAME}}
11789
env:
11890
GIT_SHA: ${{ needs.configure_build.outputs.GIT_SHA }}
119-
DEPLOYMENT_NAME: ${{ needs.configure_build.outputs.DEPLOYMENT_NAME }}
12091
steps:
121-
- uses: actions/checkout@v3
92+
- uses: actions/checkout@v4
12293
with:
12394
lfs: ${{inputs.lfs}}
12495
ref: ${{inputs.branch}}
@@ -161,18 +132,17 @@ jobs:
161132
run: echo "export const GIT_SHA = \"$GIT_SHA\";" > src/environments/sha.ts
162133

163134
- name: Import remote deployment
164-
if: ${{env.DEPLOYMENT_REPO}}
165-
uses: actions/checkout@v3
135+
uses: actions/checkout@v4
166136
with:
167137
repository: ${{env.DEPLOYMENT_REPO}}
168138
lfs: ${{inputs.lfs}}
169139
path: ".idems_app/deployments/${{env.DEPLOYMENT_NAME}}"
170140
# TODO - add support for specific branch/release
171141

172142
- name: Set deployment private key
173-
if: ${{env.DEPLOYMENT_PRIVATE_KEY}}
143+
if: ${{env.DEPLOYMENT_REPO_PRIVATE_KEY}}
174144
run:
175-
echo $DEPLOYMENT_PRIVATE_KEY > .idems_app/deployments/$DEPLOYMENT_NAME/encrypted/private.key
145+
echo $DEPLOYMENT_REPO_PRIVATE_KEY > .idems_app/deployments/$DEPLOYMENT_NAME/encrypted/private.key
176146

177147
- name: Set deployment
178148
run: yarn workflow deployment set ${{env.DEPLOYMENT_NAME}}

0 commit comments

Comments
 (0)