Skip to content

Commit f338208

Browse files
authored
Merge pull request #2306 from hydephp/new-documentation-mirror
Add documentation sync workflow
2 parents 96c2ed7 + 6522038 commit f338208

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Sync documentation mirror
2+
3+
on:
4+
push:
5+
branches: [ master, '1.x' ]
6+
paths:
7+
- 'docs/**'
8+
- '.github/workflows/sync-documentation-mirror.yml'
9+
10+
# Avoid overlapping runs trying to push at once
11+
concurrency:
12+
group: sync-docs-${{ github.ref }}
13+
cancel-in-progress: false
14+
15+
jobs:
16+
sync:
17+
if: github.repository == 'hydephp/develop'
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout monorepo
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Determine target subdirectory (1.x vs 2.x)
26+
id: vars
27+
run: |
28+
if [ "${GITHUB_REF_NAME}" = "master" ]; then
29+
echo "TARGET_SUBDIR=2.x" >> "$GITHUB_OUTPUT"
30+
elif [ "${GITHUB_REF_NAME}" = "1.x" ]; then
31+
echo "TARGET_SUBDIR=1.x" >> "$GITHUB_OUTPUT"
32+
else
33+
echo "Unsupported branch: ${GITHUB_REF_NAME}"
34+
exit 78
35+
fi
36+
37+
- name: Clone target repo (hydephp/docs)
38+
env:
39+
TOKEN: ${{ secrets.DOCS_SYNC_TOKEN }}
40+
run: |
41+
set -euo pipefail
42+
if [ -z "${TOKEN}" ]; then
43+
echo "❌ Missing DOCS_SYNC_TOKEN secret with repo access to hydephp/docs."
44+
exit 1
45+
fi
46+
git clone --depth 1 "https://x-access-token:${TOKEN}@github.com/hydephp/docs.git" target-docs
47+
48+
- name: Replace target directory with monorepo /docs
49+
run: |
50+
set -euo pipefail
51+
DEST="target-docs/${{ steps.vars.outputs.TARGET_SUBDIR }}"
52+
# Remove and recreate the target subdir to ensure a full replacement
53+
rm -rf "$DEST"
54+
mkdir -p "$DEST"
55+
# Mirror monorepo docs into the dest (delete removed files)
56+
rsync -a --delete --exclude='.git' ./docs/ "$DEST/"
57+
58+
- name: Commit & push if there are changes
59+
env:
60+
GIT_AUTHOR_NAME: hydephp-bot
61+
GIT_AUTHOR_EMAIL: bot@hydephp.com
62+
GIT_COMMITTER_NAME: hydephp-bot
63+
GIT_COMMITTER_EMAIL: bot@hydephp.com
64+
TOKEN: ${{ secrets.DOCS_SYNC_TOKEN }}
65+
run: |
66+
set -euo pipefail
67+
cd target-docs
68+
git add -A
69+
if git diff --cached --quiet; then
70+
echo "✅ No changes to sync."
71+
exit 0
72+
fi
73+
git commit -m "Sync docs from ${GITHUB_REPOSITORY}@${GITHUB_SHA} (${GITHUB_REF_NAME}) → ${{ steps.vars.outputs.TARGET_SUBDIR }}"
74+
# Push to main on hydephp/docs
75+
git push origin HEAD:main

0 commit comments

Comments
 (0)