-
Notifications
You must be signed in to change notification settings - Fork 6
107 lines (98 loc) · 5.18 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
name: Docs
on: [push, ]
jobs:
build_docs:
name: Build and Deploy Documentation
runs-on: ubuntu-20.04
container:
# We run this workflow in a docker container that has a full LaTeX
# environment installed, so that we can build the PDF version of the
# documentation
image: docker.pkg.github.com/goerz-docker/docs-build-env/docs-build-env:latest
credentials:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- name: Build the docs
id: build
run: |
set -x
python -m pip install -e .[dev]
python -m pip install zip-files
export VERSION=$(python -c 'import docs_versions_menu; print(docs_versions_menu.__version__, end="")')
python -m sphinx -W "docs/" -d "docs/_build/doctree" "docs/_build/html"
python -m sphinx -W "docs/" -d "docs/_build/doctree" -b latex "docs/_build/latex"
python docs/build_pdf.py docs/_build/latex/docsversionsmenu.tex
python -m sphinx -W "docs/" -d "docs/_build/doctree" -b epub docs/_build/epub
zip-folder --debug --auto-root --outfile "docs-versions-menu-$VERSION.zip" docs/_build/html
mv docs/_build/latex/docsversionsmenu.pdf "docs-versions-menu-$VERSION.pdf"
mv docs/_build/epub/DocsVersionsMenu.epub "docs-versions-menu-$VERSION.epub"
touch docs/_build/html/_downloads
echo ::set-output name=VERSION::$VERSION
- name: Make a Github release and set _downloads links
shell: bash
if: startsWith(github.ref, 'refs/tags/v')
run: |
set -x
git fetch --tags --force # restore tag info that actions/checkout pruned
tag_name="${GITHUB_REF##*/}"
release_title=$(git tag -l --format='%(contents:subject)' "$tag_name")
git tag -l --format='%(contents:body)' "$tag_name" | tee RELEASE_NOTES.md
gh release create "$tag_name" ./docs-versions-menu-${{ steps.build.outputs.VERSION }}.* --notes-file RELEASE_NOTES.md --title="$release_title"
epub=$(gh api "repos/${{ github.repository }}/releases/tags/$tag_name" | jq '.assets[] | .browser_download_url' | sed 's/"//g' | grep 'epub$')
pdf=$(gh api "repos/${{ github.repository }}/releases/tags/$tag_name" | jq '.assets[] | .browser_download_url' | sed 's/"//g' | grep 'pdf$')
zip=$(gh api "repos/${{ github.repository }}/releases/tags/$tag_name" | jq '.assets[] | .browser_download_url' | sed 's/"//g' | grep 'zip$')
echo "[html]: $zip" >> docs/_build/html/_downloads
echo "[epub]: $epub" >> docs/_build/html/_downloads
echo "[pdf]: $pdf" >> docs/_build/html/_downloads
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy documentation to gh-pages
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
shell: bash
run: |
set -x
# Clone gh-pages
git clone --branch gh-pages https://github.com/${{ github.repository }} gh-pages
# Run rsync
branch_name=$(echo ${GITHUB_REF##*/} | tr / -)
rsync -av --delete "./docs/_build/html/" "./gh-pages/$branch_name/"
# Run docs-versions-menu
cd gh-pages
docs-versions-menu
# Commit and push
git config user.name github-actions
git config user.email [email protected]
git add -A --verbose
git status
git log --format=%B -n 1 | tee .git/_github_actions_commit_msg
loglastline=$(cat .git/_github_actions_commit_msg | grep -v '^$' | tail -n1)
logauthor=$(git log --format=%an -n 1)
if [[ "$logauthor" == "github-actions"* && "$loglastline" == *"${{ 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
git push --verbose --force https://$GITHUB_ACTOR:[email protected]/${{ github.repository }} gh-pages
env:
DOCS_VERSIONS_MENU_DEBUG: 'true'
DOCS_VERSIONS_MENU_VERSIONS: '(<branches> != (master, rtd-theme)), (<releases>)[:-1], rtd-theme, (<releases>)[-1], master'
DOCS_VERSIONS_MENU_LABEL: 'rtd-theme: v0.4.1 (rtd-theme)'
DOCS_VERSIONS_MENU_WARNING: 'unreleased: (<branches> != rtd-theme), <local-releases>'
GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@v2
name: Upload documentation artifacts
with:
name: docs
path: |
RELEASE_NOTES.md
./docs/_build/html/_downloads
./docs-versions-menu-${{ steps.build.outputs.VERSION }}.*