Skip to content

Commit d736a07

Browse files
authored
Stable documentation workflow
Refs simonw/simonw-readthedocs-experiments#1
1 parent 3e39af0 commit d736a07

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

.github/workflows/stable-docs.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Update Stable Docs
2+
3+
on:
4+
release:
5+
types: [published]
6+
push:
7+
branches:
8+
- main
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
update_stable_docs:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 0 # We need all commits to find docs/ changes
21+
- name: Set up Git user
22+
run: |
23+
git config user.name "Automated"
24+
git config user.email "[email protected]"
25+
- name: Check if stable branch exists
26+
run: |
27+
if ! git ls-remote --heads origin stable | grep stable; then
28+
git checkout -b stable
29+
git push -u origin stable
30+
fi
31+
- name: Handle Release
32+
if: github.event_name == 'release'
33+
run: |
34+
git fetch --all
35+
git checkout stable
36+
git reset --hard ${GITHUB_REF#refs/tags/}
37+
git push origin stable --force
38+
- name: Handle Commit to Main
39+
if: contains(github.event.head_commit.message, '!stable-docs')
40+
run: |
41+
git fetch origin
42+
git checkout -b stable origin/stable
43+
# Get the list of modified files in docs/ from the current commit
44+
FILES=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} -- docs/)
45+
# Check if the list of files is non-empty
46+
if [[ -n "$FILES" ]]; then
47+
# Checkout those files to the stable branch to over-write with their contents
48+
for FILE in $FILES; do
49+
git checkout ${{ github.sha }} -- $FILE
50+
done
51+
git add docs/
52+
git commit -m "Doc changes from ${{ github.sha }}"
53+
git push origin stable
54+
else
55+
echo "No changes to docs/ in this commit."
56+
exit 0
57+
fi

0 commit comments

Comments
 (0)