ci: consolidate and streamline workflows #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Pull Request | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| types: | |
| - opened | |
| - reopened | |
| - synchronize | |
| - closed | |
| - ready_for_review | |
| permissions: | |
| contents: read | |
| # Prevent concurrent builds for the same PR | |
| concurrency: | |
| group: pr-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| # Run code quality checks | |
| code-checks: | |
| name: Code Quality (${{ matrix.check }}) | |
| runs-on: ubuntu-latest | |
| if: github.event.action != 'closed' && github.actor != 'dependabot[bot]' && github.event.pull_request.draft == false | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - check: format | |
| command: npm run format:check | |
| - check: lint | |
| command: npm run lint | |
| - check: types | |
| command: npm run typecheck | |
| - check: audit | |
| command: npm audit | |
| continue-on-error: true | |
| - check: circular-deps | |
| command: npx madge --circular . --extensions ts,js,jsx,tsx | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| lfs: false | |
| fetch-depth: 2 | |
| - name: Setup dependencies | |
| uses: ./.github/actions/setup-and-build | |
| with: | |
| build: 'false' | |
| - name: Run ${{ matrix.check }} | |
| run: ${{ matrix.command }} | |
| continue-on-error: ${{ matrix.continue-on-error || false }} | |
| # Check markdown links | |
| markdown-link-check: | |
| name: Check Documentation Links (${{ matrix.extension }}) | |
| runs-on: ubuntu-latest | |
| if: github.event.action != 'closed' && github.actor != 'dependabot[bot]' && github.event.pull_request.draft == false | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| extension: ['.md', '.mdx'] | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| fetch-depth: 1 | |
| lfs: false | |
| - name: Check Markdown links (${{ matrix.extension }}) | |
| uses: tcort/github-action-markdown-link-check@a800ad5f1c35bf61987946fd31c15726a1c9f2ba # v1.1.0 | |
| continue-on-error: true | |
| with: | |
| file-extension: ${{ matrix.extension }} | |
| use-quiet-mode: 'yes' | |
| config-file: '.github/workflows/markdown.links.config.json' | |
| # Build and test deployment | |
| build-test: | |
| name: Build and Test | |
| if: | | |
| github.event.action != 'closed' && | |
| github.event.pull_request.draft == false && | |
| (needs.code-checks.result == 'success' || needs.code-checks.result == 'skipped' || github.actor == 'dependabot[bot]') | |
| needs: [code-checks] # Only build after checks pass (or are skipped for Dependabot) | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| lfs: true | |
| fetch-depth: 2 | |
| - name: Setup and build | |
| uses: ./.github/actions/setup-and-build | |
| with: | |
| build-base-url: ${{ github.actor != 'dependabot[bot]' && format('/pr-preview/pr-{0}', github.event.number) || '' }} | |
| - name: Upload build artifacts | |
| if: github.actor != 'dependabot[bot]' && github.event.pull_request.head.repo.full_name == github.repository | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
| with: | |
| name: build-artifacts | |
| path: ./build/ | |
| retention-days: 1 | |
| compression-level: 9 | |
| # Deploy preview only for non-Dependabot PRs from the main repo (not forks) | |
| deploy-preview: | |
| name: Deploy Preview | |
| needs: build-test | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event.action != 'closed' && | |
| github.actor != 'dependabot[bot]' && | |
| github.event.pull_request.draft == false && | |
| github.event.pull_request.head.repo.full_name == github.repository | |
| permissions: | |
| contents: write # Required for pr-preview-action to push to gh-pages | |
| pull-requests: write # Required for PR comments | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| fetch-depth: 1 | |
| lfs: false | |
| sparse-checkout: | | |
| .github | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 | |
| with: | |
| name: build-artifacts | |
| path: ./build/ | |
| - name: Deploy preview | |
| uses: rossjrw/pr-preview-action@9f77b1d057b494e662c50b8ca40ecc63f21e0887 # v1.6.2 | |
| id: preview-step | |
| with: | |
| source-dir: ./build/ | |
| preview-branch: gh-pages | |
| umbrella-dir: pr-preview | |
| action: deploy | |
| - name: Publish preview link | |
| if: steps['preview-step'].outputs['deployment-action'] == 'deploy' | |
| run: | | |
| url="${{ steps['preview-step'].outputs['preview-url'] }}" | |
| echo "Preview visible at ${url}" >> "$GITHUB_STEP_SUMMARY" | |
| echo "[Open preview](${url})" >> "$GITHUB_STEP_SUMMARY" | |
| # Clean up preview on PR close (only for PRs from the main repo) | |
| cleanup-preview: | |
| name: Cleanup Preview | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event.action == 'closed' && | |
| github.actor != 'dependabot[bot]' && | |
| github.event.pull_request.draft == false && | |
| github.event.pull_request.head.repo.full_name == github.repository | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| fetch-depth: 1 | |
| lfs: false | |
| - name: Remove preview | |
| uses: rossjrw/pr-preview-action@9f77b1d057b494e662c50b8ca40ecc63f21e0887 # v1.6.2 | |
| with: | |
| preview-branch: gh-pages | |
| umbrella-dir: pr-preview | |
| action: remove |