-
Notifications
You must be signed in to change notification settings - Fork 6
147 lines (121 loc) · 4.79 KB
/
docs.yml
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Docs
on:
push:
branches:
- master
- dev
- 'release-*'
tags:
- '*'
pull_request:
branches:
- master
jobs:
build_docs:
name: Build Sphinx docs
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
name: Install Python 3.9
with:
python-version: 3.9
- name: Install zip-files
run: pip install zip-files
- name: Install apt packages
run: sudo apt-get install graphviz imagemagick pandoc
- name: Generate HTML Documentation
run: make docs
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::$(python -c 'print([line.split("=")[-1].strip()[1:-1] for line in open("./src/weylchamber/__init__.py", encoding="utf8").readlines() if line.startswith("__version__")][0], end="")')
- name: Zip the HTML documentation
run: zip-folder --debug --auto-root --outfile "weylchamber-docs-${{ steps.get_version.outputs.VERSION }}.zip" docs/_build/html
- uses: actions/upload-artifact@v4
name: Upload documentation artifacts
with:
name: weylchamber-docs
# We need at least two files in the artifact to avoid a weird
# double-zip file. Hence README.md
path: |
README.md
./weylchamber-docs-${{ steps.get_version.outputs.VERSION }}.*
deploy_gh_pages:
name: Deploy documentation to gh-pages
if: always() && needs.build_docs.result == 'success' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))
runs-on: ubuntu-24.04
needs: [build_docs]
steps:
- uses: actions/setup-python@v5
name: Install Python 3.9
with:
python-version: 3.9
- name: Install deploy requirements
run: pip install docs-versions-menu
- name: Get branch name
shell: bash
run: |
echo ${{ github.ref }}
echo "BRANCH_NAME=$(echo ${GITHUB_REF##*/} | tr / -)" >> $GITHUB_ENV
cat $GITHUB_ENV
- uses: actions/checkout@v4
name: Check out gh-pages branch (full history)
with:
ref: gh-pages
fetch-depth: 0
- uses: actions/download-artifact@v4
name: Download weylchamber-docs artifact
with:
name: weylchamber-docs
path: _weylchamber_docs
- name: Unzip html documentation
working-directory: _weylchamber_docs
shell: bash
run: |
unzip *.zip -d _unzip
mv _unzip/* _unzip/${{ env.BRANCH_NAME }}
- name: Rsync html documentation into place
run: rsync -av --delete _weylchamber_docs/_unzip/${{ env.BRANCH_NAME }}/ ./${{ env.BRANCH_NAME }}/
- name: Set download links
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo "[html]: https://github.com/qucontrol/w/releases/download/${{ env.BRANCH_NAME }}/weylchamber-${{ env.BRANCH_NAME }}.zip" >> ./${{ env.BRANCH_NAME }}/_downloads
- name: Remove artifact files
shell: bash
run: rm -rf _weylchamber_docs
- name: Run docs-versions-menu
run: docs-versions-menu
- name: Get the previous commit message
id: get_previous_commit
run: |
git log --format=%B -n 1 | tee .git/_github_actions_commit_msg
echo ::set-output name=log::$(cat .git/_github_actions_commit_msg)
echo ::set-output name=lastline::$(cat .git/_github_actions_commit_msg | grep -v '^$' | tail -n1)
echo ::set-output name=author::$(git log --format=%an -n 1)
- name: Set git configuration
shell: bash
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Commit changes
shell: bash
run: |
echo "Committing to gh-pages"
echo "# GIT ADD"
git add -A --verbose
echo "# GIT STATUS"
git status
echo "# GIT COMMIT"
if [[ "${{ steps.get_previous_commit.outputs.author }}" == "github-actions"* && "${{ steps.get_previous_commit.outputs.lastline }}" == *"${{ github.ref }}"* ]];
then
# we ammend if the previous commit was down by Github Actions and was based on the same branch/tag name
echo "Amending previous commit"
echo "Deployed from commit ${GITHUB_SHA} (${GITHUB_REF})" >> .git/_github_actions_commit_msg
git commit --verbose --amend -F .git/_github_actions_commit_msg
else
echo "Making new commit"
git commit --verbose -m "Auto-update from Github Actions Workflow" -m "Deployed from commit ${GITHUB_SHA} (${GITHUB_REF})"
fi
git log -n 1
- name: Push changes
run: git push --verbose --force