|
10 | 10 | - 'docs/**/**' |
11 | 11 | - 'mkdocs.yml' |
12 | 12 |
|
13 | | -permissions: |
14 | | - contents: write |
15 | | - |
16 | 13 | jobs: |
17 | 14 | build-and-deploy: |
18 | 15 | if: | |
19 | 16 | github.event_name == 'workflow_dispatch' || |
20 | 17 | (github.event_name == 'pull_request' && github.event.pull_request.merged == true) |
21 | 18 | runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: write |
22 | 21 |
|
23 | 22 | steps: |
24 | 23 | - name: Checkout repository |
25 | | - uses: actions/checkout@v3 |
| 24 | + uses: actions/checkout@v4 |
26 | 25 |
|
27 | 26 | - name: Set up Python |
28 | | - uses: actions/setup-python@v2 |
| 27 | + uses: actions/setup-python@v5 |
29 | 28 | with: |
30 | 29 | python-version: 3.x |
31 | 30 |
|
32 | 31 | - name: Install dependencies |
33 | 32 | run: pip install mkdocs mkdocs-material[imaging] |
34 | 33 |
|
| 34 | + - name: Determine deployment settings |
| 35 | + id: config |
| 36 | + run: | |
| 37 | + if [[ "${{ github.ref_name }}" == "main" ]]; then |
| 38 | + echo "target_repo=${{ github.repository }}" >> "$GITHUB_OUTPUT" |
| 39 | + echo "url=https://contributor.r-project.org/r-dev-env" >> "$GITHUB_OUTPUT" |
| 40 | + else |
| 41 | + echo "target_repo=r-devel/r-dev-env-devel" >> "$GITHUB_OUTPUT" |
| 42 | + echo "url=https://contributor.r-project.org/r-dev-env-devel" >> "$GITHUB_OUTPUT" |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: Modify site_url in mkdocs.yml |
| 46 | + run: | |
| 47 | + echo "Setting site_url to ${{ steps.config.outputs.url }}" |
| 48 | + sed -i "s|^site_url:.*|site_url: '${{ steps.config.outputs.url }}'|" mkdocs.yml |
| 49 | +
|
35 | 50 | - name: Build MkDocs |
36 | 51 | run: mkdocs build |
37 | 52 |
|
38 | | - - name: Deploy to GitHub Pages |
| 53 | + - name: Validate PAT |
| 54 | + env: |
| 55 | + GH_PAT: ${{ secrets.R_DEV_ENV_DOCS }} |
39 | 56 | run: | |
40 | | - mkdocs gh-deploy --force |
41 | | - git push origin gh-pages |
| 57 | + curl -H "Authorization: token $GH_PAT" https://api.github.com/user || { |
| 58 | + echo "PAT is invalid or expired" >&2 |
| 59 | + exit 1 |
| 60 | + } |
| 61 | +
|
| 62 | + - name: Deploy to GitHub Pages |
42 | 63 | env: |
43 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 64 | + GH_PAT: ${{ secrets.R_DEV_ENV_DOCS }} |
| 65 | + run: | |
| 66 | + echo "Deploying from branch: ${{ github.ref_name }}" |
| 67 | + echo "Commit: ${{ github.sha }}" |
| 68 | + git remote set-url origin https://x-access-token:${GH_PAT}@github.com/${{ steps.config.outputs.target_repo }} |
| 69 | + mkdocs gh-deploy --config-file mkdocs.yml --remote-branch gh-pages --force |
0 commit comments