diff --git a/.github/actions/detect-changes/action.yml b/.github/actions/detect-changes/action.yml new file mode 100644 index 00000000000..8b72402e801 --- /dev/null +++ b/.github/actions/detect-changes/action.yml @@ -0,0 +1,40 @@ +name: Detect Changes +description: Determines whether code-related files (not docs-only) have changed in a PR +outputs: + RUN_CHECKS: + description: 'true if code files changed, false if only docs/*.md changed' + value: ${{ steps.detect.outputs.RUN_CHECKS }} +runs: + using: composite + steps: + - name: Check for code changes + id: detect + uses: actions/github-script@v7 + with: + script: | + if (!context.payload.pull_request) { + core.setOutput('RUN_CHECKS', 'true'); + return; + } + + const files = await github.paginate(github.rest.pulls.listFiles, { + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + per_page: 100, + }); + + const skipRunPatterns = [/^docs\//, /\.md$/]; + + const shouldRun = files.some((file) => { + const filename = file.filename; + return !skipRunPatterns.some((pattern) => pattern.test(filename)); + }); + + if (!shouldRun) { + core.info('⏭️ Skip checks: only docs & md files changed'); + } else { + core.info('✅ Running checks: code-related files changed'); + } + + core.setOutput('RUN_CHECKS', shouldRun ? 'true' : 'false'); diff --git a/.github/workflows/breaking-changes-detection-bot.yml b/.github/workflows/breaking-changes-detection-bot.yml index b4cee9d2427..0dc6462b06e 100644 --- a/.github/workflows/breaking-changes-detection-bot.yml +++ b/.github/workflows/breaking-changes-detection-bot.yml @@ -1,14 +1,24 @@ on: pull_request: types: [opened, synchronize, reopened] - paths-ignore: - - '**.md' - - 'docs/**' name: API extractor jobs: + detect_changes: + name: API extractor - Detect changes + runs-on: ubuntu-latest + outputs: + RUN_CHECKS: ${{ steps.detect_code_changes.outputs.RUN_CHECKS }} + steps: + - uses: actions/checkout@v6 + - name: Detect code changes + id: detect_code_changes + uses: ./.github/actions/detect-changes + breakingChangeDetectionBot: + needs: [detect_changes] name: Breaking change detection bot runs-on: ubuntu-latest + if: ${{ needs.detect_changes.outputs.RUN_CHECKS == 'true' }} steps: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.12.1 diff --git a/.github/workflows/cache-builded-libs.yml b/.github/workflows/cache-builded-libs.yml index 269a2a1bddd..2711eefb400 100644 --- a/.github/workflows/cache-builded-libs.yml +++ b/.github/workflows/cache-builded-libs.yml @@ -5,14 +5,24 @@ on: - develop-* - 'epic/**' - release/* - paths-ignore: - - '**.md' - - 'docs/**' name: Cache libs (dist) jobs: + detect_changes: + name: Cache libs - Detect changes + runs-on: ubuntu-latest + outputs: + RUN_CHECKS: ${{ steps.detect_code_changes.outputs.RUN_CHECKS }} + steps: + - uses: actions/checkout@v6 + - name: Detect code changes + id: detect_code_changes + uses: ./.github/actions/detect-changes + cacheBuildedLibs: + needs: [detect_changes] name: Builded libs runs-on: ubuntu-latest + if: ${{ needs.detect_changes.outputs.RUN_CHECKS == 'true' }} steps: - uses: actions/checkout@master - name: Cache builded libs diff --git a/.github/workflows/cache-node-modules.yml b/.github/workflows/cache-node-modules.yml index 554885ef4e6..c43f381a249 100644 --- a/.github/workflows/cache-node-modules.yml +++ b/.github/workflows/cache-node-modules.yml @@ -5,9 +5,6 @@ on: - develop-* - 'epic/**' - release/* - paths-ignore: - - '**.md' - - 'docs/**' name: Cache node modules env: @@ -15,9 +12,22 @@ env: CONTINUUM_REGISTRY_TOKEN: ${{ secrets.CONTINUUM_REGISTRY_TOKEN }} jobs: + detect_changes: + name: Cache node modules - Detect changes + runs-on: ubuntu-latest + outputs: + RUN_CHECKS: ${{ steps.detect_code_changes.outputs.RUN_CHECKS }} + steps: + - uses: actions/checkout@v6 + - name: Detect code changes + id: detect_code_changes + uses: ./.github/actions/detect-changes + cacheNodeModules: + needs: [detect_changes] name: Cache node_modules runs-on: ubuntu-latest + if: ${{ needs.detect_changes.outputs.RUN_CHECKS == 'true' }} steps: - uses: actions/checkout@v6 - name: Setup node diff --git a/.github/workflows/ci-continuous-integration.yml b/.github/workflows/ci-continuous-integration.yml index 808faf1ea2d..f0e82ed4418 100644 --- a/.github/workflows/ci-continuous-integration.yml +++ b/.github/workflows/ci-continuous-integration.yml @@ -6,9 +6,6 @@ on: - develop-* - release/* - epic/** - paths-ignore: - - '**.md' - - 'docs/**' workflow_dispatch: # empty as it is used only to manually trigger the workflow @@ -23,9 +20,22 @@ concurrency: name: Continuous Integration jobs: + detect_changes: + name: CI - Detect changes + runs-on: ubuntu-latest + outputs: + RUN_CI_CHECKS: ${{ steps.detect_code_changes.outputs.RUN_CHECKS }} + steps: + - uses: actions/checkout@v6 + - name: Detect code changes + id: detect_code_changes + uses: ./.github/actions/detect-changes + unit_tests: + needs: [detect_changes] name: CI - Unit tests runs-on: ubuntu-latest + if: ${{ needs.detect_changes.outputs.RUN_CI_CHECKS == 'true' }} steps: - uses: actions/checkout@v6 with: @@ -50,6 +60,7 @@ jobs: run: | ci-scripts/unit-tests.sh sonarqube_scan: + needs: [detect_changes] name: CI - SonarQube Scan runs-on: ubuntu-latest steps: @@ -66,10 +77,12 @@ jobs: env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: https://sonar.tools.sap - if: github.event_name == 'pull_request' + if: ${{ github.event_name == 'pull_request' && needs.detect_changes.outputs.RUN_CI_CHECKS == 'true' }} linting: + needs: [detect_changes] name: CI - Validations and static code checks runs-on: ubuntu-latest + if: ${{ needs.detect_changes.outputs.RUN_CI_CHECKS == 'true' }} steps: - uses: actions/checkout@v6 - name: Setup node @@ -92,8 +105,10 @@ jobs: run: | ci-scripts/validate-lint.sh check_peer_dependencies: + needs: [detect_changes] name: CI - Check peerDependencies runs-on: ubuntu-latest + if: ${{ needs.detect_changes.outputs.RUN_CI_CHECKS == 'true' }} steps: - uses: actions/checkout@v6 with: diff --git a/.github/workflows/ci-merge-checks.yml b/.github/workflows/ci-merge-checks.yml index eeb7c9a55cd..a3231fa5c1e 100644 --- a/.github/workflows/ci-merge-checks.yml +++ b/.github/workflows/ci-merge-checks.yml @@ -5,9 +5,6 @@ on: - develop - develop-* - release/* - paths-ignore: - - '**.md' - - 'docs/**' workflow_dispatch: # empty as it is used only to manually trigger the workflow @@ -25,6 +22,17 @@ concurrency: name: Merge Checks jobs: + detect_changes: + name: MC - Detect changes + runs-on: ubuntu-latest + outputs: + RUN_E2E_BY_CHANGES: ${{ steps.detect_code_changes.outputs.RUN_CHECKS }} + steps: + - uses: actions/checkout@v6 + - name: Detect code changes + id: detect_code_changes + uses: ./.github/actions/detect-changes + no_retries: name: MC - Prevent retries # E2Es can't be retried. Moreover, in some retry cases, they don't run @@ -134,13 +142,13 @@ jobs: dist/storefrontapp key: spartacus-app-${{ matrix.cache_key }}-${{ matrix.build_type }}-${{ github.event.pull_request.head.sha || github.run_id }} b2c_e2e_tests: - needs: [no_retries, validate_e2e_execution, build_apps] + needs: [detect_changes, no_retries, validate_e2e_execution, build_apps] name: MC - E2E B2C core runs-on: ubuntu-latest strategy: matrix: containers: [1, 2, 3, 4, 5] - if: ${{ needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' }} + if: ${{ needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' && needs.detect_changes.outputs.RUN_E2E_BY_CHANGES == 'true' }} steps: - uses: actions/checkout@v6 - name: E2E Test Setup @@ -156,10 +164,10 @@ jobs: BUILD_NUMBER: ci-build-number-${{ github.event.pull_request.head.sha || github.run_id }} run: ci-scripts/e2e-cypress.sh --skip-build b2c_ssr_e2e_tests: - needs: [no_retries, validate_e2e_execution, build_apps] + needs: [detect_changes, no_retries, validate_e2e_execution, build_apps] name: MC - E2E SSR core (B2C) runs-on: ubuntu-latest - if: ${{ needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' }} + if: ${{ needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' && needs.detect_changes.outputs.RUN_E2E_BY_CHANGES == 'true' }} steps: - uses: actions/checkout@v6 - name: E2E Test Setup @@ -175,13 +183,13 @@ jobs: BUILD_NUMBER: ci-build-number-${{ github.event.pull_request.head.sha || github.run_id }} run: ci-scripts/e2e-cypress.sh --skip-build --ssr b2b_e2e_tests: - needs: [no_retries, validate_e2e_execution, build_apps] + needs: [detect_changes, no_retries, validate_e2e_execution, build_apps] name: MC - E2E B2B core runs-on: ubuntu-latest strategy: matrix: containers: [1, 2, 3, 4] - if: ${{ needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' }} + if: ${{ needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' && needs.detect_changes.outputs.RUN_E2E_BY_CHANGES == 'true' }} steps: - uses: actions/checkout@v6 - name: E2E Test Setup @@ -197,13 +205,13 @@ jobs: BUILD_NUMBER: ci-build-number-${{ github.event.pull_request.head.sha || github.run_id }} run: ci-scripts/e2e-cypress.sh -s b2b --skip-build a11y_e2e_tests: - needs: [no_retries, validate_e2e_execution, build_apps] + needs: [detect_changes, no_retries, validate_e2e_execution, build_apps] name: MC - E2E A11Y runs-on: ubuntu-latest strategy: matrix: containers: [1, 2, 3] - if: ${{ needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' }} + if: ${{ needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' && needs.detect_changes.outputs.RUN_E2E_BY_CHANGES == 'true' }} steps: - uses: actions/checkout@v6 - name: E2E Test Setup diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b75a311cd86..e70ad481728 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,9 +4,6 @@ on: - develop - develop-* - release/* - paths-ignore: - - "**.md" - - "docs/**" workflow_dispatch: # empty as it is used only to manually trigger the workflow. @@ -23,16 +20,31 @@ concurrency: name: Spartacus build pipeline jobs: + detect_changes: + name: CI - Detect changes + runs-on: ubuntu-latest + outputs: + RUN_CHECKS: ${{ steps.detect_code_changes.outputs.RUN_CHECKS }} + steps: + - uses: actions/checkout@v6 + - name: Detect code changes + id: detect_code_changes + uses: ./.github/actions/detect-changes + no_retries: + needs: [detect_changes] name: Verify re-run of all jobs runs-on: ubuntu-latest + if: ${{ needs.detect_changes.outputs.RUN_CHECKS == 'true' }} steps: - uses: actions/checkout@v6 - name: Prevent retries uses: ./.github/actions/prevent-retries validate_e2e_execution: + needs: [detect_changes] name: Validate pull_request files runs-on: ubuntu-latest + if: ${{ needs.detect_changes.outputs.RUN_CHECKS == 'true' }} outputs: SHOULD_RUN_E2E: ${{ steps.save-e2e-output-result.outputs.SHOULD_RUN_E2E }} steps: diff --git a/.github/workflows/config-check.yml b/.github/workflows/config-check.yml index 785f507a865..d3adf1197b7 100644 --- a/.github/workflows/config-check.yml +++ b/.github/workflows/config-check.yml @@ -2,27 +2,51 @@ on: pull_request: types: [opened, synchronize, reopened] - paths-ignore: - - '**.md' - - 'docs/**' - name: Config check jobs: configCheck: name: Dependencies and tsconfig files runs-on: ubuntu-latest steps: + - name: Detect whether config check should run + id: detect_changes + uses: actions/github-script@v7 + with: + script: | + const files = await github.paginate(github.rest.pulls.listFiles, { + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + per_page: 100, + }); + + const shouldRun = files.some((file) => { + const filename = file.filename; + return !filename.startsWith('docs/') && !filename.endsWith('.md'); + }); + + core.setOutput('run_config_check', shouldRun ? 'true' : 'false'); + + - name: Skip config check for docs-only changes + if: ${{ steps.detect_changes.outputs.run_config_check != 'true' }} + run: echo 'Skipping config check because PR changes only markdown/docs files.' + - name: Cancel Previous Runs + if: ${{ steps.detect_changes.outputs.run_config_check == 'true' }} uses: styfle/cancel-workflow-action@0.12.1 with: access_token: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/checkout@master - - uses: actions/setup-node@v4 + - if: ${{ steps.detect_changes.outputs.run_config_check == 'true' }} + uses: actions/checkout@master + - if: ${{ steps.detect_changes.outputs.run_config_check == 'true' }} + uses: actions/setup-node@v4 with: node-version: '20' - name: NPM + if: ${{ steps.detect_changes.outputs.run_config_check == 'true' }} run: npm i - name: Check configurations + if: ${{ steps.detect_changes.outputs.run_config_check == 'true' }} run: npm run config:check env: FORCE_COLOR: 2 # Support colors from chalk diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index 85caf797956..0582387f95c 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -6,16 +6,25 @@ on: - 'develop' - 'develop-*' - paths-ignore: - - '**.md' - - 'docs/**' - name: Installation jobs: + detect_changes: + name: Installation - Detect changes + runs-on: ubuntu-latest + outputs: + RUN_CHECKS: ${{ steps.detect_code_changes.outputs.RUN_CHECKS }} + steps: + - uses: actions/checkout@v6 + - name: Detect code changes + id: detect_code_changes + uses: ./.github/actions/detect-changes + install: + needs: [detect_changes] name: Build libs and install environment: dev runs-on: ubuntu-latest + if: ${{ needs.detect_changes.outputs.RUN_CHECKS == 'true' }} steps: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.12.1 diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 367d04ac8bd..4fca8f8a675 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -6,10 +6,6 @@ on: - develop-* - release/* - paths-ignore: - - '**.md' - - 'docs/**' - workflow_dispatch: # empty as it is used only to manually trigger the workflow env: @@ -22,9 +18,22 @@ concurrency: name: Lighthouse jobs: + detect_changes: + name: Lighthouse - Detect changes + runs-on: ubuntu-latest + outputs: + RUN_CHECKS: ${{ steps.detect_code_changes.outputs.RUN_CHECKS }} + steps: + - uses: actions/checkout@v6 + - name: Detect code changes + id: detect_code_changes + uses: ./.github/actions/detect-changes + lighthouse: + needs: [detect_changes] name: Lighthouse score validation runs-on: ubuntu-latest + if: ${{ needs.detect_changes.outputs.RUN_CHECKS == 'true' }} steps: - uses: actions/checkout@v6 - name: Setup node diff --git a/.github/workflows/prepend-license.yml b/.github/workflows/prepend-license.yml index 3f79af2e59a..e6bb44fa2b2 100644 --- a/.github/workflows/prepend-license.yml +++ b/.github/workflows/prepend-license.yml @@ -2,15 +2,24 @@ on: pull_request: types: [opened, synchronize] - paths-ignore: - - '**.md' - - 'docs/**' - name: Add license header to files jobs: + detect_changes: + name: Add license - Detect changes + runs-on: ubuntu-latest + outputs: + RUN_CHECKS: ${{ steps.detect_code_changes.outputs.RUN_CHECKS }} + steps: + - uses: actions/checkout@v6 + - name: Detect code changes + id: detect_code_changes + uses: ./.github/actions/detect-changes + add_license_header: + needs: [detect_changes] name: Add license header to files runs-on: ubuntu-latest + if: ${{ needs.detect_changes.outputs.RUN_CHECKS == 'true' }} steps: - uses: actions/checkout@v6 with: