Skip to content

Commit

Permalink
Merge pull request #1467 from SalesforceCommerceCloud/reusable-github…
Browse files Browse the repository at this point in the history
…-actions

@W-13578461@ GitHub actions for hybrid testing
  • Loading branch information
shethj authored Oct 23, 2023
2 parents 7c806c8 + 82fcd52 commit 6f91dc8
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/actions/create_mrt/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ inputs:
description: "Mobify user email"
mobify_api_key:
description: "Mobify user API key"
cwd:
required: false
default: ${PWD}
runs:
using: composite
steps:
- name: Create MRT credentials file
working-directory: ${{ inputs.cwd }}
run: |-
# Add credentials file at ~/.mobify so we can upload to Mobify Cloud
npm run save-credentials --prefix packages/template-retail-react-app -- --user "${{inputs.mobify_user}}" --key "${{inputs.mobify_api_key}}"
Expand Down
4 changes: 4 additions & 0 deletions .github/actions/e2e_generate_app/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ inputs:
description: Project key to specify project to generate ("retail-app-demo", "retail-app-ext" or "retail-app-no-ext")
required: true
type: string
cwd:
required: false
default: ${PWD}
runs:
using: composite
steps:
- name: Generate new project based on project-key
working-directory: ${{ inputs.cwd }}
run: node e2e/scripts/generate-project.js ${{ inputs.PROJECT_KEY }}
shell: bash
4 changes: 4 additions & 0 deletions .github/actions/e2e_validate_generated_app/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ inputs:
description: Project key to specify project to validate ("retail-app-demo", "retail-app-ext" or "retail-app-no-ext")
required: true
type: string
cwd:
required: false
default: ${PWD}
runs:
using: composite
steps:
- name: Validate generated project based on project-key
working-directory: ${{ inputs.cwd }}
run: node e2e/scripts/validate-generated-project.js ${{ inputs.PROJECT_KEY }}
shell: bash
2 changes: 2 additions & 0 deletions .github/actions/push_to_mrt/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ inputs:
description: Project directory
TARGET:
description: MRT target
FLAGS:
description: Push flags
runs:
using: composite
steps:
Expand Down
5 changes: 3 additions & 2 deletions .github/actions/setup_ubuntu/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ name: setup_ubuntu
inputs:
cwd:
required: false
default: "${PWD}"
default: ${{ github.workspace }}
description: "Setup Ubuntu Machine"
runs:
using: composite
steps:
- name: Install Dependencies
working-directory: ${{ inputs.cwd }}
run: |-
# Install system dependencies
sudo apt-get update -yq
Expand All @@ -28,7 +29,7 @@ runs:
npm run check-dep-version
# Install Snyk CLI
# TODO: Ticket W-12425059. Revisit Snyk CLI integration to monitor manifest files on generated projects.
# TODO: Ticket W-12425059. Revisit Snyk CLI integration to monitor manifest files on generated projects.
# TODO: Latest Snyk CLI version is currently failing on npm i. We use the alternative Snyk GitHub integration.
# sudo npm install -g snyk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

