Repository navigation
143 lines (127 loc) · 4.8 KB
/
Copy pathdeploy-docs.yml
File metadata and controls
143 lines (127 loc) · 4.8 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
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
name: Build and Deploy Docs
env:
POETRY_VERSION: "2.4.1"
POETRY_DYNAMIC_VERSIONING_VERSION: "1.9.1"
on:
push:
branches:
- main
workflow_dispatch:
workflow_run:
workflows: ["Publish Python Package"]
types: [completed]
permissions:
contents: write
concurrency:
group: docs-pages
cancel-in-progress: false
jobs:
build-and-deploy:
runs-on: ubuntu-latest
if: >
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.ref }}
- name: Set up Python & Graphviz
uses: actions/setup-python@v5
with:
python-version: '3.11'
- uses: ts-graphviz/setup-graphviz@v2
- name: Cache Poetry & pip
uses: actions/cache@v3
with:
path: |
~/.cache/pypoetry
~/.cache/pip
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
- name: Install Dependencies
env:
POETRY_DYNAMIC_VERSIONING_COMMANDS: install,build
run: |
pip install "poetry==${POETRY_VERSION}"
poetry self add "poetry-dynamic-versioning[plugin]==${POETRY_DYNAMIC_VERSIONING_VERSION}"
poetry install --with dev --extras docs
- name: Debug Git state and version
run: |
echo "=== Git State ==="
echo "Commit: $(git rev-parse HEAD)"
echo "Ref: $GITHUB_REF"
echo "Ref name: $GITHUB_REF_NAME"
echo "Exact tag?: $(git describe --tags --exact-match HEAD 2>/dev/null || echo 'none')"
echo "Latest tag: $(git describe --tags --abbrev=0 2>/dev/null || echo 'none')"
echo "=== Project Version ==="
poetry version
poetry run python -c 'import corneto; print(corneto.__version__)'
- name: Determine version_folder
id: set_version
run: |
if [ "${{ github.event_name }}" = "workflow_run" ]; then
if [[ "${{ github.event.workflow_run.head_branch }}" == v* ]]; then
echo "version_folder=${{ github.event.workflow_run.head_branch }}" >> $GITHUB_OUTPUT
else
echo "Publish workflow did not run for a release tag" >&2
exit 1
fi
elif [ "${GITHUB_REF}" = "refs/heads/main" ]; then
echo "version_folder=stable" >> $GITHUB_OUTPUT
else
echo "No documentation target for ${GITHUB_REF}" >&2
exit 1
fi
- name: Sync GitHub Releases to Docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: python scripts/sync_releases.py --repo saezlab/corneto --docs-dir docs
- name: Build Docs
env:
SPHINX_VERSION_MATCH: ${{ steps.set_version.outputs.version_folder }}
DOCS_BASE_URL: https://corneto.org
run: poetry run sphinx-build -W --keep-going -b html docs docs/_build/html
- name: Check out gh-pages
run: |
set -euo pipefail
git fetch origin gh-pages:refs/remotes/origin/gh-pages
git worktree add --detach gh-pages-worktree refs/remotes/origin/gh-pages
- name: Prepare Pages tree
env:
DOCS_BASE_URL: https://corneto.org
run: |
set -euo pipefail
root_args=()
if [ "${{ steps.set_version.outputs.version_folder }}" = "stable" ]; then
root_args+=(--update-root)
fi
poetry run python scripts/prepare_docs_pages.py \
--pages-dir gh-pages-worktree \
--build-dir docs/_build/html \
--landing-dir docs/landing \
--version-folder "${{ steps.set_version.outputs.version_folder }}" \
--base-url "${DOCS_BASE_URL}" \
"${root_args[@]}"
- name: Commit and deploy Pages tree
env:
VERSION_FOLDER: ${{ steps.set_version.outputs.version_folder }}
run: |
set -euo pipefail
cd gh-pages-worktree
if [ -z "$(git status --porcelain)" ]; then
echo "No Pages changes to deploy."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "docs: deploy ${VERSION_FOLDER}"
git fetch origin gh-pages
if ! git merge --ff-only origin/gh-pages; then
echo "gh-pages advanced during deployment; refusing to overwrite it." >&2
exit 1
fi
git push origin HEAD:gh-pages