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**
This commit is contained in:
Nikolay Vitkov 2023-01-19 13:53:43 +01:00 committed by GitHub
parent 6847f8835f
commit db6085df65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,11 +39,11 @@ jobs:
run: npm run commitlint run: npm run commitlint
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request'
check-docs: check-changes:
name: Check documentation name: Check which packages changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
needs_deploying: ${{ steps.needs_deploying.outputs.value }} changes: ${{ steps.changes.outputs.changes }}
steps: steps:
- name: Check out repository - name: Check out repository
uses: actions/checkout@v3.1.0 uses: actions/checkout@v3.1.0
@ -58,6 +58,26 @@ jobs:
run: npm ci --ignore-scripts run: npm ci --ignore-scripts
- name: Build - name: Build
run: npm run docs 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 - name: Check if autogenerated docs differ
run: | run: |
diff_file=$(mktemp doc_diff_XXXXXX) diff_file=$(mktemp doc_diff_XXXXXX)
@ -69,20 +89,11 @@ jobs:
exit 1 exit 1
fi fi
rm $diff_file 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: deploy-docs:
needs: check-docs needs: check-changes
name: Deploy docs (if needed) 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 runs-on: ubuntu-latest
permissions: permissions:
contents: write contents: write
@ -121,6 +132,8 @@ jobs:
chrome-tests: chrome-tests:
name: ${{ matrix.suite }} tests on ${{ matrix.os }} name: ${{ matrix.suite }} tests on ${{ matrix.os }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
needs: check-changes
if: ${{ contains(fromJSON(needs.check-changes.outputs.changes), 'puppeteer') }}
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
@ -167,9 +180,21 @@ jobs:
if: ${{ matrix.os == 'ubuntu-latest' }} if: ${{ matrix.os == 'ubuntu-latest' }}
run: xvfb-run --auto-servernum npm run test -- --test-suite ${{ matrix.suite }} 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: firefox-tests:
name: ${{ matrix.suite }} tests on ${{ matrix.os }} name: ${{ matrix.suite }} tests on ${{ matrix.os }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
needs: check-changes
if: ${{ contains(fromJSON(needs.check-changes.outputs.changes), 'puppeteer') }}
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
@ -213,10 +238,21 @@ jobs:
if: ${{ matrix.os == 'ubuntu-latest' }} if: ${{ matrix.os == 'ubuntu-latest' }}
run: xvfb-run --auto-servernum npm run test -- --test-suite ${{ matrix.suite }} 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: installation-test-build:
name: Build installation test name: Build installation test
runs-on: ubuntu-latest 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: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
@ -240,6 +276,7 @@ jobs:
installation-test: installation-test:
name: Test ${{ matrix.pkg_manager }} installation on ${{ matrix.os }} (${{ matrix.node }}) name: Test ${{ matrix.pkg_manager }} installation on ${{ matrix.os }} (${{ matrix.node }})
needs: installation-test-build needs: installation-test-build
if: ${{ !startsWith(github.ref_name, 'release-please') }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
fail-fast: false fail-fast: false
@ -279,9 +316,21 @@ jobs:
PKG_MANAGER: ${{ matrix.pkg_manager }} PKG_MANAGER: ${{ matrix.pkg_manager }}
run: ${{ matrix.pkg_manager }} test 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: docker-tests:
name: Test Docker image name: Test Docker image
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: check-changes
if: ${{ contains(fromJSON(needs.check-changes.outputs.changes), 'puppeteer') }}
steps: steps:
- name: Check out repository - name: Check out repository
uses: actions/checkout@v3.0.2 uses: actions/checkout@v3.0.2
@ -310,6 +359,8 @@ jobs:
ng-schematics-tests: ng-schematics-tests:
name: Test Angular Schematics name: Test Angular Schematics
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: check-changes
if: ${{ contains(fromJSON(needs.check-changes.outputs.changes), 'ng-schematics') }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3