Repository navigation
137 lines (122 loc) · 4.43 KB
/
Copy pathgenerate-docs.yml
File metadata and controls
137 lines (122 loc) · 4.43 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
# Generate PySceneDetect documentation and updates the gh-pages branch.
name: Generate Documentation
on:
push:
branches:
- main # docs/head
- 'releases/**' # docs/**
paths:
- 'docs/**'
- 'scenedetect/**'
- 'scenedetect.cfg'
- 'website/pages/docs.md'
workflow_dispatch:
concurrency:
group: gh-pages-docs
cancel-in-progress: false
jobs:
update_docs:
runs-on: ubuntu-latest
if: github.repository == 'Breakthrough/PySceneDetect'
permissions:
contents: write # pushes generated docs to the gh-pages branch
env:
scenedetect_docs_dest: ''
steps:
- uses: actions/checkout@v7.0.1
- name: Get Latest Version
run: |
git fetch origin main --depth=1
echo "scenedetect_docs_latest=$(git show origin/main:docs/LATEST_VERSION | tr -d '[:space:]')" >> "$GITHUB_ENV"
- name: Set up Python 3.12
uses: actions/setup-python@v7.1.0
with:
python-version: '3.12'
cache: 'pip'
- name: Set Destination (Releases)
if: ${{ startsWith(github.ref, 'refs/heads/releases/') }}
shell: bash
env:
REF_NAME: ${{ github.ref_name }}
run: |
echo "scenedetect_docs_dest=${REF_NAME#releases/}" >> "$GITHUB_ENV"
- name: Set Destination (Head)
if: ${{ github.ref == 'refs/heads/main' }}
shell: bash
run: |
echo "scenedetect_docs_dest=head" >> "$GITHUB_ENV"
- name: Check Destination
if: ${{ env.scenedetect_docs_dest == '' }}
shell: bash
run: |
echo "Failing build: destination must be set!"
exit 1
- name: Setup Environment
run: |
pip install ".[docs,pyav,moviepy]"
git config --global user.name github-actions
git config --global user.email github-actions@github.com
- name: Check CLI Documentation
shell: bash
env:
PYTHONDONTWRITEBYTECODE: "1"
run: |
python -B docs/generate_cli_docs.py
if [[ $(git status --porcelain=1 -- docs | wc -l) -ne 0 ]]; then
git --no-pager diff -- docs
echo 'CLI documentation is out of date: the generated docs do not match the output of docs/generate_cli_docs.py!'
echo 'Re-run "python docs/generate_cli_docs.py" and commit the result.'
exit 1
fi
- name: Generate Docs
shell: bash
env:
PYTHONDONTWRITEBYTECODE: "1"
run: |
sphinx-build -b html -d "${RUNNER_TEMP}/doctrees" docs "${RUNNER_TEMP}/docs-build"
- name: Update gh-pages Branch
shell: bash
env:
DOCS_DEST: ${{ env.scenedetect_docs_dest }}
run: |
git fetch origin gh-pages
git checkout -B gh-pages origin/gh-pages
git clean -ffdx
git rm "docs/${DOCS_DEST}" -r -f --ignore-unmatch
mkdir -p "docs/${DOCS_DEST}"
cp -a "${RUNNER_TEMP}/docs-build/." "docs/${DOCS_DEST}/"
git add -A "docs/${DOCS_DEST}"
- name: Update Latest
if: ${{ env.scenedetect_docs_dest == env.scenedetect_docs_latest }}
shell: bash
env:
DOCS_DEST: ${{ env.scenedetect_docs_dest }}
run: |
git rm "docs/latest" -r -f --ignore-unmatch
cp -a "docs/${DOCS_DEST}" docs/latest
git add -A docs/latest
echo "scenedetect_docs_dest=${DOCS_DEST} (latest)" >> "$GITHUB_ENV"
- name: Commit and Push
shell: bash
env:
DOCS_DEST: ${{ env.scenedetect_docs_dest }}
TRIGGER_ACTOR: ${{ github.triggering_actor }}
run: |
if ! git diff --quiet || ! git diff --cached --quiet; then
git commit -a -m "[docs] @${TRIGGER_ACTOR}: Generate Documentation" \
-m "Source: ${GITHUB_REF_NAME} (${GITHUB_SHA})" \
-m "Destination: ${DOCS_DEST}"
for attempt in 1 2 3 4 5; do
if git push origin gh-pages; then
break
fi
if [[ "${attempt}" -eq 5 ]]; then
echo "Failed to push to gh-pages after ${attempt} attempts." >&2
exit 1
fi
echo "Push failed (attempt ${attempt}/5); rebasing onto origin/gh-pages and retrying..."
sleep $((attempt * 2))
git fetch origin gh-pages
git pull --rebase origin gh-pages
done
fi