test(docs): verify preview lifecycle #14
Workflow file for this run
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: Build docs | |
| on: | |
| push: | |
| branches: [master] | |
| paths: | |
| - "docs/**" | |
| - ".github/workflows/docs-preview.yml" | |
| - ".github/workflows/deploy-docs.yml" | |
| pull_request: | |
| types: [opened, synchronize, reopened, closed] | |
| paths: | |
| - "docs/**" | |
| - ".github/workflows/docs-preview.yml" | |
| - ".github/workflows/deploy-docs.yml" | |
| permissions: | |
| contents: read | |
| env: | |
| ASTRO_SITE: https://vide.pascal-lab.net | |
| ASTRO_BASE: ${{ github.event_name == 'pull_request' && format('/preview/pr-{0}/', github.event.pull_request.number) || '/' }} | |
| PREVIEW_URL: ${{ github.event_name == 'pull_request' && format('https://vide.pascal-lab.net/preview/pr-{0}/', github.event.pull_request.number) || '' }} | |
| jobs: | |
| metadata: | |
| name: Prepare preview metadata | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Write preview metadata | |
| env: | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| PR_ACTION: ${{ github.event.action }} | |
| run: | | |
| set -euo pipefail | |
| preview_path="preview/pr-${PR_NUMBER}/" | |
| preview_url="https://vide.pascal-lab.net/${preview_path}" | |
| mkdir -p preview-metadata | |
| printf '%s\n' "${PR_NUMBER}" > preview-metadata/pr-number | |
| printf '%s\n' "${PR_ACTION}" > preview-metadata/action | |
| printf '%s\n' "${preview_path}" > preview-metadata/path | |
| printf '%s\n' "${preview_url}" > preview-metadata/url | |
| if [ "${PR_ACTION}" = "closed" ]; then | |
| echo "Docs preview will be removed from ${preview_url}" >> "${GITHUB_STEP_SUMMARY}" | |
| else | |
| echo "Docs preview will be deployed to ${preview_url}" >> "${GITHUB_STEP_SUMMARY}" | |
| fi | |
| - name: Upload preview metadata | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: vide-docs-preview-metadata | |
| path: preview-metadata | |
| retention-days: 7 | |
| build: | |
| name: Build Starlight | |
| if: github.event_name != 'pull_request' || github.event.action != 'closed' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: npm | |
| cache-dependency-path: docs/package-lock.json | |
| - name: Install dependencies | |
| run: npm ci | |
| working-directory: docs | |
| - name: Build docs | |
| run: npm run build | |
| working-directory: docs | |
| - name: Add preview summary | |
| if: github.event_name == 'pull_request' | |
| run: | | |
| set -euo pipefail | |
| echo "Docs preview will be deployed to ${PREVIEW_URL}" >> "${GITHUB_STEP_SUMMARY}" | |
| - name: Upload preview artifact | |
| if: github.event_name == 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: vide-docs-preview | |
| path: docs/dist | |
| retention-days: 7 |