-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
88 lines (86 loc) · 3.23 KB
/
action.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
name: 'Sphinx docs to GitHub Pages'
description: 'Automatic Sphinx html docs compilation and deployment through the gh-pages branch.'
author: "Bruce Ravel"
branding:
icon: "upload-cloud"
color: "orange"
inputs:
branch:
description: Name of the branch where the sphinx documentation is located
required: false
default: 'main'
dir_docs:
description: Path where the sphinx documentation is located
required: false
default: 'docs'
sphinxopts:
description: Compilation options for sphinx-build
required: false
default: ''
runs:
using: "composite"
steps:
- name: setting the committer name and email
id: committer
shell: bash
run: |
author_name="$(git show --format=%an -s)"
author_email="$(git show --format=%ae -s)"
echo "::group::Set committer"
echo "git config user.name $author_name"
git config user.name $author_name
echo "git config user.email $author_email"
git config user.email $author_email
echo "::endgroup::"
- name: gh-pages branch creation if needed
id: gh-pages-branch-creation
shell: bash
run: |
echo "::group::Checking if gh-pages branch exists"
if [[ -z $(git ls-remote --heads origin gh-pages) ]]; then
echo "Creating gh-pages branch"
git checkout --orphan gh-pages
git reset --hard
git commit --allow-empty -m "First commit to create gh-pages branch"
git push origin gh-pages
echo "Created gh-pages branch"
else
echo "Branch gh-pages already exists"
fi
echo "::endgroup::"
- name: Moving to branch where sphinx docs are located
id: to-branch-with-docs
shell: bash
run: |
git checkout ${{ inputs.branch }}
- name: sphinx html docs compilation
shell: bash -l {0} # This is needed to work with conda here. See:https://github.com/marketplace/actions/setup-miniconda#IMPORTANT
working-directory: ./${{ inputs.dir_docs }}
run: |
echo ::group::Sphinx docs compilation
sphinx-build -M html . _build ${{ inputs.sphinxopts }}
echo ::endgroup::
- name: pushing to gh-pages
shell: bash
run: |
echo ::group::Create README for gh-pages
SHA=$GITHUB_SHA
echo "$SHA $GITHUB_EVENT_NAME"
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
SHA=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.head.sha)
fi
SHORT_SHA="$(git rev-parse --short $SHA)"
DIR_HTML=${{ inputs.dir_docs }}/_build/html/
echo "#GitHub Pages" > $DIR_HTML/README.md
echo "" >> $DIR_HTML/README.md
echo "Last update of sphinx html documentation from [$SHORT_SHA](https://github.com/$GITHUB_REPOSITORY/tree/$SHA)" >> $DIR_HTML/README.md
cat $DIR_HTML/README.md
echo ::endgroup::
echo ::group::Create .nojekyll in case 'sphinx.ext.githubpages' is not used
touch $DIR_HTML/.nojekyll
echo ::endgroup::
echo ::group::Push to gh-pages
git add -f $DIR_HTML
git commit -m "From $GITHUB_REF $SHA"
git push origin `git subtree split --prefix $DIR_HTML ${{ inputs.branch }}`:gh-pages --force
echo ::endgroup::