Skip to content

Commit 1d18d29

Browse files
authored
Merge pull request #238 from r-devel/docs/deploy
update mkdocs workflow
2 parents fd2bffa + 539e6f9 commit 1d18d29

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

.github/workflows/build-mkdocs-website.yml

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,60 @@ on:
1010
- 'docs/**/**'
1111
- 'mkdocs.yml'
1212

13-
permissions:
14-
contents: write
15-
1613
jobs:
1714
build-and-deploy:
1815
if: |
1916
github.event_name == 'workflow_dispatch' ||
2017
(github.event_name == 'pull_request' && github.event.pull_request.merged == true)
2118
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write
2221

2322
steps:
2423
- name: Checkout repository
25-
uses: actions/checkout@v3
24+
uses: actions/checkout@v4
2625

2726
- name: Set up Python
28-
uses: actions/setup-python@v2
27+
uses: actions/setup-python@v5
2928
with:
3029
python-version: 3.x
3130

3231
- name: Install dependencies
3332
run: pip install mkdocs mkdocs-material[imaging]
3433

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+
3550
- name: Build MkDocs
3651
run: mkdocs build
3752

38-
- name: Deploy to GitHub Pages
53+
- name: Validate PAT
54+
env:
55+
GH_PAT: ${{ secrets.R_DEV_ENV_DOCS }}
3956
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
4263
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

Comments
 (0)