Skip to content

Commit

Permalink
Merge branch 'epic/ssr-error-handling' into feat/CXSPA-6940
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelfras committed Sep 5, 2024
2 parents f16b8e1 + 7eba698 commit 62d6137
Show file tree
Hide file tree
Showing 953 changed files with 31,034 additions and 4,522 deletions.
2 changes: 1 addition & 1 deletion .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2
update_configs:
- package_manager: "javascript"
directory: "/"
Expand Down
11 changes: 10 additions & 1 deletion .env-cmdrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"CX_BASE_URL": "https://api.cp96avkh5f-integrati1-d1-public.model-t.cc.commerce.ondemand.com"
},
"cpq": {
"CX_BASE_URL": "https://api.cpce-teamtiger1-d2-public.model-t.cc.commerce.ondemand.com",
"CX_BASE_URL": "https://api.cg79x9wuu9-eccommerc1-s1-public.model-t.myhybris.cloud/",
"CX_B2B": "true",
"CX_CPQ": "true"
},
Expand All @@ -55,6 +55,10 @@
"CX_REQUESTED_DELIVERY_DATE": "true",
"CX_PDF_INVOICES": "true"
},
"omf":{
"CX_BASE_URL": "https://api.cg79x9wuu9-eccommerc1-s9-public.model-t.myhybris.cloud",
"CX_OMF": "true"
},
"requested-delivery-date": {
"CX_BASE_URL": "https://api.cg79x9wuu9-eccommerc1-s8-public.model-t.myhybris.cloud",
"CX_REQUESTED_DELIVERY_DATE": "true"
Expand All @@ -81,5 +85,10 @@
"opps":{
"CX_BASE_URL": "https://api.cg79x9wuu9-eccommerc1-s5-public.model-t.myhybris.cloud",
"CX_OPPS": "true"
},
"s4-service":{
"CX_BASE_URL": "https://api.cg79x9wuu9-eccommerc1-s1-public.model-t.myhybris.cloud",
"CX_S4_SERVICE": "true",
"CX_B2B": "true"
}
}
27 changes: 0 additions & 27 deletions .github/workflows/ci-continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,6 @@ jobs:
- name: Run unit tests
run: |
ci-scripts/unit-tests.sh
build-libs:
# TODO: For Testing SSR Epic only, remove job before merge
name: CI - Build Libraries
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: |
node_modules
projects/storefrontapp-e2e-cypress/node_modules
~/.cache/Cypress
key: nodemodules-${{ github.event.pull_request.base.sha }}
restore-keys: nodemodules-${{ github.event.pull_request.base.sha }}
- name: Package installation
run: npm ci
- name: Build Libraries
run: |
npm run build:libs
sonarqube_scan:
name: CI - SonarQube Scan
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-merge-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ jobs:
run: |
ci-scripts/e2e-cypress.sh -s b2b
merge_checks_result:
needs: [b2c_e2e_tests, b2c_ssr_e2e_tests, b2b_e2e_tests]
needs: [b2c_e2e_tests, b2c_ssr_e2e_tests, b2b_e2e_tests, ssr_tests]
name: MC - Result
runs-on: ubuntu-latest
if: ${{ always() }}
Expand Down
28 changes: 26 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,32 @@ jobs:
BUILD_NUMBER: ci-build-number-${{ github.event.pull_request.head.sha || github.run_id }}
run: |
ci-scripts/e2e-cypress.sh -s b2b
ssr_tests:
needs: [no_retries, validate_e2e_execution]
name: SSR Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: |
node_modules
key: nodemodules-${{ github.event.pull_request.base.sha }}
restore-keys: nodemodules-${{ github.event.pull_request.base.sha }}
- name: Package installation
run: npm ci
- name: Build SSR Server
run: npm run build:libs && npm run build && npm run build:ssr:local-http-backend
- name: Run SSR tests
run: npm run test:ssr:ci --verbose
build_conclusion:
needs: [no_retries, unit_tests, linting, b2c_e2e_tests, b2c_ssr_e2e_tests, b2b_e2e_tests, sonarqube_scan]
needs: [no_retries, unit_tests, linting, b2c_e2e_tests, b2c_ssr_e2e_tests, b2b_e2e_tests, ssr_tests, sonarqube_scan]
name: Build Conclusion
runs-on: ubuntu-latest
if: ${{ always() }}
Expand Down Expand Up @@ -250,7 +274,7 @@ jobs:
- name: Notify the slack channel of when build conclusion failed
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }}
uses: slackapi/slack-github-action@v1.24.0
uses: slackapi/slack-github-action@v1.26.0
with:
channel-id: ${{ secrets.SLACK_NOTIFICATION_CHANNEL }}
payload: |
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ on:
schedule:
- cron: '45 2 * * *'


