Skip to content

Spartacus build pipeline #13665

Spartacus build pipeline

Spartacus build pipeline #13665

Workflow file for this run

on:
push:
branches:
- develop
- develop-*
- release-*
workflow_dispatch:
# empty as it is used only to manually trigger the workflow
env:
CYPRESS_KEY: ${{ secrets.CYPRESS_KEY }}
NODE_VERSION: '20'
AMP_API_TOKEN: ${{ secrets.AMP_API_TOKEN }}
CONTINUUM_REGISTRY_TOKEN: ${{ secrets.CONTINUUM_REGISTRY_TOKEN }}
concurrency:
group: ci-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
name: Spartacus build pipeline
jobs:
no_retries:
name: Verify re-run of all jobs
runs-on: ubuntu-latest
steps:
- name: Forcefully fail build if jobs are all retried
uses: actions/github-script@v7
with:
script: |
core.setFailed('Please push a commit to trigger the build. To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`')
if: ${{ github.run_attempt > 1 }}
validate_e2e_execution:
name: Validate pull_request files
runs-on: ubuntu-latest
outputs:
SHOULD_RUN_E2E: ${{ steps.save-e2e-output-result.outputs.SHOULD_RUN_E2E }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine whether to run e2es
id: save-e2e-output-result
run: |
source ci-scripts/validate-e2e-execution.sh
echo "::set-output name=SHOULD_RUN_E2E::$(echo $RUN_E2E)"
unit_tests:
needs: no_retries
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
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: Run unit tests
run: |
ci-scripts/unit-tests.sh
sonarqube_scan:
needs: no_retries
name: SonarQube Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
with:
args: >
-Dsonar.qualitygate.wait=true
-Dsonar.projectKey=composable-storefront
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: https://sonar.tools.sap
if: github.event_name == 'pull_request'
linting:
needs: no_retries
name: Validations and static code checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
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: Run linting validation
run: |
ci-scripts/validate-lint.sh
b2c_e2e_tests:
needs: [no_retries, validate_e2e_execution]
name: E2E tests for B2C
runs-on: ubuntu-latest
strategy:
matrix:
containers: [1, 2, 3, 4, 5]
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' }}
steps:
- name: Forcefully fail build if e2e job is retried
uses: actions/github-script@v7
with:
script: |
core.setFailed('Please push a commit to trigger the build. To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`')
if: ${{ github.run_attempt > 1 }}
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
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: Run e2es
env:
SPA_ENV: ci,b2c
BUILD_NUMBER: ci-build-number-${{ github.event.pull_request.head.sha || github.run_id }}
run: |
ci-scripts/e2e-cypress.sh
b2c_ssr_e2e_tests:
needs: [no_retries, validate_e2e_execution]
name: E2E tests for SSR B2C
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' }}
steps:
- name: Forcefully fail build if e2e job is retried
uses: actions/github-script@v7
with:
script: |
core.setFailed('Please push a commit to trigger the build. To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`')
if: ${{ github.run_attempt > 1 }}
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
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: Run e2es
env:
SPA_ENV: ci,b2c
BUILD_NUMBER: ci-build-number-${{ github.event.pull_request.head.sha || github.run_id }}
run: |
ci-scripts/e2e-cypress.sh --ssr
b2b_e2e_tests:
needs: [no_retries, validate_e2e_execution]
name: E2E tests for B2B
runs-on: ubuntu-latest
strategy:
matrix:
containers: [1, 2, 3, 4]
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' }}
steps:
- name: Forcefully fail build if e2e job is retried
uses: actions/github-script@v7
with:
script: |
core.setFailed('Please push a commit to trigger the build. To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`')
if: ${{ github.run_attempt > 1 }}
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
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: Run e2es
env:
SPA_ENV: ci,b2b
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@v4
- 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@v4
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, ssr_tests, sonarqube_scan]
name: Build Conclusion
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- name: Required build failed
uses: actions/github-script@v7
with:
script: |
core.setFailed('Build failed')
if: |
needs.no_retries.result == 'failure' || needs.no_retries.result == 'cancelled' ||
needs.unit_tests.result == 'failure' || needs.unit_tests.result == 'cancelled' ||
needs.sonarqube_scan.result == 'failure' || needs.sonarqube_scan.result == 'cancelled' ||
needs.linting.result == 'failure' || needs.linting.result == 'cancelled' ||
needs.b2c_e2e_tests.result == 'failure' || needs.b2c_e2e_tests.result == 'cancelled' ||
needs.b2c_ssr_e2e_tests.result == 'failure' || needs.b2c_ssr_e2e_tests.result == 'cancelled' ||
needs.b2b_e2e_tests.result == 'failure' || needs.b2b_e2e_tests.result == 'cancelled' ||
needs.ssr_tests.result == 'failure' || needs.ssr_tests.result == 'cancelled'
send_slack_message:
needs: build_conclusion
name: Slack message for failed CI build in Spartacus
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- run: |
echo "Context Info:"
echo " Event = ${{ github.event_name }}"
echo " Build Result = ${{ needs.build_conclusion.result }}"
echo " Branch = ${{ github.ref_name }}"
echo " Default branch = ${{ github.event.repository.default_branch }}"
- name: Notify the slack channel of when build conclusion failed
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }}
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_NOTIFICATION_CHANNEL }}
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":nuclear-bomb: :fireduck: *Broken build on ${{ github.ref_name }}*"
}
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Failed build",
"emoji": true
},
"value": "failed_build",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "What was committed?",
"emoji": true
},
"value": "recent_merged_commit",
"url": "${{ github.event.head_commit.url }}"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Build history",
"emoji": true
},
"value": "buid_history",
"url": "https://github.com/SAP/spartacus/actions/workflows/ci.yml?query=branch%3Adevelop"
}
]
}
]
}
if: |
needs.build_conclusion.result == 'failure' &&
github.event_name == 'push' &&
github.ref_name == github.event.repository.default_branch