Skip to content

Commit 3ddf419

Browse files
vmartashethj
andauthored
[CI workflow] automate generating, configurating, and deploying build from develop branch (@W-19170135@) (#3058)
* Add new performance metrics workflow * Add comment * Disable some steps that are not needed * Update todos * Generate the project * Avoid dirtying workspace and remove unnecessary step * Tweak parameters * Allow for internal short codes * Align with the order of answers to the extensibility question * Create update-csp-directives.js * Rename script for clarity * Schedule it to run before the performance tests * Move constant into the config file * Move CSP directives into the config file * Make sure the corresponding .hbs files are up to date * Now scripts looks for the config file * Fix linting errors * Add auto lint fixing * For backward compatibility * New step to add CSP directives * Log where the file is at * Add a new script * Address a few todos * Allow updating property with the same value * Finish and clean up the workflow * Move scripts and remove default value for config path * No longer assume default value for config path And no longer preserving comments * No longer support null, undefined values * Delete unnecessary comments * Revert changes in retail-react-app * Create a new generator preset * Revert changes to the generator * Add csp directives to ssr.js.hbs * Update app/constants.js files to support the new preset * No longer needing these scripts * Workflow now uses the new generator preset * No need to validate app in this case * Add the preset to more files * Revert some changes and keep one change * Delete extra space * Empty commit * Simplify the handlebar template logic * No more hardcoding the `generated-projects` path * Move feature toggle for partial hydration into the config file * Remove unnecessary tests * Update CHANGELOG.md * Make sure all ssr.js related files are in sync * Fix linting error I wanted to preserve the comma at the end of the line because otherwise, I'm worried that it's easy to overlook it later. --------- Co-authored-by: Jainam Sheth <j.sheth@salesforce.com>
1 parent 96b7bda commit 3ddf419

File tree

22 files changed

+340
-70
lines changed

22 files changed

+340
-70
lines changed

.github/actions/e2e_generate_app/action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,24 @@ inputs:
1010
required: false
1111
type: string
1212

13+
outputs:
14+
project_path:
15+
description: Path to the generated project directory
16+
value: ${{ steps.generate_project.outputs.project_path }}
17+
1318
runs:
1419
using: composite
1520
steps:
1621
- name: Generate new project based on project-key
22+
id: generate_project
1723
run: |
1824
COMMAND="node e2e/scripts/generate-project.js --project-key ${{ inputs.PROJECT_KEY }}"
1925
if [[ -n "${{ inputs.TEMPLATE_VERSION }}" ]]; then
2026
COMMAND="$COMMAND --templateVersion ${{ inputs.TEMPLATE_VERSION }}"
2127
fi
2228
$COMMAND
29+
30+
# Return path to the generated project
31+
GENERATED_PROJECTS_DIR=$(node -e "console.log(require('./e2e/config.js').GENERATED_PROJECTS_DIR)")
32+
echo "project_path=$GENERATED_PROJECTS_DIR/${{ inputs.PROJECT_KEY }}" >> $GITHUB_OUTPUT
2333
shell: bash

.github/actions/generate_app/action.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ inputs:
2222
project_dir:
2323
description: Project Directory
2424

25+
outputs:
26+
project_path:
27+
description: Path to the generated project directory
28+
value: ${{ steps.generate_project.outputs.project_path }}
29+
2530
runs:
2631
using: composite
2732
steps:
@@ -31,20 +36,20 @@ runs:
3136
run: |
3237
use_extensibility_input="${{ inputs.use_extensibility }}"
3338
if [ "use_extensibility_input" = "true" ]; then
34-
use_extensibility_value=2
35-
else
3639
use_extensibility_value=1
40+
else
41+
use_extensibility_value=2
3742
fi
38-
echo "USE_EXTENSIBILITY_VALUE=$use_extensibility_value" >> $GITHUB_ENV
39-
43+
echo "USE_EXTENSIBILITY_VALUE=$use_extensibility_value" >> $GITHUB_ENV
44+
4045
is_private_client_input="${{ inputs.is_private_client }}"
4146
if [ "$is_private_client_input" = "true" ]; then
4247
is_private_client_value=1
4348
else
4449
is_private_client_value=2
4550
fi
4651
echo "IS_PRIVATE_CLIENT_VALUE=$is_private_client_value" >> $GITHUB_ENV
47-
52+
4853
setup_hybrid_input="${{ inputs.setup_hybrid }}"
4954
if [ "$setup_hybrid_input" = "true" ]; then
5055
setup_hybrid_value=2
@@ -53,6 +58,8 @@ runs:
5358
fi
5459
echo "SETUP_HYBRID_VALUE=$setup_hybrid_value" >> $GITHUB_ENV
5560
61+
# TODO: update this to use the standard input feature that Ben created recently
62+
# TODO: this action does not finish successfully because of a dirty-workspace error, due to creating this generator-responses.json
5663
- name: Build project generator inputs
5764
id: build_generator_inputs
5865
shell: bash
@@ -107,11 +114,16 @@ runs:
107114
run: |
108115
cat generator-responses.json
109116
node e2e/scripts/generate-project.js --project-config "$(jq -c . generator-responses.json)"
117+
118+
# Return path to the generated project
119+
GENERATED_PROJECTS_DIR=$(node -e "console.log(require('./e2e/config.js').GENERATED_PROJECTS_DIR)")
120+
echo "project_path=$GENERATED_PROJECTS_DIR/${{ inputs.project_dir }}" >> $GITHUB_OUTPUT
110121
shell: bash
111122

123+
# TODO: I think we can safely delete this step. We already install the dependencies in the previous step.
112124
- name: Build generated project
113125
id: build_generated_project
114-
working-directory: ../generated-projects/${{ inputs.project_dir }}
126+
working-directory: ${{ steps.generate_project.outputs.project_path }}
115127
run: |-
116128
npm ci
117129
npm run build

.github/workflows/deploy_latest_release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ jobs:
7070
node ./scripts/gtime.js monorepo_install npm ci
7171
7272
- name: Generate Retail App Demo
73+
id: generate_app
7374
uses: ./.github/actions/e2e_generate_app
7475
with:
7576
PROJECT_KEY: ${{ matrix.environment.project_key }}
@@ -94,7 +95,7 @@ jobs:
9495
- name: Push Bundle to MRT (${{matrix.environment.name}})
9596
uses: "./.github/actions/push_to_mrt"
9697
with:
97-
CWD: "../generated-projects/${{ matrix.environment.project_key }}"
98+
CWD: ${{ steps.generate_app.outputs.project_path }}
9899
TARGET: ${{ matrix.environment.target }}
99100
PROJECT: ${{ matrix.environment.project }}
100101
MESSAGE: ${{ env.BUNDLE_NAME }})