jobs:
analyze:
name: Analyze (${{ matrix.language }})

# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
Expand Down Expand Up @@ -62,6 +64,13 @@ jobs:
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
config: |
name: Disable scan for tests
paths-ignore:
- "projects/storefrontapp-e2e-cypress/**"
- "**/*.spec.ts"
- "**/*.spec.js"
- "**/*_spec.ts"
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand Down
156 changes: 156 additions & 0 deletions .github/workflows/update-cloud-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: Update Cloud Commerce Repository
on:
workflow_dispatch:
inputs:
version:
description: 'Enter the version to use'
required: true
npm_token:
description: 'Enter your npm token'
required: true
secret: true

env:
CONFIG_DIR: scripts/install
REPO_URL: https://${{secrets.GH_TEMPORARY_TOKEN}}@github.com/SAP-samples/cloud-commerce-sample-setup.git
NPM_REPO_URL: https://73554900100900004337.dev.npmsrv.base.repositories.cloud.sap/
OCC_BACKEND_URL: OCC_BACKEND_BASE_URL_VALUE

jobs:
run_script:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Create storefronts
run: |
function setup_config_dir() {
[ -d "${CONFIG_DIR}" ]
cp "${CONFIG_DIR}/config.default.sh" "${CONFIG_DIR}/config.sh"
}
function update_config() {
local storefront_type=$1
local version=${{ github.event.inputs.version }}
local npm_token=${{ github.event.inputs.npm_token }}
# Update configuration values
if [ "${storefront_type}" == "b2c" ]; then
sed -i 's/^BASE_SITE=.*/BASE_SITE="electronics-spa"/' "${CONFIG_DIR}/config.sh"
sed -i 's/^SSR_APP_NAME=.*/SSR_APP_NAME="spartacusstore"/' "${CONFIG_DIR}/config.sh"
elif [ "${storefront_type}" == "b2b" ]; then
sed -i 's/^BASE_SITE=.*/BASE_SITE="powertools-spa"/' "${CONFIG_DIR}/config.sh"
sed -i 's/^SSR_APP_NAME=.*/SSR_APP_NAME="b2bspastore"/' "${CONFIG_DIR}/config.sh"
sed -i '/ADD_B2B_LIBS/c\ADD_B2B_LIBS=true' "${CONFIG_DIR}/config.sh"
else
echo "Invalid storefront type. BASE_SITE and SSR_APP_NAME not set."
fi
sed -i 's/^BACKEND_URL=.*/BACKEND_URL="'${OCC_BACKEND_URL}'"/' "${CONFIG_DIR}/config.sh"
sed -i "s/^SPARTACUS_VERSION=.*/SPARTACUS_VERSION='${version}'/" "${CONFIG_DIR}/config.sh"
sed -i "s/^NPM_TOKEN=.*/NPM_TOKEN='${npm_token}'/" "${CONFIG_DIR}/config.sh"
sed -i "s|^NPM_URL=.*|NPM_URL='${NPM_REPO_URL}'|" "${CONFIG_DIR}/config.sh"
}
# Rename the generated spartacus folders so we can have B2C and B2B folders
function rename_spartacus_folders() {
local version=${{ github.event.inputs.version }}
if [ "${storefront_type}" == "b2c" ]; then
mv ../spartacus-${version} ../spartacus-${version}-b2c
if [ -d "../spartacus-${version}-b2c" ]; then
echo "Renaming to ../spartacus-${version}-b2c was successful"
else
echo "Renaming to ../spartacus-${version}-b2c failed"
exit 1
fi
elif [ "${storefront_type}" == "b2b" ]; then
mv ../spartacus-${version} ../spartacus-${version}-b2b
if [ -d "../spartacus-${version}-b2b" ]; then
echo "Renaming to ../spartacus-${version}-b2b was successful"
else
echo "Renaming to ../spartacus-${version}-b2b failed"
exit 1
fi
fi
}
# Comment out the base url in the spartacus-configuration.module.ts file
function modify_file_to_remove_baseurl() {
local path
if [ "${storefront_type}" == "b2c" ]; then
path="spartacusstore"
elif [ "${storefront_type}" == "b2b" ]; then
path="b2bspastore"
else
echo "Invalid storefront type: ${storefront_type}"
exit 1
fi
local file_location="../spartacus-${{ github.event.inputs.version }}-${storefront_type}/apps/${path}/src/app/spartacus/spartacus-configuration.module.ts"
if [ -f "${file_location}" ]; then
sed -i 's/baseUrl/\/\/baseUrl/1' "${file_location}"
echo "Modified ${file_location}."
else
echo "${file_location} does not exist."
exit 1
fi
}
storefront_types=("b2c" "b2b")
# Loop over storefront types
for storefront_type in "${storefront_types[@]}"; do
setup_config_dir
update_config $storefront_type
cd "${CONFIG_DIR}" && bash "./run.sh" install_npm
cd ../../
rename_spartacus_folders $storefront_type
modify_file_to_remove_baseurl $storefront_type
done
- name: Set Git user
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Commit changes
run: |
function clone_and_setup_repo() {
git clone $REPO_URL
cd cloud-commerce-sample-setup
# Get the current date and time
timestamp=$(date +%Y%m%d%H%M%S)
# Create a new branch with a unique name
branch_name="update_storefronts_$timestamp"
git checkout -b $branch_name
# Copy over the B2C and B2B content to the js-storefront folder and then commit the changes
rm -rf js-storefront/spartacusstore/*
cp -r ./../../spartacus-${{ github.event.inputs.version }}-b2c/apps/spartacusstore/* js-storefront/spartacusstore/
git add .
git commit -m "Updated content of js-storefront/spartacusstore"
rm -rf js-storefront/b2bspastore/*
cp -r ./../../spartacus-${{ github.event.inputs.version }}-b2b/apps/b2bspastore/* js-storefront/b2bspastore/
git add .
git commit -m "Updated content of js-storefront/b2bspastore"
git push -u $REPO_URL
}
clone_and_setup_repo
# Echo the branch name so it can be used in later steps
echo "branch_name=$branch_name" >> $GITHUB_ENV
- name: Create Pull Request
run: |
curl -X POST -H "Authorization: token ${{ secrets.GH_TEMPORARY_TOKEN }}" -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/SAP-samples/cloud-commerce-sample-setup/pulls \
-d '{
"title": "Update js-storefronts content",
"body": "This PR updates the content of the js-storefronts.",
"head": "'"$branch_name"'",
"base": "main"
}'
4 changes: 2 additions & 2 deletions ci-scripts/e2e-cypress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ if [[ "${SSR}" = true ]]; then
if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then
if [[ "${GITHUB_HEAD_REF}" == epic/* ]]; then
npm run e2e:run:ci:ssr
else
else
npm run e2e:run:ci:core:ssr
fi
else
Expand All @@ -106,7 +106,7 @@ else
if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then
if [[ "${GITHUB_HEAD_REF}" == epic/* ]]; then
npm run e2e:run:ci"${SUITE}"
else
else
npm run e2e:run:ci:core"${SUITE}"
fi
else
Expand Down
10 changes: 5 additions & 5 deletions core-libs/setup/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spartacus/setup",
"version": "2211.25.1",
"version": "2211.28.0-1",
"description": "Includes features that makes Spartacus and it's setup easier and streamlined.",
"keywords": [
"spartacus",
Expand All @@ -21,10 +21,10 @@
"peerDependencies": {
"@angular/core": "^17.0.5",
"@angular/ssr": "^17.0.5",
"@spartacus/cart": "2211.25.1",
"@spartacus/core": "2211.25.1",
"@spartacus/order": "2211.25.1",
"@spartacus/user": "2211.25.1"
"@spartacus/cart": "2211.28.0-1",
"@spartacus/core": "2211.28.0-1",
"@spartacus/order": "2211.28.0-1",
"@spartacus/user": "2211.28.0-1"
},
"optionalDependencies": {
"@angular/platform-server": "^17.0.5",
Expand Down
4 changes: 2 additions & 2 deletions core-libs/setup/ssr/engine/cx-common-engine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('CxCommonEngine', () => {
});

// Cannot use `.toMatchInlineSnapshot()` due to bug in jest:
// see: https://github.com/thymikee/jest-preset-angular/issues/1084ń
// see: https://github.com/thymikee/jest-preset-angular/issues/1084
await expect(
engine.render({
url: 'http://localhost:4200',
Expand All @@ -119,7 +119,7 @@ describe('CxCommonEngine', () => {
});

// Cannot use `.toMatchInlineSnapshot()` due to bug in jest:
// see: https://github.com/thymikee/jest-preset-angular/issues/1084ń
// see: https://github.com/thymikee/jest-preset-angular/issues/1084
await expect(
engine.render({
url: 'http://localhost:4200',
Expand Down
9 changes: 8 additions & 1 deletion core-libs/setup/ssr/engine/cx-common-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
import { PROPAGATE_ERROR_TO_SERVER } from '../error-handling/error-response/propagate-error-to-server';

/**
* The Spartacus extension of the CommonEngine introduced to handle propagated server responses caught during server-side rendering.
* The Spartacus extension of the Angular's `CommonEngine`. It is able to handle the propagated server responses caught during server-side rendering of a Spartacus app.
* For reference, see Angular's source code: https://github.com/angular/angular-cli/blob/6cf866225ab09f8b4b3803c000b632bed8448ce4/packages/angular/ssr/src/common-engine.ts#L56
*
* @extends {CommonEngine}
*/
export class CxCommonEngine extends CommonEngine {
Expand All @@ -26,6 +28,11 @@ export class CxCommonEngine extends CommonEngine {
* If an error is populated from the rendered applications
* (via `PROPAGATE_ERROR_TO_SERVER` callback), then such an error
* will be thrown and the result promise rejected - but only AFTER the rendering is complete.
* In other words, at first an error occurs and it's captured, then we wait until the rendering completes
* and ONLY then we reject the promise with the payload being the encountered error.
*
* Note: if more errors are captured during the rendering, only the first one will be used
* as the payload of the rejected promise, others won't.
*
* @param {CommonEngineRenderOptions} options - The options to render.
* @returns {Promise<string>} Promise which resolves with the rendered HTML as a string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { ErrorRequestHandler } from 'express';
* @param documentContent The document content to be sent to the client.
* @returns The error request handler.
*/
//EXPRESS JS ERROR HANDLER
export const defaultExpressErrorHandlers =
(documentContent: string): ErrorRequestHandler =>
(err, _req, res, _next) => {
Expand Down
Loading

0 comments on commit 62d6137

Please sign in to comment.