|
| 1 | +name: JavaScript Unit Tests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [trunk] |
| 6 | + push: |
| 7 | + branches: [trunk] |
| 8 | + # Allow manually triggering the workflow |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +# Cancels all previous workflow runs for pull requests that have not completed |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +# Disable permissions for all available scopes by default |
| 17 | +permissions: {} |
| 18 | + |
| 19 | +jobs: |
| 20 | + unit-js: |
| 21 | + name: Node.js ${{ matrix.node }} |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + contents: read |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + matrix: |
| 28 | + event: ['${{ github.event_name }}'] |
| 29 | + node: ['20', '22', '24'] |
| 30 | + exclude: |
| 31 | + # On PRs: only test minimum supported version |
| 32 | + - event: 'pull_request' |
| 33 | + node: '22' |
| 34 | + - event: 'pull_request' |
| 35 | + node: '24' |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout repository |
| 39 | + uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + show-progress: false |
| 42 | + persist-credentials: false |
| 43 | + |
| 44 | + - name: Setup Node.js and install dependencies |
| 45 | + uses: actions/setup-node@v4 |
| 46 | + with: |
| 47 | + node-version: ${{ matrix.node }} |
| 48 | + cache: 'npm' |
| 49 | + |
| 50 | + - name: Install dependencies |
| 51 | + run: npm ci |
| 52 | + |
| 53 | + - name: Run unit tests |
| 54 | + run: npm run test:unit -- --ci --coverage |
| 55 | + |
| 56 | + - name: Upload coverage to Codecov |
| 57 | + if: always() |
| 58 | + uses: codecov/codecov-action@v5 |
| 59 | + with: |
| 60 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 61 | + files: ./coverage/unit/lcov.info |
| 62 | + flags: javascript |
| 63 | + slug: WordPress/secure-custom-fields |
| 64 | + name: unit-js-node-${{ matrix.node }} |
| 65 | + fail_ci_if_error: false |
0 commit comments