|
| 1 | +name: Build pull request |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - "master" |
| 7 | + |
| 8 | +jobs: |
| 9 | + lint-pull-request: |
| 10 | + name: Lint pull request |
| 11 | + runs-on: ubuntu-20.04 |
| 12 | + strategy: |
| 13 | + fail-fast: true |
| 14 | + matrix: |
| 15 | + node: [18.x] |
| 16 | + steps: |
| 17 | + - name: Setup node v${{ matrix.node }} |
| 18 | + uses: actions/setup-node@v3 |
| 19 | + with: |
| 20 | + node-version: ${{ matrix.node }} |
| 21 | + |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v3 |
| 24 | + |
| 25 | + - name: Cache node_modules |
| 26 | + uses: actions/cache@v2 |
| 27 | + with: |
| 28 | + key: ${{ runner.os }}-node_modules-${{ matrix.node }}-${{ hashFiles('package.json') }} |
| 29 | + path: | |
| 30 | + node_modules |
| 31 | +
|
| 32 | + - name: Check if source or test files changed |
| 33 | + id: files_changed |
| 34 | + uses: tj-actions/[email protected] |
| 35 | + with: |
| 36 | + files: | |
| 37 | + src/**/* |
| 38 | + spec/**/* |
| 39 | +
|
| 40 | + - name: Install dependencies |
| 41 | + if: ${{ steps.files_changed.outputs.any_changed == 'true' || steps.files_changed.outputs.any_deleted == 'true' }} |
| 42 | + run: | |
| 43 | + yarn |
| 44 | +
|
| 45 | + - name: Lint files |
| 46 | + if: ${{ steps.files_changed.outputs.any_changed == 'true' || steps.files_changed.outputs.any_deleted == 'true' }} |
| 47 | + run: | |
| 48 | + yarn lint |
| 49 | +
|
| 50 | + build-and-test-pull-request: |
| 51 | + needs: |
| 52 | + - lint-pull-request |
| 53 | + name: Build and test pull request |
| 54 | + runs-on: ubuntu-20.04 |
| 55 | + strategy: |
| 56 | + fail-fast: true |
| 57 | + matrix: |
| 58 | + node: [14.x, 16.x, 18.x] |
| 59 | + module: [cjs, esm, umd] |
| 60 | + target: [es5, es2015, esnext] |
| 61 | + steps: |
| 62 | + - name: Setup node v${{ matrix.node }} |
| 63 | + uses: actions/setup-node@v3 |
| 64 | + with: |
| 65 | + node-version: ${{ matrix.node }} |
| 66 | + - name: Checkout |
| 67 | + uses: actions/checkout@v3 |
| 68 | + |
| 69 | + - name: Cache targets |
| 70 | + uses: actions/cache@v2 |
| 71 | + with: |
| 72 | + key: ${{ runner.os }}-targets-${{ matrix.node }}-${{ matrix.target }}-${{ matrix.module }}-${{ hashFiles('package.json') }} |
| 73 | + path: | |
| 74 | + targets |
| 75 | +
|
| 76 | + - name: Cache node_modules |
| 77 | + uses: actions/cache@v2 |
| 78 | + with: |
| 79 | + key: ${{ runner.os }}-node_modules-${{ matrix.node }}-${{ matrix.target }}-${{ matrix.module }}-${{ hashFiles('package.json') }} |
| 80 | + path: | |
| 81 | + node_modules |
| 82 | +
|
| 83 | + - name: Check if test files changed |
| 84 | + id: test_files_changed |
| 85 | + uses: tj-actions/[email protected] |
| 86 | + with: |
| 87 | + files: | |
| 88 | + spec/**/* |
| 89 | +
|
| 90 | + - name: Check if source files changed |
| 91 | + id: source_files_changed |
| 92 | + uses: tj-actions/[email protected] |
| 93 | + with: |
| 94 | + files: | |
| 95 | + src/**/* |
| 96 | +
|
| 97 | + - name: Install dependencies |
| 98 | + if: ${{ steps.test_files_changed.outputs.any_changed == 'true' || steps.test_files_changed.outputs.any_deleted == 'true' || steps.source_files_changed.outputs.any_changed == 'true' || steps.source_files_changed.outputs.any_deleted == 'true' }} |
| 99 | + run: | |
| 100 | + yarn |
| 101 | +
|
| 102 | + - name: Build package |
| 103 | + if: ${{ steps.source_files_changed.outputs.any_changed == 'true' || steps.source_files_changed.outputs.any_deleted == 'true' }} |
| 104 | + run: | |
| 105 | + yarn build -t ${{ matrix.target }} -m ${{ matrix.module }} |
| 106 | +
|
| 107 | + - name: Test package |
| 108 | + if: ${{ steps.test_files_changed.outputs.any_changed == 'true' || steps.test_files_changed.outputs.any_deleted == 'true' || steps.source_files_changed.outputs.any_changed == 'true' || steps.source_files_changed.outputs.any_deleted == 'true' }} |
| 109 | + run: | |
| 110 | + yarn test -t ${{ matrix.target }} -m ${{ matrix.module }} |
0 commit comments