Skip to content

Commit ebf46dd

Browse files
authored
Merge pull request #2383 from SalesforceCommerceCloud/bugifx/ci-stale-template
@W-18405621@ - [Bugfix] Fix E2E CI generates apps with released package versions instead of local-dev versions.
2 parents 3753674 + aa383bd commit ebf46dd

File tree

5 files changed

+94
-29
lines changed

5 files changed

+94
-29
lines changed

.github/actions/e2e_generate_app/action.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@ inputs:
44
description: Project key to specify project to generate ("retail-app-demo", "retail-app-ext" or "retail-app-no-ext")
55
required: true
66
type: string
7+
8+
TEMPLATE_VERSION:
9+
description: Version of the template to use for the project
10+
required: false
11+
type: string
12+
713
runs:
814
using: composite
915
steps:
1016
- name: Generate new project based on project-key
11-
run: node e2e/scripts/generate-project.js --project-key ${{ inputs.PROJECT_KEY }}
17+
run: |
18+
COMMAND="node e2e/scripts/generate-project.js --project-key ${{ inputs.PROJECT_KEY }}"
19+
if [[ -n "${{ inputs.TEMPLATE_VERSION }}" ]]; then
20+
COMMAND="$COMMAND --templateVersion ${{ inputs.TEMPLATE_VERSION }}"
21+
fi
22+
$COMMAND
1223
shell: bash

.github/actions/e2e_validate_generated_app/action.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ inputs:
44
description: Project key to specify project to validate ("retail-app-demo", "retail-app-ext" or "retail-app-no-ext")
55
required: true
66
type: string
7+
8+
TEMPLATE_VERSION:
9+
description: Version of the template to use for the project
10+
required: true
11+
type: string
712
runs:
813
using: composite
914
steps:
10-
- name: Validate generated project based on project-key
11-
run: node e2e/scripts/validate-generated-project.js ${{ inputs.PROJECT_KEY }}
15+
- name: Validate generated project
16+
run: |
17+
COMMAND="node e2e/scripts/validate-generated-project.js ${{ inputs.PROJECT_KEY }}"
18+
if [[ -n "${{ inputs.TEMPLATE_VERSION }}" ]]; then
19+
COMMAND="$COMMAND --templateVersion ${{ inputs.TEMPLATE_VERSION }}"
20+
fi
21+
$COMMAND
1222
shell: bash

.github/workflows/e2e.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,23 @@ jobs:
106106
107107
# Check the installed version of @playwright/test
108108
echo "@playwright/test version: $(npm list @playwright/test --depth=0)"
109+
110+
- name: Get Template Version
111+
run: |-
112+
version=`jq -r ".version" packages/template-retail-react-app/package.json`
113+
echo "retail_app_template_version=$version" >> "$GITHUB_ENV"
109114
110115
- name: Generate Retail App Without Extensibility
111116
uses: ./.github/actions/e2e_generate_app
112117
with:
113118
PROJECT_KEY: "retail-app-no-ext"
114-
119+
TEMPLATE_VERSION: ${{ env.retail_app_template_version }}
120+
115121
- name: Validate Retail App Without Extensibility
116122
uses: ./.github/actions/e2e_validate_generated_app
117123
with:
118124
PROJECT_KEY: "retail-app-no-ext"
125+
TEMPLATE_VERSION: ${{ env.retail_app_template_version }}
119126

120127
- name: Create MRT credentials file
121128
uses: "./.github/actions/create_mrt"
@@ -213,15 +220,22 @@ jobs:
213220
# Check the installed version of @playwright/test
214221
echo "@playwright/test version: $(npm list @playwright/test --depth=0)"
215222
223+
- name: Get Template Version
224+
run: |-
225+
version=`jq -r ".version" packages/template-retail-react-app/package.json`
226+
echo "retail_app_template_version=$version" >> "$GITHUB_ENV"
227+
216228
- name: Generate Retail App With Extensibility
217229
uses: ./.github/actions/e2e_generate_app
218230
with:
219231
PROJECT_KEY: "retail-app-ext"
232+
TEMPLATE_VERSION: ${{ env.retail_app_template_version }}
220233

221234
- name: Validated Generated Retail App Demo
222235
uses: ./.github/actions/e2e_validate_generated_app
223236
with:
224237
PROJECT_KEY: "retail-app-ext"
238+
TEMPLATE_VERSION: ${{ env.retail_app_template_version }}
225239

226240
- name: Create MRT credentials file
227241
uses: "./.github/actions/create_mrt"
@@ -316,10 +330,22 @@ jobs:
316330
# Check the installed version of @playwright/test
317331
echo "@playwright/test version: $(npm list @playwright/test --depth=0)"
318332
333+
- name: Get Template Version
334+
run: |-
335+
version=`jq -r ".version" packages/template-retail-react-app/package.json`
336+
echo "retail_app_template_version=$version" >> "$GITHUB_ENV"
337+
319338
- name: Generate Retail App Private Client
320339
uses: ./.github/actions/e2e_generate_app
321340
with:
322341
PROJECT_KEY: "retail-app-private-client"
342+
TEMPLATE_VERSION: ${{ env.retail_app_template_version }}
343+
344+
- name: Validate Generated Retail App Private Client
345+
uses: ./.github/actions/e2e_validate_generated_app
346+
with:
347+
PROJECT_KEY: "retail-app-private-client"
348+
TEMPLATE_VERSION: ${{ env.retail_app_template_version }}
323349

324350
- name: Create MRT credentials file
325351
uses: "./.github/actions/create_mrt"

e2e/scripts/generate-project.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const {program} = require('commander')
1010
const {mkdirIfNotExists} = require('./utils.js')
1111

