-
Notifications
You must be signed in to change notification settings - Fork 20
104 lines (91 loc) · 3.48 KB
/
docs.yml
File metadata and controls
104 lines (91 loc) · 3.48 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Build Docs
on:
workflow_dispatch: # run on request (no need for PR)
push:
branches:
- master
permissions: {} # No permissions by default on workflow level
jobs:
Build-Docs:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version-file: ".python-version"
- name: Install uv
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
with:
version: "0.10.8"
- name: Install dependencies
run: |
uv sync --locked --extra docs
- name: Build Docs
working-directory: docs
run: uv run make html
- name: Branch name
id: branch_name
run: |
echo "SOURCE_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: Create gh-pages branch
env:
SOURCE: ${{steps.branch_name.outputs.SOURCE_NAME}}
run: |
if [[ ${{github.event_name}} == 'workflow_dispatch' ]]; then
echo RELEASE_VERSION="test_build" >> $GITHUB_ENV
else
echo RELEASE_VERSION=${GITHUB_REF#refs/*/} >> $GITHUB_ENV
fi
echo SOURCE_NAME=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT
echo SOURCE_BRANCH=${GITHUB_REF#refs/heads/} >> $GITHUB_OUTPUT
echo SOURCE_TAG=${GITHUB_REF#refs/tags/} >> $GITHUB_OUTPUT
existed_in_remote=$(git ls-remote --heads origin gh-pages)
if [[ -z ${existed_in_remote} ]]; then
echo "Creating gh-pages branch"
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git checkout --orphan gh-pages
git reset --hard
echo '<html><head><meta http-equiv="refresh" content="0; url=latest/" /></head></html>' > index.html
git add index.html
touch .nojekyll
git add .nojekyll
git commit -m "Initializing gh-pages branch"
git push origin gh-pages
git checkout "${SOURCE}"
echo "Created gh-pages branch"
else
echo "Branch gh-pages already exists"
fi
- name: Commit docs to gh-pages branch
env:
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
run: |
git fetch
git checkout gh-pages
mkdir -p /tmp/docs_build
cp -r docs/build/html/* /tmp/docs_build/
rm -rf "$RELEASE_VERSION"/*
echo '<html><head><meta http-equiv="refresh" content="0; url=latest/" /></head></html>' > index.html
mkdir -p "$RELEASE_VERSION"
cp -r /tmp/docs_build/* ./"$RELEASE_VERSION"
rm -rf /tmp/docs_build
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
if [[ "$RELEASE_VERSION" != 'test_build' ]]; then
ln -sfn "$RELEASE_VERSION" latest
fi
git add ./latest "$RELEASE_VERSION"
git add index.html
git commit -m "Update documentation" -a || true
- name: Push changes
uses: ad-m/github-push-action@57116acb309081ee57864270b0e3c4cedbe45452
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages