-
Notifications
You must be signed in to change notification settings - Fork 19
85 lines (73 loc) · 2.56 KB
/
build-mkdocs-website.yml
File metadata and controls
85 lines (73 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Build MKDocs website
on:
workflow_dispatch:
pull_request:
branches: ["main","devel"]
types: [closed]
paths:
- '.github/workflows/build-mkdocs-website.yml'
- 'docs/**/**'
- 'mkdocs.yml'
jobs:
build-and-deploy:
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' &&
github.event.pull_request.merged == true)
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install dependencies
run: pip install mkdocs mkdocs-material[imaging]
- name: Determine deployment settings
id: config
run: |
if [[ "${{ github.ref_name }}" == "main" ]]; then
echo "target_repo=${{ github.repository }}" >> "$GITHUB_OUTPUT"
echo "url=https://contributor.r-project.org/r-dev-env" \
>> "$GITHUB_OUTPUT"
else
echo "target_repo=r-devel/r-dev-env-devel" >> "$GITHUB_OUTPUT"
echo "url=https://contributor.r-project.org/r-dev-env-devel" \
>> "$GITHUB_OUTPUT"
fi
- name: Modify site_url in mkdocs.yml
run: |
echo "Setting site_url to ${{ steps.config.outputs.url }}"
sed -i "s|^site_url:.*|site_url: '${{
steps.config.outputs.url }}'|" mkdocs.yml
- name: Build MkDocs
run: mkdocs build
- name: Validate PAT
env:
GH_PAT: ${{ secrets.R_DEV_ENV_DOCS }}
run: |
curl -H "Authorization: token $GH_PAT" \
https://api.github.com/user || {
echo "PAT is invalid or expired" >&2
exit 1
}
- name: Deploy to GitHub Pages
env:
GH_PAT: ${{ secrets.R_DEV_ENV_DOCS }}
run: |
echo "Deploying from branch: ${{ github.ref_name }}"
echo "Commit: ${{ github.sha }}"
git config --global user.email "github-actions@github.com"
git config --global user.name "github-actions"
git fetch origin gh-pages
git worktree add gh-pages gh-pages
cp -r site/* gh-pages/
cd gh-pages
git add .
git commit -m "Automated site update for r-dev-env ${{ github.sha }}" \
|| echo "No changes to commit"
git push https://x-access-token:${GH_PAT}@github.com/${{
steps.config.outputs.target_repo }} gh-pages