{{#if answers.project.hybrid}}
import React, { useEffect } from 'react'
import { withRouter } from 'react-router-dom'
{{else}}
import React from 'react'
{{/if}}
import loadable from '@loadable/component'
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'

Expand All @@ -18,20 +23,60 @@ const fallback = <Skeleton height="75vh" width="100%" />

// Create your pages here and add them to the routes array
// Use loadable to split code into smaller js chunks
{{#if answers.project.hybrid}}
const Home = loadable(() => import('@salesforce/retail-react-app/app/pages/home'), { fallback })
{{else}}
const Home = loadable(() => import('./pages/home'), {fallback})
{{/if}}
const MyNewRoute = loadable(() => import('./pages/my-new-route'))
{{#if answers.project.hybrid}}
const PageNotFound = loadable(() => import('@salesforce/retail-react-app/app/pages/page-not-found'))
{{/if}}

const routes = [
{
path: '/',
component: Home,
exact: true
},
{{#if answers.project.hybrid}}
{
path: '/home',
component: Home,
exact: true
},
{{/if}}
{
path: '/my-new-route',
component: MyNewRoute
},
{{#if answers.project.hybrid}}
// remove routes from the base template that we want to go to SFRA
..._routes.filter((route) => {
return !(route.path === '/cart' || route.path === '/checkout' || route.path === '*')
}),
{
path: '*',
component: withRouter((props) => {
const { location, history } = props
const urlParams = new URLSearchParams(location.search)

useEffect(() => {
const newURL = new URL(window.location)
if (!urlParams.has('redirected')) {
newURL.searchParams.append('redirected', '1')
window.location.href = newURL
}
}, [location.pathname])
if (urlParams.has('redirected')) {
return <PageNotFound {...props} />
}
return null
})
}
{{else}}
..._routes
{{/if}}
]

{{!-- export default routes --}}
Expand Down
44 changes: 44 additions & 0 deletions packages/pwa-kit-create-app/scripts/create-mobify-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@ const EXTENSIBILITY_QUESTIONS = [
}
]

const HYBRID_QUESTIONS = [
{
name: 'project.hybrid',
message: 'Do you wish to set up a phased headless rollout?',
type: 'list',
choices: [
{
name: 'No',
value: false
},
{
name: 'Yes',
value: true
}
]
}
]

const MRT_REFERENCE_QUESTIONS = [
{
name: 'project.name',
Expand Down Expand Up @@ -223,6 +241,7 @@ const PRESETS = [
questions: [...EXTENSIBILITY_QUESTIONS, ...RETAIL_REACT_APP_QUESTIONS],
answers: {
['project.extend']: true,
['project.hybrid']: false,
['project.name']: 'demo-storefront',
['project.commerce.instanceUrl']: 'https://zzte-053.dx.commercecloud.salesforce.com',
['project.commerce.clientId']: '1d763261-6522-4913-9d52-5d947d3b94c4',
Expand All @@ -246,6 +265,7 @@ const PRESETS = [
questions: [...EXTENSIBILITY_QUESTIONS, ...RETAIL_REACT_APP_QUESTIONS],
answers: {
['project.extend']: true,
['project.hybrid']: false,
['project.name']: 'retail-react-app',
['project.commerce.instanceUrl']: 'https://zzrf-001.dx.commercecloud.salesforce.com',
['project.commerce.clientId']: 'c9c45bfd-0ed3-4aa2-9971-40f88962b836',
Expand All @@ -258,6 +278,30 @@ const PRESETS = [
assets: ['translations'],
private: true
},
{
id: 'retail-react-app-hybrid-test-project',
name: 'Retail React App Hybrid Test Project',
description: '',
templateSource: {
type: TEMPLATE_SOURCE_NPM,
id: '@salesforce/retail-react-app'
},
questions: [...EXTENSIBILITY_QUESTIONS, ...HYBRID_QUESTIONS, ...RETAIL_REACT_APP_QUESTIONS],
answers: {
['project.extend']: true,
['project.hybrid']: true,
['project.name']: 'retail-react-app',
['project.commerce.instanceUrl']: 'https://test.phased-launch-testing.com/',
['project.commerce.clientId']: '50b359ea-4224-4125-b75d-dd80ff4b0f00',
['project.commerce.siteId']: 'RefArch',
['project.commerce.organizationId']: 'f_ecom_bdpx_dev',
['project.commerce.shortCode']: 'xitgmcd3',
['project.einstein.clientId']: '1ea06c6e-c936-4324-bcf0-fada93f83bb1',
['project.einstein.siteId']: 'aaij-MobileFirst'
},
assets: ['translations'],
private: true
},
{
id: 'typescript-minimal-test-project',
name: 'Template Minimal Test Project',
Expand Down
2 changes: 1 addition & 1 deletion packages/pwa-kit-dev/bin/pwa-kit-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ const main = async () => {
warnings.forEach(warn)
if (wait) {
success('Bundle Uploaded - waiting for deployment to complete')
await client.waitForDeploy()
await client.waitForDeploy(projectSlug, target)
} else {
success('Bundle Uploaded')
}
Expand Down

0 comments on commit 6f91dc8

Please sign in to comment.