Sync open source content 🐝 (from 175a023ff7f6a33219f3aa63ab71e81197ea… #92
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sync Public → Private | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "api-design/**" | |
- "docs/**" | |
- "guides/**" | |
- "mcp/**" | |
- "openapi/**" | |
env: | |
SYNC_REPO: ${{ secrets.SYNC_REPO }} | |
BRANCH: main | |
SYNC_DIRS: "api-design docs guides mcp openapi" | |
jobs: | |
sync: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout public repo | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Clone private repo | |
env: | |
TOKEN: ${{ secrets.SERVICE_BOT_TOKEN }} | |
run: | | |
git clone https://x-access-token:${TOKEN}@github.com/${SYNC_REPO}.git private-repo | |
- name: Sync public folders into private repo content paths | |
run: | | |
set -euo pipefail | |
for dir in $SYNC_DIRS; do | |
src_dir="$dir" | |
dest_dir="private-repo/src/content/$dir" | |
if [ -d "$src_dir" ]; then | |
echo "Syncing $src_dir → $dest_dir" | |
rsync -a --delete "$src_dir/" "$dest_dir/" | |
else | |
echo "Warning: $src_dir does not exist, skipping..." | |
fi | |
done | |
- name: Commit and push changes to private repo | |
run: | | |
set -euo pipefail | |
cd private-repo | |
git config user.name "Beezy the bot" | |
git config user.email "marketing@speakeasy.com" | |
git add . | |
if git diff --cached --quiet; then | |
echo "No changes to sync" | |
echo "Nothing synced." >> $GITHUB_STEP_SUMMARY | |
exit 0 | |
fi | |
git commit -m "Sync open source content 🐝 (from $GITHUB_SHA)" | |
if ! git push origin ${BRANCH}; then | |
echo "❌ Push to private repo failed!" >> $GITHUB_STEP_SUMMARY | |
echo "Please check for conflicts or access issues." >> $GITHUB_STEP_SUMMARY | |
exit 1 | |
fi | |
COMMIT_SHA=$(git rev-parse HEAD) | |
echo "### ✅ Synced content to private repo at \`$(date)\`" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "**Commit SHA:** \`${COMMIT_SHA}\`" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "**Grouped file changes:**" >> $GITHUB_STEP_SUMMARY | |
git diff --cached --name-status | awk ' | |
{ | |
split($2, parts, "/"); | |
folder = parts[1]; | |
if (current != folder) { | |
if (current != "") print "" >> ENVIRON["GITHUB_STEP_SUMMARY"]; | |
print "#### `" folder "/`" >> ENVIRON["GITHUB_STEP_SUMMARY"]; | |
current = folder; | |
} | |
print $0 >> ENVIRON["GITHUB_STEP_SUMMARY"]; | |
} | |
' |