Skip to content

Commit 9937e02

Browse files
committed
set credentials in checkout action
1 parent e0058b2 commit 9937e02

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: Build MkDocs website
22

33
on:
44
workflow_dispatch:
5+
push:
6+
branches: ["main","devel"]
7+
paths:
8+
- '.github/workflows/build-mkdocs-website.yml'
59
pull_request:
610
branches: ["main","devel"]
711
types: [closed]
@@ -14,15 +18,28 @@ jobs:
1418
build-and-deploy:
1519
if: |
1620
github.event_name == 'workflow_dispatch' ||
21+
github.event_name == 'push' ||
1722
(github.event_name == 'pull_request' &&
1823
github.event.pull_request.merged == true)
1924
runs-on: ubuntu-latest
2025
permissions:
2126
contents: write
2227

2328
steps:
29+
- name: Validate PAT
30+
env:
31+
GH_PAT: ${{ secrets.R_DEV_ENV_DOCS }}
32+
run: |
33+
curl -H "Authorization: token $GH_PAT" \
34+
https://api.github.com/user || {
35+
echo "PAT is invalid or expired" >&2
36+
exit 1
37+
}
38+
2439
- name: Checkout repository
2540
uses: actions/checkout@v4
41+
with:
42+
token: ${{ secrets.R_DEV_ENV_DOCS }}
2643

2744
- name: Set up Python
2845
uses: actions/setup-python@v5
@@ -32,53 +49,36 @@ jobs:
3249
- name: Install dependencies
3350
run: pip install mkdocs mkdocs-material[imaging]
3451

35-
- name: Determine deployment settings
52+
- name: Determine target repo
3653
id: config
3754
run: |
3855
if [[ "${{ github.ref_name }}" == "main" ]]; then
3956
echo "target_repo=${{ github.repository }}" >> "$GITHUB_OUTPUT"
40-
echo "url=https://contributor.r-project.org/r-dev-env" \
41-
>> "$GITHUB_OUTPUT"
4257
else
43-
echo "target_repo=r-devel/r-dev-env-devel" >> "$GITHUB_OUTPUT"
44-
echo "url=https://contributor.r-project.org/r-dev-env-devel" \
45-
>> "$GITHUB_OUTPUT"
58+
echo "target_repo=${{ github.repository }}-devel" >> "$GITHUB_OUTPUT"
4659
fi
4760
48-
- name: Modify site_url in mkdocs.yml
61+
- name: Modify site_url for development documentation
4962
run: |
50-
echo "Setting site_url to ${{ steps.config.outputs.url }}"
51-
sed -i "s|^site_url:.*|site_url: '${{
52-
steps.config.outputs.url }}'|" mkdocs.yml
63+
if [[ "${{ github.ref_name }}" != "main" ]]; then
64+
site_url=https://contributor.r-project.org/r-dev-env-devel
65+
echo "Setting site_url to '${site_url}'"
66+
sed -i "s|^site_url:.*|site_url: '${site_url}'|" mkdocs.yml
67+
fi
5368
5469
- name: Build MkDocs
5570
run: mkdocs build
5671

57-
- name: Validate PAT
58-
env:
59-
GH_PAT: ${{ secrets.R_DEV_ENV_DOCS }}
60-
run: |
61-
curl -H "Authorization: token $GH_PAT" \
62-
https://api.github.com/user || {
63-
echo "PAT is invalid or expired" >&2
64-
exit 1
65-
}
66-
6772
- name: Deploy to GitHub Pages
68-
env:
69-
GH_PAT: ${{ secrets.R_DEV_ENV_DOCS }}
7073
run: |
7174
echo "Deploying from branch: ${{ github.ref_name }}"
7275
echo "Commit: ${{ github.sha }}"
76+
echo "Deploying to: ${{ steps.config.outputs.target_repo}}"
7377
7478
git config --global user.email "[email protected]"
7579
git config --global user.name "github-actions"
7680
77-
git fetch origin gh-pages
78-
git worktree add gh-pages gh-pages
79-
cp -r site/* gh-pages/
80-
cd gh-pages
81-
git add .
82-
git commit -m "Automated site update for r-dev-env ${{ github.sha }}" \
83-
|| echo "No changes to commit"
84-
git push https://x-access-token:${GH_PAT}@github.com/${{ steps.config.outputs.target_repo }} gh-pages
81+
git remote set-url origin \
82+
https://github.com/${{ steps.config.outputs.target_repo }}
83+
mkdocs gh-deploy --config-file mkdocs.yml \
84+
--remote-branch gh-pages --force

0 commit comments

Comments
 (0)