@@ -2,6 +2,10 @@ name: Build MkDocs website
2
2
3
3
on :
4
4
workflow_dispatch :
5
+ push :
6
+ branches : ["main","devel"]
7
+ paths :
8
+ - ' .github/workflows/build-mkdocs-website.yml'
5
9
pull_request :
6
10
branches : ["main","devel"]
7
11
types : [closed]
@@ -14,15 +18,28 @@ jobs:
14
18
build-and-deploy :
15
19
if : |
16
20
github.event_name == 'workflow_dispatch' ||
21
+ github.event_name == 'push' ||
17
22
(github.event_name == 'pull_request' &&
18
23
github.event.pull_request.merged == true)
19
24
runs-on : ubuntu-latest
20
25
permissions :
21
26
contents : write
22
27
23
28
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
+
24
39
- name : Checkout repository
25
40
uses : actions/checkout@v4
41
+ with :
42
+ token : ${{ secrets.R_DEV_ENV_DOCS }}
26
43
27
44
- name : Set up Python
28
45
uses : actions/setup-python@v5
@@ -32,53 +49,36 @@ jobs:
32
49
- name : Install dependencies
33
50
run : pip install mkdocs mkdocs-material[imaging]
34
51
35
- - name : Determine deployment settings
52
+ - name : Determine target repo
36
53
id : config
37
54
run : |
38
55
if [[ "${{ github.ref_name }}" == "main" ]]; then
39
56
echo "target_repo=${{ github.repository }}" >> "$GITHUB_OUTPUT"
40
- echo "url=https://contributor.r-project.org/r-dev-env" \
41
- >> "$GITHUB_OUTPUT"
42
57
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"
46
59
fi
47
60
48
- - name : Modify site_url in mkdocs.yml
61
+ - name : Modify site_url for development documentation
49
62
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
53
68
54
69
- name : Build MkDocs
55
70
run : mkdocs build
56
71
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
-
67
72
- name : Deploy to GitHub Pages
68
- env :
69
- GH_PAT : ${{ secrets.R_DEV_ENV_DOCS }}
70
73
run : |
71
74
echo "Deploying from branch: ${{ github.ref_name }}"
72
75
echo "Commit: ${{ github.sha }}"
76
+ echo "Deploying to: ${{ steps.config.outputs.target_repo}}"
73
77
74
78
git config --global user.email "[email protected] "
75
79
git config --global user.name "github-actions"
76
80
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