From db6085df650fa3b9f35c18b94e5c94f544636d94 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Thu, 19 Jan 2023 13:53:43 +0100 Subject: [PATCH] chore: Run Test only when necessary (#9538) **What kind of change does this PR introduce?** CI change **Did you add tests for your changes?** N/A **If relevant, did you update the documentation?** **Summary** We want to run our test only when relevant parts of the code are changed. Example change to `ng-schematics` should not trigger `puppeteer` test. **Does this PR introduce a breaking change?** No **Other information** --- .github/workflows/ci.yml | 81 ++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a1215a86ea..f68c8d35634 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,11 +39,11 @@ jobs: run: npm run commitlint if: github.event_name != 'pull_request' - check-docs: - name: Check documentation + check-changes: + name: Check which packages changed runs-on: ubuntu-latest outputs: - needs_deploying: ${{ steps.needs_deploying.outputs.value }} + changes: ${{ steps.changes.outputs.changes }} steps: - name: Check out repository uses: actions/checkout@v3.1.0 @@ -58,6 +58,26 @@ jobs: run: npm ci --ignore-scripts - name: Build run: npm run docs + - name: Detect changed packages + uses: dorny/paths-filter@v2.11.1 + id: changes + with: + filters: | + puppeteer: + - '.github/workflows/ci.yml' + - 'packages/puppeteer/**' + - 'packages/puppeteer-core/**' + - 'docker/**' + - 'test/**' + - 'test-d/**' + - 'tools/mochaRunner/**' + website: + - '.github/workflows/ci.yml' + - 'docs/**' + - 'website/**' + ng-schematics: + - '.github/workflows/ci.yml' + - 'packages/ng-schematics/**' - name: Check if autogenerated docs differ run: | diff_file=$(mktemp doc_diff_XXXXXX) @@ -69,20 +89,11 @@ jobs: exit 1 fi rm $diff_file - - name: Check if docs need to be deployed - id: needs_deploying - run: | - if [[ $(git diff HEAD^ -- ./docs ./website) ]]; then - needs_deploying=true - else - needs_deploying=false - fi - echo "value=$needs_deploying" >> $GITHUB_OUTPUT deploy-docs: - needs: check-docs + needs: check-changes name: Deploy docs (if needed) - if: ${{ needs.check-docs.outputs.needs_deploying == 'true' && github.event_name != 'pull_request' }} + if: ${{ github.event_name != 'pull_request' && contains(fromJSON(needs.check-changes.outputs.changes), 'website') }} runs-on: ubuntu-latest permissions: contents: write @@ -121,6 +132,8 @@ jobs: chrome-tests: name: ${{ matrix.suite }} tests on ${{ matrix.os }} runs-on: ${{ matrix.os }} + needs: check-changes + if: ${{ contains(fromJSON(needs.check-changes.outputs.changes), 'puppeteer') }} strategy: fail-fast: false matrix: @@ -167,9 +180,21 @@ jobs: if: ${{ matrix.os == 'ubuntu-latest' }} run: xvfb-run --auto-servernum npm run test -- --test-suite ${{ matrix.suite }} + chrome-tests-required: + name: Chrome tests required job + needs: [check-changes, chrome-tests] + runs-on: ubuntu-latest + if: ${{ always() }} + steps: + - if: ${{ needs.chrome-tests.result != 'success' && contains(fromJSON(needs.check-changes.outputs.changes), 'puppeteer') }} + run: 'exit 1' + - run: 'exit 0' + firefox-tests: name: ${{ matrix.suite }} tests on ${{ matrix.os }} runs-on: ${{ matrix.os }} + needs: check-changes + if: ${{ contains(fromJSON(needs.check-changes.outputs.changes), 'puppeteer') }} strategy: fail-fast: false matrix: @@ -213,10 +238,21 @@ jobs: if: ${{ matrix.os == 'ubuntu-latest' }} run: xvfb-run --auto-servernum npm run test -- --test-suite ${{ matrix.suite }} + firefox-tests-required: + name: Firefox tests required job + needs: [check-changes, firefox-tests] + runs-on: ubuntu-latest + if: ${{ always() }} + steps: + - if: ${{ needs.firefox-tests.result != 'success' && contains(fromJSON(needs.check-changes.outputs.changes), 'puppeteer') }} + run: 'exit 1' + - run: 'exit 0' + installation-test-build: name: Build installation test runs-on: ubuntu-latest - if: "!startsWith(github.ref_name, 'release-please')" + needs: check-changes + if: ${{ !startsWith(github.ref_name, 'release-please') && contains(fromJSON(needs.check-changes.outputs.changes), 'puppeteer') }} steps: - name: Checkout uses: actions/checkout@v3 @@ -240,6 +276,7 @@ jobs: installation-test: name: Test ${{ matrix.pkg_manager }} installation on ${{ matrix.os }} (${{ matrix.node }}) needs: installation-test-build + if: ${{ !startsWith(github.ref_name, 'release-please') }} runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -279,9 +316,21 @@ jobs: PKG_MANAGER: ${{ matrix.pkg_manager }} run: ${{ matrix.pkg_manager }} test + installation-test-required: + name: Installation tests required job + needs: [check-changes, installation-test] + runs-on: ubuntu-latest + if: ${{ always() }} + steps: + - if: ${{ needs.installation-test.result != 'success' && contains(fromJSON(needs.check-changes.outputs.changes), 'puppeteer') }} + run: 'exit 1' + - run: 'exit 0' + docker-tests: name: Test Docker image runs-on: ubuntu-latest + needs: check-changes + if: ${{ contains(fromJSON(needs.check-changes.outputs.changes), 'puppeteer') }} steps: - name: Check out repository uses: actions/checkout@v3.0.2 @@ -310,6 +359,8 @@ jobs: ng-schematics-tests: name: Test Angular Schematics runs-on: ubuntu-latest + needs: check-changes + if: ${{ contains(fromJSON(needs.check-changes.outputs.changes), 'ng-schematics') }} steps: - name: Checkout uses: actions/checkout@v3