|
| 1 | +name: build-and-test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + |
| 9 | +jobs: |
| 10 | + lint: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + - uses: actions/setup-node@v4 |
| 15 | + with: |
| 16 | + node-version: '20.19.0' |
| 17 | + cache: 'yarn' |
| 18 | + - run: corepack enable |
| 19 | + - run: yarn --immutable |
| 20 | + - run: yarn lint-no-fix |
| 21 | + |
| 22 | + typescript: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + - uses: actions/setup-node@v4 |
| 27 | + with: |
| 28 | + node-version: '20.19.0' |
| 29 | + cache: 'yarn' |
| 30 | + - run: corepack enable |
| 31 | + - run: yarn --immutable |
| 32 | + - run: yarn typescript |
| 33 | + |
| 34 | + unit-tests: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v4 |
| 38 | + - uses: actions/setup-node@v4 |
| 39 | + with: |
| 40 | + node-version: '20.19.0' |
| 41 | + cache: 'yarn' |
| 42 | + - run: corepack enable |
| 43 | + - run: yarn --immutable |
| 44 | + - uses: actions/cache@v4 |
| 45 | + with: |
| 46 | + path: ./cache/jest |
| 47 | + key: jest-cache-${{ github.ref_name }} |
| 48 | + restore-keys: jest-cache- |
| 49 | + - name: Run unit tests |
| 50 | + run: yarn test --maxWorkers=2 --coverage |
| 51 | + - uses: actions/upload-artifact@v4 |
| 52 | + if: always() |
| 53 | + with: |
| 54 | + name: coverage |
| 55 | + path: coverage |
| 56 | + |
| 57 | + build-package: |
| 58 | + runs-on: ubuntu-latest |
| 59 | + steps: |
| 60 | + - uses: actions/checkout@v4 |
| 61 | + - uses: actions/setup-node@v4 |
| 62 | + with: |
| 63 | + node-version: '20.19.0' |
| 64 | + cache: 'yarn' |
| 65 | + - run: corepack enable |
| 66 | + - run: yarn --immutable |
| 67 | + - name: Build package |
| 68 | + run: | |
| 69 | + yarn prepack |
| 70 | + node ./scripts/typescript-output-lint |
| 71 | +
|
| 72 | + build-docs: |
| 73 | + if: github.ref != 'refs/heads/main' |
| 74 | + runs-on: ubuntu-latest |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v4 |
| 77 | + - uses: actions/setup-node@v4 |
| 78 | + with: |
| 79 | + node-version: '20.19.0' |
| 80 | + cache: 'yarn' |
| 81 | + - run: corepack enable |
| 82 | + - run: yarn --immutable |
| 83 | + - name: Build docs |
| 84 | + run: yarn --cwd docs build |
| 85 | + - uses: actions/upload-artifact@v4 |
| 86 | + with: |
| 87 | + name: docs |
| 88 | + path: docs/build |
| 89 | + |
| 90 | + comment-artifacts: |
| 91 | + if: github.event_name == 'pull_request' |
| 92 | + needs: build-docs |
| 93 | + runs-on: ubuntu-latest |
| 94 | + permissions: |
| 95 | + pull-requests: write |
| 96 | + steps: |
| 97 | + - uses: actions/github-script@v7 |
| 98 | + with: |
| 99 | + script: | |
| 100 | + const artifactsUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/artifacts`; |
| 101 | + const body = `Hey @${context.payload.pull_request.user.login}, thank you for your pull request 🤗. The documentation from this branch can be viewed [here](${artifactsUrl}).`; |
| 102 | + const marker = 'The documentation from this branch can be viewed'; |
| 103 | +
|
| 104 | + const { data: comments } = await github.rest.issues.listComments({ |
| 105 | + owner: context.repo.owner, |
| 106 | + repo: context.repo.repo, |
| 107 | + issue_number: context.issue.number, |
| 108 | + }); |
| 109 | +
|
| 110 | + const existing = comments.find(c => c.body.includes(marker)); |
| 111 | +
|
| 112 | + if (existing) { |
| 113 | + await github.rest.issues.updateComment({ |
| 114 | + owner: context.repo.owner, |
| 115 | + repo: context.repo.repo, |
| 116 | + comment_id: existing.id, |
| 117 | + body, |
| 118 | + }); |
| 119 | + } else { |
| 120 | + await github.rest.issues.createComment({ |
| 121 | + owner: context.repo.owner, |
| 122 | + repo: context.repo.repo, |
| 123 | + issue_number: context.issue.number, |
| 124 | + body, |
| 125 | + }); |
| 126 | + } |
| 127 | +
|
| 128 | + deploy-docs: |
| 129 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 130 | + runs-on: ubuntu-latest |
| 131 | + steps: |
| 132 | + - uses: actions/checkout@v4 |
| 133 | + - uses: actions/setup-node@v4 |
| 134 | + with: |
| 135 | + node-version: '20.19.0' |
| 136 | + cache: 'yarn' |
| 137 | + - run: corepack enable |
| 138 | + - run: yarn --immutable |
| 139 | + - name: Build docs |
| 140 | + run: yarn --cwd docs build |
| 141 | + - name: Deploy to GitHub Pages |
| 142 | + uses: peaceiris/actions-gh-pages@v4 |
| 143 | + with: |
| 144 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 145 | + publish_dir: ./docs/build |
0 commit comments