|
1 | | -#This job tests changes made in main branch via PRs. |
| 1 | +# This job is to test different npm profiles in main branch against Pull Requests raised |
| 2 | +# This workflow targets jest-js |
| 3 | + |
| 4 | +name: Jest-js Test workflow for Node from workflow_dispatch |
2 | 5 |
|
3 | | -name: Review changes from PRs |
4 | | -run-name: ${{ github.actor }} has created/updated a PR |
5 | 6 | on: |
6 | | - pull_request: |
7 | | - branches: [ main ] |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + pull_request_number: |
| 10 | + description: 'The pull request number to build' |
| 11 | + required: true |
8 | 12 |
|
9 | 13 | jobs: |
10 | | - build: |
| 14 | + comment-run: |
| 15 | + runs-on: ${{ matrix.os }} |
11 | 16 | strategy: |
| 17 | + fail-fast: false |
| 18 | + max-parallel: 3 |
12 | 19 | matrix: |
13 | | - version: [ 14, 16, 18 ] |
| 20 | + node: ['14', '16', '18'] |
14 | 21 | os: [ macos-latest, windows-latest, ubuntu-latest ] |
15 | | - runs-on: ${{ matrix.os }} |
16 | | - name: JestJS repo ${{ matrix.version }} - ${{ matrix.os }} Sample |
| 22 | + name: Jest-js Repo ${{ matrix.node }} - ${{ matrix.os }} Sample |
17 | 23 | env: |
18 | 24 | BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} |
19 | 25 | BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} |
20 | 26 |
|
21 | 27 | steps: |
22 | 28 | - uses: actions/checkout@v3 |
23 | | - - uses: actions/setup-node@v3 |
24 | 29 | with: |
25 | | - node-version: ${{ matrix.version }} |
26 | | - |
27 | | - - name: Setup environment for testing |
| 30 | + ref: refs/pull/${{ github.event.inputs.pull_request_number }}/head |
| 31 | + - name: Fetch Commit SHA |
| 32 | + run: | |
| 33 | + git log -1 --format='%H' |
| 34 | + echo "commit_sha=$(git log -1 --format='%H')" >> $GITHUB_ENV |
| 35 | + echo "commit_sha=$(git log -1 --format='%H')" >> $env:GITHUB_ENV |
| 36 | + - uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 |
| 37 | + id: status-check-in-progress |
| 38 | + env: |
| 39 | + job_name: Jest-js Repo ${{ matrix.node }} - ${{ matrix.os }} Sample |
| 40 | + with: |
| 41 | + github-token: ${{ github.token }} |
| 42 | + script: | |
| 43 | + const result = await github.rest.checks.create({ |
| 44 | + owner: context.repo.owner, |
| 45 | + repo: context.repo.repo, |
| 46 | + name: process.env.job_name, |
| 47 | + head_sha: process.env.commit_sha, |
| 48 | + status: 'in_progress' |
| 49 | + }).catch((err) => ({status: err.status, response: err.response})); |
| 50 | + console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`) |
| 51 | + if (result.status !== 201) { |
| 52 | + console.log('Failed to create check run') |
| 53 | + } |
| 54 | + - name: Setup node |
| 55 | + uses: actions/setup-node@v3 |
| 56 | + with: |
| 57 | + node-version: ${{ matrix.node }} |
| 58 | + |
| 59 | + - name: Install dependencies |
28 | 60 | run: npm install |
29 | 61 |
|
30 | 62 | - name: Run sample tests |
31 | 63 | run: npm run sample-test |
32 | 64 |
|
33 | 65 | - name: Run local tests |
34 | 66 | run: npm run sample-local-test |
| 67 | + |
| 68 | + - if: always() |
| 69 | + uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 |
| 70 | + id: status-check-completed |
| 71 | + env: |
| 72 | + conclusion: ${{ job.status }} |
| 73 | + job_name: Jest-js Repo ${{ matrix.node }} - ${{ matrix.os }} Sample |
| 74 | + with: |
| 75 | + github-token: ${{ github.token }} |
| 76 | + script: | |
| 77 | + const result = await github.rest.checks.create({ |
| 78 | + owner: context.repo.owner, |
| 79 | + repo: context.repo.repo, |
| 80 | + name: process.env.job_name, |
| 81 | + head_sha: process.env.commit_sha, |
| 82 | + status: 'completed', |
| 83 | + conclusion: process.env.conclusion |
| 84 | + }).catch((err) => ({status: err.status, response: err.response})); |
| 85 | + console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`) |
| 86 | + if (result.status !== 201) { |
| 87 | + console.log('Failed to create check run') |
| 88 | + } |
0 commit comments