.github/workflows/e2e-pr.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
echo "retail_app_template_version=$version" >> "$GITHUB_ENV"
6565
6666
- name: Generate Retail App Private Client
67+
id: generate_app
6768
if: ${{ env.SKIP_WORKFLOW != 'true' }}
6869
uses: ./.github/actions/e2e_generate_app
6970
with:
@@ -89,7 +90,7 @@ jobs:
8990
if: ${{ env.SKIP_WORKFLOW != 'true' }}
9091
uses: './.github/actions/push_to_mrt'
9192
with:
92-
CWD: '../generated-projects/retail-app-no-ext'
93+
CWD: ${{ steps.generate_app.outputs.project_path }}
9394
# TODO: Use the MRT target ID from the target lock step above.
9495
TARGET: e2e-tests-pwa-kit
9596
FLAGS: --wait

.github/workflows/e2e.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ jobs:
114114
echo "retail_app_template_version=$version" >> "$GITHUB_ENV"
115115
116116
- name: Generate Retail App Without Extensibility
117+
id: generate_app_no_ext
117118
uses: ./.github/actions/e2e_generate_app
118119
with:
119120
PROJECT_KEY: "retail-app-no-ext"
@@ -134,7 +135,7 @@ jobs:
134135
- name: Push Bundle to MRT (E2E Test PWA Kit)
135136
uses: "./.github/actions/push_to_mrt"
136137
with:
137-
CWD: "../generated-projects/retail-app-no-ext"
138+
CWD: ${{ steps.generate_app_no_ext.outputs.project_path }}
138139
TARGET: e2e-tests-pwa-kit
139140
FLAGS: --wait
140141

@@ -231,6 +232,7 @@ jobs:
231232
echo "retail_app_template_version=$version" >> "$GITHUB_ENV"
232233
233234
- name: Generate Retail App With Extensibility
235+
id: generate_app_ext
234236
uses: ./.github/actions/e2e_generate_app
235237
with:
236238
PROJECT_KEY: "retail-app-ext"
@@ -251,7 +253,7 @@ jobs:
251253
- name: Push Bundle to MRT (E2E Test PWA Kit)
252254
uses: "./.github/actions/push_to_mrt"
253255
with:
254-
CWD: "../generated-projects/retail-app-ext"
256+
CWD: ${{ steps.generate_app_ext.outputs.project_path }}
255257
TARGET: e2e-tests-pwa-kit
256258
FLAGS: --wait
257259

