|
1 | 1 | name: Documentation |
2 | 2 | on: |
| 3 | + pull_request: |
| 4 | + types: [opened, synchronize, reopened, closed] |
| 5 | + branches: |
| 6 | + - feature/zensical |
3 | 7 | push: |
4 | 8 | branches: |
5 | | - - main |
| 9 | + - feature/zensical |
6 | 10 | permissions: |
7 | | - contents: read |
8 | | - pages: write |
9 | | - id-token: write |
| 11 | + contents: write # gh-pages + cleanup |
| 12 | + pull-requests: write # PR comments |
| 13 | + pages: write # deploy-pages |
| 14 | + id-token: write # required by deploy-pages |
10 | 15 | jobs: |
11 | 16 | build: |
| 17 | + if: github.event.action != 'closed' |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v6 |
| 23 | + |
| 24 | + - name: "Set up Python" |
| 25 | + uses: actions/setup-python@v6 |
| 26 | + with: |
| 27 | + python-version-file: "pyproject.toml" |
| 28 | + |
| 29 | + - name: Install uv |
| 30 | + uses: astral-sh/setup-uv@v7 |
| 31 | + |
| 32 | + - name: Sync dependencies |
| 33 | + run: uv sync |
| 34 | + |
| 35 | + - name: Build site |
| 36 | + run: uv run zensical build --clean |
| 37 | + |
| 38 | + - name: Deploy PR preview |
| 39 | + if: github.event_name == 'pull_request' |
| 40 | + uses: peaceiris/actions-gh-pages@v4 |
| 41 | + with: |
| 42 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + publish_dir: site |
| 44 | + destination_dir: pr-${{ github.event.pull_request.number }} |
| 45 | + |
| 46 | + - name: Comment PR with preview URL |
| 47 | + if: github.event_name == 'pull_request' |
| 48 | + uses: actions/github-script@v7 |
| 49 | + with: |
| 50 | + script: | |
| 51 | + const pr = context.payload.pull_request.number; |
| 52 | + const { owner, repo } = context.repo; |
| 53 | +
|
| 54 | + const url = `https://ff4j.github.io/docs/pr-${pr}/`; |
| 55 | +
|
| 56 | + await github.rest.issues.createComment({ |
| 57 | + owner, |
| 58 | + repo, |
| 59 | + issue_number: pr, |
| 60 | + body: `📘 **Site preview available**:\n\n${url}` |
| 61 | + }); |
| 62 | +
|
| 63 | + - name: Upload Pages artifact |
| 64 | + if: github.event_name == 'push' |
| 65 | + uses: actions/upload-pages-artifact@v3 |
| 66 | + with: |
| 67 | + path: site |
| 68 | + |
| 69 | + publish: |
| 70 | + if: github.event_name == 'push' |
| 71 | + runs-on: ubuntu-latest |
| 72 | + needs: build |
| 73 | + environment: |
| 74 | + name: github-pages |
| 75 | + steps: |
| 76 | + - name: Deploy to GitHub Pages |
| 77 | + uses: actions/deploy-pages@v4 |
| 78 | + |
| 79 | + cleanup: |
| 80 | + if: github.event_name == 'pull_request' && |
| 81 | + github.event.action == 'closed' && |
| 82 | + github.event.pull_request.merged == false |
12 | 83 | runs-on: ubuntu-latest |
| 84 | + |
13 | 85 | steps: |
14 | | - - uses: actions/checkout@v6 |
| 86 | + - name: Checkout gh-pages branch |
| 87 | + uses: actions/checkout@v4 |
| 88 | + with: |
| 89 | + ref: gh-pages |
| 90 | + |
| 91 | + - name: Remove PR preview folder |
| 92 | + run: | |
| 93 | + rm -rf pr-${{ github.event.pull_request.number }} |
| 94 | +
|
| 95 | + - name: Commit cleanup |
| 96 | + run: | |
| 97 | + git config user.name "github-actions" |
| 98 | + git config user.email "github-actions@github.com" |
| 99 | + git commit -am "chore: remove preview for PR #${{ github.event.pull_request.number }}" || exit 0 |
| 100 | + git push |
0 commit comments