| 1 |
name: Update Stable Docs |
| 2 |
|
| 3 |
on: |
| 4 |
release: |
| 5 |
types: [published] |
| 6 |
push: |
| 7 |
branches: |
| 8 |
- main |
| 9 |
- 0.65.x |
| 10 |
|
| 11 |
permissions: |
| 12 |
contents: write |
| 13 |
|
| 14 |
jobs: |
| 15 |
update_stable_docs: |
| 16 |
runs-on: ubuntu-latest |
| 17 |
steps: |
| 18 |
- name: Checkout repository |
| 19 |
uses: actions/checkout@v7 |
| 20 |
with: |
| 21 |
fetch-depth: 0 # We need all commits to find docs/ changes |
| 22 |
- name: Set up Git user |
| 23 |
run: | |
| 24 |
git config user.name "Automated" |
| 25 |
git config user.email "[email protected]" |
| 26 |
- name: Create stable branch if it does not yet exist |
| 27 |
run: | |
| 28 |
if ! git ls-remote --heads origin stable | grep -qE '\bstable\b'; then |
| 29 |
# Make sure we have all tags locally |
| 30 |
git fetch --tags --quiet |
| 31 |
|
| 32 |
# Latest tag that is just numbers and dots (optionally prefixed with 'v') |
| 33 |
# e.g., 0.65.2 or v0.65.2 — excludes 1.0a20, 1.0-rc1, etc. |
| 34 |
LATEST_RELEASE=$( |
| 35 |
git tag -l --sort=-v:refname \ |
| 36 |
| grep -E '^v?[0-9]+(\.[0-9]+){1,3}$' \ |
| 37 |
| head -n1 |
| 38 |
) |
| 39 |
|
| 40 |
git checkout -b stable |
| 41 |
|
| 42 |
# If there are any stable releases, copy docs/ from the most recent |
| 43 |
if [ -n "$LATEST_RELEASE" ]; then |
| 44 |
rm -rf docs/ |
| 45 |
git checkout "$LATEST_RELEASE" -- docs/ || true |
| 46 |
fi |
| 47 |
|
| 48 |
git commit -m "Populate docs/ from $LATEST_RELEASE" || echo "No changes" |
| 49 |
git push -u origin stable |
| 50 |
fi |
| 51 |
# After the first non-prerelease 1.0 release, disable this workflow on 0.65.x |
| 52 |
# (both release resets and !stable-docs updates), along with the docs.db |
| 53 |
# upload in publish.yml. Later 0.65 releases must not replace the 1.0 docs. |
| 54 |
- name: Handle Release |
| 55 |
if: github.event_name == 'release' && !github.event.release.prerelease |
| 56 |
run: | |
| 57 |
git fetch --all |
| 58 |
git checkout stable |
| 59 |
git reset --hard ${GITHUB_REF#refs/tags/} |
| 60 |
git push origin stable --force |
| 61 |
- name: Handle documentation update |
| 62 |
if: github.event_name == 'push' && contains(github.event.head_commit.message, '!stable-docs') |
| 63 |
run: | |
| 64 |
git fetch origin |
| 65 |
git checkout -b stable origin/stable |
| 66 |
# Get the list of modified files in docs/ from the current commit |
| 67 |
FILES=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} -- docs/) |
| 68 |
# Check if the list of files is non-empty |
| 69 |
if [[ -n "$FILES" ]]; then |
| 70 |
# Checkout those files to the stable branch to over-write with their contents |
| 71 |
for FILE in $FILES; do |
| 72 |
git checkout ${{ github.sha }} -- $FILE |
| 73 |
done |
| 74 |
git add docs/ |
| 75 |
git commit -m "Doc changes from ${{ github.sha }}" |
| 76 |
git push origin stable |
| 77 |
else |
| 78 |
echo "No changes to docs/ in this commit." |
| 79 |
exit 0 |
| 80 |
fi |