Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Updated CI to skip expensive actions when not needed #2184

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 62 additions & 6 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ env:
OUTPUT_MODE: quiet

jobs:
should_run:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
javascript_changed: ${{ steps.filter.output.javascript }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
javascript:
- '**/*.js'
- '**/*.json'
- '**/*.mjs'
- '**/*.cjs'

skip_if_release:
runs-on: ubuntu-latest

Expand All @@ -22,8 +40,11 @@ jobs:
do_not_skip: '["workflow_dispatch", "pull_request"]'

lint:
needs: skip_if_release
needs:
- skip_if_release
- should_run
if: needs.skip_if_release.outputs.should_skip != 'true'
&& needs.should_run.outputs.javascript_changed == 'true'
runs-on: ubuntu-latest

strategy:
Expand All @@ -44,8 +65,11 @@ jobs:
run: npm run lint:lockfile

ci:
needs: skip_if_release
needs:
- skip_if_release
- should_run
if: needs.skip_if_release.outputs.should_skip != 'true'
&& needs.should_run.outputs.javascript_changed == 'true'
runs-on: ubuntu-latest

strategy:
Expand All @@ -65,8 +89,11 @@ jobs:
run: npm run unit:scripts

unit:
needs: skip_if_release
needs:
- skip_if_release
- should_run
if: needs.skip_if_release.outputs.should_skip != 'true'
&& needs.should_run.outputs.javascript_changed == 'true'
runs-on: ubuntu-latest

strategy:
Expand All @@ -89,9 +116,13 @@ jobs:
with:
name: unit-tests-${{ matrix.node-version }}
path: ./coverage/unit/lcov.info

integration:
needs: skip_if_release
needs:
- skip_if_release
- should_run
if: needs.skip_if_release.outputs.should_skip != 'true'
&& needs.should_run.outputs.javascript_changed == 'true'
runs-on: ubuntu-latest

env:
Expand Down Expand Up @@ -128,8 +159,11 @@ jobs:
path: ./coverage/integration-esm/lcov.info

versioned-internal:
needs: skip_if_release
needs:
- skip_if_release
- should_run
if: needs.skip_if_release.outputs.should_skip != 'true'
&& needs.should_run.outputs.javascript_changed == 'true'
runs-on: ${{ github.ref == 'refs/heads/main' && vars.NR_RUNNER || 'ubuntu-latest' }}

strategy:
Expand Down Expand Up @@ -176,8 +210,11 @@ jobs:

# There is no coverage for external as that's tracked in their respective repos
versioned-external:
needs: skip_if_release
needs:
- skip_if_release
- should_run
if: needs.skip_if_release.outputs.should_skip != 'true'
&& needs.should_run.outputs.javascript_changed == 'true'
runs-on: ${{ github.ref == 'refs/heads/main' && vars.NR_RUNNER || 'ubuntu-latest' }}

strategy:
Expand All @@ -199,6 +236,7 @@ jobs:
VERSIONED_MODE: ${{ github.ref == 'refs/heads/main' && '--minor' || '--major' }}
# Run more jobs when using larger runner, otherwise 2 per CPU seems to be the sweet spot in GHA default runners(July 2022)
JOBS: ${{ github.ref == 'refs/heads/main' && vars.NR_RUNNER && 16 || 4 }}

codecov:
needs: [unit, integration, versioned-internal]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -229,3 +267,21 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
directory: versioned-tests-${{ matrix.node-version }}
flags: versioned-tests-${{ matrix.node-version }}

all-clear:
if: always()
runs-on: ubuntu-latest
needs:
- lint
- ci
- unit
- integration
- versioned-internal
- versioned-external
steps:
- name: All checks passed
if: ${{ !(contains(needs.*.result, 'failure')) }}
run: exit 0
- name: Some checks failed
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1