Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .github/workflows/sync-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Sync Docs to Central Repo

on:
workflow_dispatch:
push:
branches:
- main
- staging
paths:
- 'squadcastv1/docs/**'
- 'squadcastv1/*.md'

jobs:
sync-docs:
runs-on: ubuntu-latest

env:
SDK_LANG: python
DOCS_PATH: squadcastv1/docs
CENTRAL_REPO: bhattu-gauravv/squadcast-sdk-docs

steps:
- name: Checkout SDK repo
uses: actions/checkout@v4

- name: Checkout central docs repo
uses: actions/checkout@v4
with:
repository: ${{ env.CENTRAL_REPO }}
token: ${{ secrets.DOCS_REPO_PAT }}
path: central-docs
fetch-depth: 0

- name: Create branch and sync docs
id: sync
run: |
# Target staging in central repo when triggered from staging, else main
if [[ "${{ github.ref_name }}" == "staging" ]]; then
BASE_BRANCH="staging"
else
BASE_BRANCH="main"
fi

BRANCH="docs-sync/${SDK_LANG}-${BASE_BRANCH}-${{ github.sha }}"
cd central-docs
git config user.name "speakeasy-docs-bot"
git config user.email "docs-bot@solarwinds.com"

# Ensure base branch exists in central repo; create from main if not
git fetch origin
if git ls-remote --exit-code --heads origin "$BASE_BRANCH" > /dev/null 2>&1; then
git checkout -b "$BASE_BRANCH" "origin/$BASE_BRANCH"
else
git checkout -b "$BASE_BRANCH"
git push origin "$BASE_BRANCH"
fi

git checkout -b "$BRANCH"
rm -rf "${SDK_LANG}/"
mkdir -p "${SDK_LANG}"
cp -r "../${DOCS_PATH}" "${SDK_LANG}/docs"
SDK_ROOT=$(dirname "../${DOCS_PATH}")
find "${SDK_ROOT}" -maxdepth 1 -name "*.md" -exec cp {} "${SDK_LANG}/" \;
git add .
if git diff --staged --quiet; then
echo "No doc changes to sync. Skipping."
echo "has_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git commit -m "docs(${SDK_LANG}): sync from squadcast-sdk-${SDK_LANG} @ ${{ github.sha }}"
git push --force origin "$BRANCH"
echo "has_changes=true" >> "$GITHUB_OUTPUT"

- name: Create Pull Request
if: steps.sync.outputs.has_changes == 'true'
run: |
if [[ "${{ github.ref_name }}" == "staging" ]]; then
BASE_BRANCH="staging"
else
BASE_BRANCH="main"
fi
BRANCH="docs-sync/${SDK_LANG}-${BASE_BRANCH}-${{ github.sha }}"
EXISTING_PR=$(gh pr list --repo "${CENTRAL_REPO}" --head "$BRANCH" --json number --jq '.[0].number' 2>/dev/null || echo "")
if [[ -n "$EXISTING_PR" ]]; then
echo "PR #${EXISTING_PR} already exists for branch $BRANCH, skipping creation."
else
gh pr create \
--repo "${CENTRAL_REPO}" \
--head "$BRANCH" \
--base "$BASE_BRANCH" \
--title "docs(${SDK_LANG}): sync from squadcast-sdk-${SDK_LANG}" \
--body "Automated docs sync triggered by commit [${{ github.sha }}](https://github.com/solarwinds/squadcast-sdk-${SDK_LANG}/commit/${{ github.sha }}) in \`squadcast-sdk-${SDK_LANG}\`."
fi
env:
GH_TOKEN: ${{ secrets.DOCS_REPO_PAT }}