|
| 1 | +name: Pull Request |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + types: |
| 8 | + - opened |
| 9 | + - reopened |
| 10 | + - synchronize |
| 11 | + - closed |
| 12 | + - ready_for_review |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +# Prevent concurrent builds for the same PR |
| 18 | +concurrency: |
| 19 | + group: pr-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + # Run code quality checks |
| 24 | + code-checks: |
| 25 | + name: Code Quality (${{ matrix.check }}) |
| 26 | + runs-on: ubuntu-latest |
| 27 | + if: github.event.action != 'closed' && github.actor != 'dependabot[bot]' && github.event.pull_request.draft == false |
| 28 | + strategy: |
| 29 | + fail-fast: false |
| 30 | + matrix: |
| 31 | + include: |
| 32 | + - check: format |
| 33 | + command: npm run format:check |
| 34 | + - check: lint |
| 35 | + command: npm run lint |
| 36 | + - check: types |
| 37 | + command: npm run typecheck |
| 38 | + - check: audit |
| 39 | + command: npm audit |
| 40 | + continue-on-error: true |
| 41 | + - check: circular-deps |
| 42 | + command: npx madge --circular . --extensions ts,js,jsx,tsx |
| 43 | + permissions: |
| 44 | + contents: read |
| 45 | + steps: |
| 46 | + - name: Checkout repository |
| 47 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 48 | + with: |
| 49 | + lfs: false |
| 50 | + fetch-depth: 2 |
| 51 | + |
| 52 | + - name: Setup dependencies |
| 53 | + uses: ./.github/actions/setup-and-build |
| 54 | + with: |
| 55 | + build: 'false' |
| 56 | + |
| 57 | + - name: Run ${{ matrix.check }} |
| 58 | + run: ${{ matrix.command }} |
| 59 | + continue-on-error: ${{ matrix.continue-on-error || false }} |
| 60 | + |
| 61 | + # Check markdown links |
| 62 | + markdown-link-check: |
| 63 | + name: Check Documentation Links (${{ matrix.extension }}) |
| 64 | + runs-on: ubuntu-latest |
| 65 | + if: github.event.action != 'closed' && github.actor != 'dependabot[bot]' && github.event.pull_request.draft == false |
| 66 | + strategy: |
| 67 | + fail-fast: true |
| 68 | + matrix: |
| 69 | + extension: ['.md', '.mdx'] |
| 70 | + permissions: |
| 71 | + contents: read |
| 72 | + steps: |
| 73 | + - name: Checkout repository |
| 74 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 75 | + with: |
| 76 | + fetch-depth: 1 |
| 77 | + lfs: false |
| 78 | + |
| 79 | + - name: Check Markdown links (${{ matrix.extension }}) |
| 80 | + uses: tcort/github-action-markdown-link-check@a800ad5f1c35bf61987946fd31c15726a1c9f2ba # v1.1.0 |
| 81 | + continue-on-error: true |
| 82 | + with: |
| 83 | + file-extension: ${{ matrix.extension }} |
| 84 | + use-quiet-mode: 'yes' |
| 85 | + config-file: '.github/workflows/markdown.links.config.json' |
| 86 | + |
| 87 | + # Build and test deployment |
| 88 | + build-test: |
| 89 | + name: Build and Test |
| 90 | + if: | |
| 91 | + github.event.action != 'closed' && |
| 92 | + github.event.pull_request.draft == false && |
| 93 | + (needs.code-checks.result == 'success' || needs.code-checks.result == 'skipped' || github.actor == 'dependabot[bot]') |
| 94 | + needs: [code-checks] # Only build after checks pass (or are skipped for Dependabot) |
| 95 | + runs-on: ubuntu-latest |
| 96 | + permissions: |
| 97 | + contents: read |
| 98 | + steps: |
| 99 | + - name: Checkout repository |
| 100 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 101 | + with: |
| 102 | + lfs: true |
| 103 | + fetch-depth: 2 |
| 104 | + |
| 105 | + - name: Setup and build |
| 106 | + uses: ./.github/actions/setup-and-build |
| 107 | + with: |
| 108 | + build-base-url: ${{ github.actor != 'dependabot[bot]' && format('/pr-preview/pr-{0}', github.event.number) || '' }} |
| 109 | + |
| 110 | + - name: Upload build artifacts |
| 111 | + if: github.actor != 'dependabot[bot]' && github.event.pull_request.head.repo.full_name == github.repository |
| 112 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 113 | + with: |
| 114 | + name: build-artifacts |
| 115 | + path: ./build/ |
| 116 | + retention-days: 1 |
| 117 | + compression-level: 9 |
| 118 | + |
| 119 | + # Deploy preview only for non-Dependabot PRs from the main repo (not forks) |
| 120 | + deploy-preview: |
| 121 | + name: Deploy Preview |
| 122 | + needs: build-test |
| 123 | + runs-on: ubuntu-latest |
| 124 | + if: | |
| 125 | + github.event.action != 'closed' && |
| 126 | + github.actor != 'dependabot[bot]' && |
| 127 | + github.event.pull_request.draft == false && |
| 128 | + github.event.pull_request.head.repo.full_name == github.repository |
| 129 | + permissions: |
| 130 | + contents: write # Required for pr-preview-action to push to gh-pages |
| 131 | + pull-requests: write # Required for PR comments |
| 132 | + steps: |
| 133 | + - name: Checkout repository |
| 134 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 135 | + with: |
| 136 | + fetch-depth: 0 |
| 137 | + lfs: false |
| 138 | + |
| 139 | + - name: Download build artifacts |
| 140 | + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 |
| 141 | + with: |
| 142 | + name: build-artifacts |
| 143 | + path: ./build/ |
| 144 | + |
| 145 | + - name: Deploy preview |
| 146 | + uses: rossjrw/pr-preview-action@9f77b1d057b494e662c50b8ca40ecc63f21e0887 # v1.6.2 |
| 147 | + id: preview-step |
| 148 | + with: |
| 149 | + source-dir: ./build/ |
| 150 | + preview-branch: gh-pages |
| 151 | + umbrella-dir: pr-preview |
| 152 | + action: deploy |
| 153 | + |
| 154 | + - name: Publish preview link |
| 155 | + if: steps['preview-step'].outputs['deployment-action'] == 'deploy' |
| 156 | + run: | |
| 157 | + url="${{ steps['preview-step'].outputs['preview-url'] }}" |
| 158 | + echo "Preview visible at ${url}" >> "$GITHUB_STEP_SUMMARY" |
| 159 | + echo "[Open preview](${url})" >> "$GITHUB_STEP_SUMMARY" |
| 160 | +
|
| 161 | + # Clean up preview on PR close (only for PRs from the main repo) |
| 162 | + cleanup-preview: |
| 163 | + name: Cleanup Preview |
| 164 | + runs-on: ubuntu-latest |
| 165 | + if: | |
| 166 | + github.event.action == 'closed' && |
| 167 | + github.actor != 'dependabot[bot]' && |
| 168 | + github.event.pull_request.draft == false && |
| 169 | + github.event.pull_request.head.repo.full_name == github.repository |
| 170 | + permissions: |
| 171 | + contents: write |
| 172 | + steps: |
| 173 | + - name: Checkout repository |
| 174 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 175 | + with: |
| 176 | + fetch-depth: 1 |
| 177 | + lfs: false |
| 178 | + |
| 179 | + - name: Remove preview |
| 180 | + uses: rossjrw/pr-preview-action@9f77b1d057b494e662c50b8ca40ecc63f21e0887 # v1.6.2 |
| 181 | + with: |
| 182 | + preview-branch: gh-pages |
| 183 | + umbrella-dir: pr-preview |
| 184 | + action: remove |
0 commit comments