1212
const main = async (opts) => {
13-
const {projectKey, projectConfig} = opts
13+
const {projectKey, projectConfig, templateVersion} = opts
1414

1515
if (!projectKey && !projectConfig) {
1616
console.error('You must provide either <project-key> or <project-config>.')
@@ -44,6 +44,11 @@ const main = async (opts) => {
4444
if (preset) {
4545
generateAppCommand = `${config.GENERATOR_CMD} ${outputDir} --preset ${preset}`
4646
}
47+
48+
if (templateVersion) {
49+
generateAppCommand = `${generateAppCommand} --templateVersion ${templateVersion}`
50+
}
51+
console.log('Running command:', generateAppCommand)
4752
return await runGeneratorWithResponses(generateAppCommand, cliResponses)
4853
} catch (err) {
4954
// Generator failed to create project
@@ -78,6 +83,7 @@ program
7883
throw new Error('Invalid JSON string.')
7984
}
8085
})
86+
.option('--templateVersion <templateVersion>', 'Template version used to generate the project')
8187
.action((options) => {
8288
// Call the main function with parsed options
8389
main(options)

e2e/scripts/validate-generated-project.js

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ const config = require('../config.js')
1212
const path = require('path')
1313

1414
const validateGeneratedArtifacts = async (project) => {
15-
const generatedProjectDirPath = path.join(process.cwd(), config.GENERATED_PROJECTS_DIR, project)
16-
const generatedArtifacts = await fs.readdirSync(generatedProjectDirPath)
15+
try {
16+
const generatedProjectDirPath = path.join(process.cwd(), config.GENERATED_PROJECTS_DIR, project)
17+
const generatedArtifacts = fs.readdirSync(generatedProjectDirPath)
1718

1819
return new Promise((resolve, reject) => {
1920
const missingArtifacts = diffArrays(
@@ -25,31 +26,40 @@ const validateGeneratedArtifacts = async (project) => {
2526
`Generated project (${project}) is missing one or more artifacts: ${missingArtifacts}`
2627
)
2728
} else {
28-
resolve(`Successfully validated generated artifacts for: ${project} `)
29-
}
30-
})
29+
resolve(`Successfully validated generated artifacts for: ${project} `)
30+
}
31+
})
32+
} catch (err) {
33+
reject(`Generated project (${project}) is missing one or more artifacts: ${err}`)
34+
}
3135
}
3236

33-
const validateExtensibilityConfig = async (project) => {
37+
const validateExtensibilityConfig = async (project, templateVersion) => {
3438
const pkgPath = path.join(process.cwd(), config.GENERATED_PROJECTS_DIR, project, 'package.json')
3539
const pkg = require(pkgPath)
3640
return new Promise((resolve, reject) => {
3741
if (
38-
pkg.hasOwnProperty('ccExtensibility') &&
39-
pkg['ccExtensibility'].hasOwnProperty('extends') &&
40-
pkg['ccExtensibility'].hasOwnProperty('overridesDir') &&
41-
pkg['ccExtensibility'].extends === '@salesforce/retail-react-app' &&
42-
pkg['ccExtensibility'].overridesDir === 'overrides'
42+
!pkg.hasOwnProperty('ccExtensibility') ||
43+
!pkg['ccExtensibility'].hasOwnProperty('extends') ||
44+
!pkg['ccExtensibility'].hasOwnProperty('overridesDir') ||
45+
!pkg['ccExtensibility'].extends === '@salesforce/retail-react-app' ||
46+
!pkg['ccExtensibility'].overridesDir === 'overrides'
4347
) {
44-
resolve(`Successfully validated extensibility config for ${project}`)
48+
reject(`Generated project ${project} is missing extensibility config in package.json`)
4549
}
46-
reject(`Generated project ${project} is missing extensibility config in package.json`)
50+
51+
if (templateVersion && pkg.version !== templateVersion) {
52+
reject(
53+
`Generated project ${project} is using an incorrect template version. Expected ${templateVersion}, but got ${pkg.version}.`
54+
)
55+
}
56+
resolve(`Successfully validated extensibility config for ${project}`)
4757
})
4858
}
4959

5060
const main = async (opts) => {
5161
const {args} = opts
52-
const [project] = args
62+
const [project, templateVersion] = args
5363
if (opts.args.length !== 1) {
5464
console.log(program.helpInformation())
5565
process.exit(1)
@@ -58,22 +68,24 @@ const main = async (opts) => {
5868
try {
5969
console.log(await validateGeneratedArtifacts(project))
6070
if (project === 'retail-app-ext' || project === 'retail-app-ext') {
61-
console.log(await validateExtensibilityConfig(project))
71+
console.log(await validateExtensibilityConfig(project, templateVersion))
6272
}
6373
} catch (err) {
6474
console.error(err)
6575
}
6676
}
6777

68-
program.description(`Validate project generated by generator using the key <project-key>`)
69-
70-
program.addArgument(
71-
new Argument('<project-key>', 'project key').choices([
72-
'retail-app-demo',
73-
'retail-app-ext',
74-
'retail-app-no-ext'
75-
])
76-
)
78+
program
79+
.description(`Validate project generated by generator using the key <project-key>`)
80+
.addArgument(
81+
new Argument('<project-key>', 'project key').choices([
82+
'retail-app-demo',
83+
'retail-app-ext',
84+
'retail-app-no-ext',
85+
'retail-app-private-client'
86+
])
87+
)
88+
.option('--templateVersion <templateVersion>', 'Template version used to generate the project')
7789

7890
program.parse(process.argv)
7991

0 commit comments

Comments
 (0)