Skip to content

Commit c3c62f3

Browse files
authored
Add stable branch syncing and webhook for readthedocs build triggering (#89)
This change adds a periodic GitHub Action that pulls the main branch, checks out the latest release of Slang for the slang submodule (instead of using the master branch), and then force pushes the updated main branch and release submodule to the branch "stable", which will be used for the stable branch of the readthedocs site. readthedocs does not recognize pushes from GitHub Actions bots, so the final step is to post a token to the site's webhook to directly trigger a new build. This change also adds that step to the submodule sync action.
1 parent 8c864a4 commit c3c62f3

File tree

2 files changed

+104
-5
lines changed

2 files changed

+104
-5
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Sync Stable Branch with Slang Release
2+
3+
on:
4+
schedule:
5+
# Run at 3:00 AM UTC every day
6+
- cron: '0 3 * * *'
7+
workflow_dispatch: # Allow manual trigger
8+
9+
jobs:
10+
sync-stable-branch:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
steps:
15+
- name: Checkout main branch
16+
uses: actions/checkout@v4
17+
with:
18+
ref: main # Explicitly checkout main
19+
# Fetch all history for all branches and tags
20+
fetch-depth: 0
21+
# Get submodules, but don't update them yet
22+
submodules: 'recursive'
23+
24+
- name: Set up Git
25+
run: |
26+
git config --global user.name 'Read the Docs Bot'
27+
git config --global user.email 'rtd-bot@shader-slang.com'
28+
29+
- name: Get latest slang release tag
30+
id: slang_latest_tag
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Provide token explicitly for gh
33+
run: |
34+
LATEST_TAG=$(gh release view --repo shader-slang/slang --json tagName --jq .tagName)
35+
if [ -z "$LATEST_TAG" ]; then
36+
echo "Failed to fetch latest slang release tag using gh"
37+
exit 1
38+
fi
39+
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
40+
echo "Fetched latest slang tag: $LATEST_TAG"
41+
42+
- name: Update slang submodule to latest release tag
43+
run: |
44+
pushd docs/external/slang
45+
git fetch --tags origin
46+
git checkout ${{ steps.slang_latest_tag.outputs.tag }}
47+
popd
48+
echo "Checked out tag ${{ steps.slang_latest_tag.outputs.tag }} in docs/external/slang"
49+
50+
- name: Check for changes
51+
id: check_changes
52+
run: |
53+
# Only stage the slang submodule, as the others are already updated
54+
git add docs/external/slang
55+
56+
# Check if the index differs from HEAD
57+
# git diff --cached --quiet exits 0 if no diff, 1 if diff
58+
if ! git diff --cached --quiet; then
59+
echo "Changes detected in submodule references."
60+
echo "changes=true" >> $GITHUB_OUTPUT
61+
else
62+
echo "No changes detected in submodule references."
63+
echo "changes=false" >> $GITHUB_OUTPUT
64+
# If no changes, reset the index in case unrelated changes were staged
65+
git reset HEAD --quiet
66+
fi
67+
68+
- name: Commit and push changes to stable branch
69+
if: steps.check_changes.outputs.changes == 'true'
70+
run: |
71+
git commit -m "Sync stable to release (slang@${{ steps.slang_latest_tag.outputs.tag }})"
72+
git push origin HEAD:stable --force
73+
echo "Committed and force-pushed updates to stable branch."
74+
75+
- name: Trigger Read the Docs Build on stable branch update
76+
if: steps.check_changes.outputs.changes == 'true'
77+
env:
78+
RTD_WEBHOOK_SECRET: ${{ secrets.RTD_WEBHOOK_SECRET }}
79+
run: |
80+
curl -X POST \
81+
-H "Authorization: token $RTD_WEBHOOK_SECRET" \
82+
https://readthedocs.org/api/v2/webhook/slang-documentation/296117/
83+
echo "Triggered Read the Docs build."

.github/workflows/update-submodules.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222

2323
- name: Set up Git
2424
run: |
25-
git config --global user.name 'github-actions'
26-
git config --global user.email 'github-actions@github.com'
25+
git config --global user.name 'Read the Docs Bot'
26+
git config --global user.email 'rtd-bot@shader-slang.com'
2727
2828
- name: Get default branch
2929
id: default_branch
@@ -42,15 +42,31 @@ jobs:
4242
- name: Check if submodules changed
4343
id: check_changes
4444
run: |
45-
if [[ -n "$(git status --porcelain)" ]]; then
45+
git add -A
46+
47+
# Check if the index differs from HEAD
48+
# git diff --cached --quiet exits 0 if no diff, 1 if diff
49+
if ! git diff --cached --quiet; then
50+
echo "Changes detected in submodule references."
4651
echo "changes=true" >> $GITHUB_OUTPUT
4752
else
53+
echo "No changes detected in submodule references."
4854
echo "changes=false" >> $GITHUB_OUTPUT
55+
# If no changes, reset the index in case unrelated changes were staged
56+
git reset HEAD --quiet
4957
fi
5058
5159
- name: Commit and push changes
5260
if: steps.check_changes.outputs.changes == 'true'
5361
run: |
54-
git add -A
5562
git commit -m "Auto-update submodules"
56-
git push origin ${{ steps.default_branch.outputs.name }}
63+
git push origin ${{ steps.default_branch.outputs.name }}
64+
65+
- name: Trigger Read the Docs Build
66+
if: steps.check_changes.outputs.changes == 'true'
67+
env:
68+
RTD_WEBHOOK_SECRET: ${{ secrets.RTD_WEBHOOK_SECRET }}
69+
run: |
70+
curl -X POST \
71+
-H "Authorization: token $RTD_WEBHOOK_SECRET" \
72+
https://readthedocs.org/api/v2/webhook/slang-documentation/296117/

0 commit comments

Comments
 (0)