@@ -346,6 +348,7 @@ jobs:
346348
echo "retail_app_template_version=$version" >> "$GITHUB_ENV"
347349
348350
- name: Generate Retail App Private Client
351+
id: generate_app_private_client
349352
uses: ./.github/actions/e2e_generate_app
350353
with:
351354
PROJECT_KEY: "retail-app-private-client"
@@ -366,7 +369,7 @@ jobs:
366369
- name: Push Bundle to MRT
367370
uses: "./.github/actions/push_to_mrt"
368371
with:
369-
CWD: "../generated-projects/retail-app-private-client"
372+
CWD: ${{ steps.generate_app_private_client.outputs.project_path }}
370373
TARGET: e2e-pwa-kit-private
371374
FLAGS: --wait
372375

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: SalesforceCommerceCloud/pwa-kit/performance-metrics
2+
3+
on:
4+
workflow_dispatch: # Allows you to manually run the workflow on any branch.
5+
schedule:
6+
# Run every day at 7pm (PST) - cron uses UTC times.
7+
# We want to run it before the performance tests are scheduled to run.
8+
# Runs on the default branch.
9+
- cron: '0 3 * * *'
10+
11+
jobs:
12+
run-performance-metrics:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 22
22+
cache: npm
23+
24+
- name: Install Monorepo Dependencies
25+
run: |-
26+
npm ci
27+
28+
- name: Generate App
29+
id: generate_app
30+
uses: ./.github/actions/e2e_generate_app
31+
with:
32+
PROJECT_KEY: "retail-react-app-performance-tests"
33+
34+
- name: Create MRT credentials file
35+
uses: './.github/actions/create_mrt'
36+
with:
37+
mobify_user: ${{ secrets.MOBIFY_STG_CLIENT_USER }}
38+
mobify_api_key: ${{ secrets.MOBIFY_STG_CLIENT_API_KEY }}
39+
40+
- name: Push Bundle to MRT
41+
uses: './.github/actions/push_to_mrt'
42+
with:
43+
CWD: '${{ steps.generate_app.outputs.project_path }}'
44+
PROJECT: q4-pwa-perf-develop
45+
TARGET: production
46+
FLAGS: --wait --cloud-origin https://cloud-testing.mobify-staging.com

.github/workflows/setup_pwa_manual.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ jobs:
8989
with:
9090
project_id: ${{ github.event.inputs.project_id }}
9191
target_id: ${{ github.event.inputs.mrt_target_id }}
92-
project_dir: "../generated-projects/${{ env.PROJECT_DIR }}"
92+
project_dir: "${{ steps.generate_app.outputs.project_path }}"
9393
mobify_user: ${{ secrets.MOBIFY_CLIENT_USER }}
9494
mobify_api_key: ${{ secrets.MOBIFY_CLIENT_API_KEY }}

e2e/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,13 @@ module.exports = {
104104
"retail-app-private-client": [],
105105
"retail-react-app-bug-bounty": [],
106106
"retail-react-app-demo-site": [],
107+
"retail-react-app-performance-tests": [],
107108
},
108109
PRESET: {
109110
"retail-app-private-client": "retail-react-app-private-slas-client",
110111
"retail-react-app-bug-bounty": "retail-react-app-bug-bounty",
111-
"retail-react-app-demo-site": "retail-react-app-demo-site-internal"
112+
"retail-react-app-demo-site": "retail-react-app-demo-site-internal",
113+
"retail-react-app-performance-tests": "retail-react-app-performance-tests"
112114
},
113115
EXPECTED_GENERATED_ARTIFACTS: {
114116
"retail-app-demo": [

e2e/scripts/generate-project.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ program
6969
'retail-app-no-ext',
7070
'retail-app-private-client',
7171
'retail-react-app-bug-bounty',
72-
'retail-react-app-demo-site'
72+
'retail-react-app-demo-site',
73+
'retail-react-app-performance-tests'
7374
]
7475
if (!validKeys.includes(value)) {
7576
throw new Error('Invalid project key.')

packages/pwa-kit-create-app/assets/bootstrap/js/config/default.js.hbs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ const {parseCommerceAgentSettings} = require('./utils.js')
1010

1111
module.exports = {
1212
app: {
13+
// Enable partial hydration capabilities via Island component
14+
{{#if answers.project.partialHydrationEnabled}}
15+
partialHydrationEnabled: {{answers.project.partialHydrationEnabled}},
16+
{{else}}
17+
partialHydrationEnabled: false,
18+
{{/if}}
1319
// Commerce shopping agent configuration for embedded messaging service
1420
// This enables an agentic shopping experience in the application
1521
// This property accepts either a JSON string or a plain JavaScript object.

0 commit comments

Comments
 (0)