From 4208f09e9d22a8900ffb761c782e166d5bd6a83b Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 24 Nov 2024 16:40:00 +0530 Subject: [PATCH] chore: enhance GitHub workflows with path filtering for builds and tests --- .github/workflows/build.yaml | 34 ++++++++++++++++++++++++++++++---- .github/workflows/tests.yaml | 24 +++++++++++++++++++++--- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1e1ccdd..6c951b9 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -5,10 +5,34 @@ on: branches: [main] pull_request: branches: [main] + workflow_dispatch: jobs: + changes: + runs-on: ubuntu-latest + outputs: + root: ${{ steps.filter.outputs.root }} + playground: ${{ steps.filter.outputs.playground }} + docs: ${{ steps.filter.outputs.docs }} + steps: + - uses: actions/checkout@v3 + - uses: dorny/paths-filter@v2 + id: filter + with: + filters: | + root: + - '!{playground,docs}/**' + - '*.{ts,tsx,js,jsx,json}' + - 'package.json' + - 'tsconfig.json' + playground: + - 'playground/**' + docs: + - 'docs/**' + build-root: - if: github.workspace == '.' + needs: changes + if: ${{ needs.changes.outputs.root == 'true' }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -18,9 +42,10 @@ jobs: cache: 'npm' - run: npm ci - run: npm run build - + build-playground: - if: contains(github.event.head_commit.modified, 'playground/') || contains(github.event.pull_request.changed_files, 'playground/') + needs: changes + if: ${{ needs.changes.outputs.playground == 'true' }} runs-on: ubuntu-latest defaults: run: @@ -36,7 +61,8 @@ jobs: - run: npm run build build-docs: - if: contains(github.event.head_commit.modified, 'docs/') || contains(github.event.pull_request.changed_files, 'docs/') + needs: changes + if: ${{ needs.changes.outputs.docs == 'true' }} runs-on: ubuntu-latest defaults: run: diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 1daafb1..0d0feff 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -5,10 +5,28 @@ on: branches: [main] pull_request: branches: [main] + workflow_dispatch: jobs: - test: - if: github.workspace == '.' + changes: + runs-on: ubuntu-latest + outputs: + root: ${{ steps.filter.outputs.root }} + steps: + - uses: actions/checkout@v3 + - uses: dorny/paths-filter@v2 + id: filter + with: + filters: | + root: + - '!{playground,docs}/**' + - '*.{ts,tsx,js,jsx,json}' + - 'package.json' + - 'tsconfig.json' + + test-root: + needs: changes + if: ${{ needs.changes.outputs.root == 'true' }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -17,4 +35,4 @@ jobs: node-version: '18' cache: 'npm' - run: npm ci - - run: npm run test \ No newline at end of file + - run: npm test \ No newline at end of file