Mirror public docs markdown from braze-docs #31
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: Mirror public docs markdown from braze-docs | |
| on: | |
| schedule: | |
| - cron: "0 6 * * 1-5" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| concurrency: | |
| group: mirror-public-docs-markdown | |
| cancel-in-progress: true | |
| env: | |
| SYNC_BRANCH: docs-sync/public-docs-mirror | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout destination repo on main | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| ref: main | |
| - name: Build sitemap-driven markdown mirror from public docs | |
| run: | | |
| set -euo pipefail | |
| python3 scripts/sync_public_docs_markdown.py | |
| mkdir -p docs | |
| for section in "User Guide" "Developer Guide" "API" "Technology Partners" "What's New"; do | |
| mkdir -p "docs/${section}" | |
| rsync -av --delete "sync-staging/${section}/" "docs/${section}/" | |
| done | |
| - name: Stage mirror output and detect changes | |
| id: diff | |
| run: | | |
| set -euo pipefail | |
| git add -A -- "docs/User Guide" "docs/Developer Guide" "docs/API" "docs/Technology Partners" "docs/What's New" | |
| if git diff --cached --quiet; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| echo "No markdown changes detected." | |
| else | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Write daily changes report | |
| if: steps.diff.outputs.changed == 'true' | |
| run: | | |
| set -euo pipefail | |
| TODAY="$(date -u +%Y-%m-%d)" | |
| LOG_FILE="changes/${TODAY}.md" | |
| mkdir -p changes | |
| CHANGES="$(git diff --cached --name-status -- "docs/User Guide" "docs/Developer Guide" "docs/API" "docs/Technology Partners" "docs/What's New")" | |
| COUNT="$(printf "%s\n" "$CHANGES" | sed '/^$/d' | wc -l | tr -d ' ')" | |
| { | |
| echo "# Daily docs markdown sync - ${TODAY}" | |
| echo | |
| echo "## Summary" | |
| echo "- Source: https://www.braze.com/docs/sitemap.xml" | |
| echo "- Changed files: ${COUNT}" | |
| echo | |
| echo "## Changes" | |
| printf "%s\n" "$CHANGES" | sed '/^$/d' | while IFS=$'\t' read -r status path; do | |
| echo "- ${status} \`${path}\`" | |
| done | |
| } > "$LOG_FILE" | |
| git add "$LOG_FILE" | |
| - name: Commit and push to mirror branch, then open or update the mirror PR | |
| if: steps.diff.outputs.changed == 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| set -euo pipefail | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| TODAY="$(date -u +%Y-%m-%d)" | |
| git commit -m "Mirror public docs markdown from braze.com/docs (${TODAY})" | |
| git push --force "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "HEAD:${SYNC_BRANCH}" | |
| PR_NUMBER="$(gh pr list --state open --base main --head "${SYNC_BRANCH}" --json number --jq '.[0].number // empty')" | |
| PR_TITLE="Mirror public docs markdown from braze.com/docs (${TODAY})" | |
| PR_BODY="Automated daily sync of public-facing markdown from https://www.braze.com/docs into docs/User Guide, docs/Developer Guide, docs/API, docs/Technology Partners, and docs/What's New." | |
| if [ -z "${PR_NUMBER}" ]; then | |
| gh pr create --base main --head "${SYNC_BRANCH}" --title "${PR_TITLE}" --body "${PR_BODY}" | |
| PR_NUMBER="$(gh pr list --state open --base main --head "${SYNC_BRANCH}" --json number --jq '.[0].number')" | |
| echo "Opened mirror PR #${PR_NUMBER}. A Docs team reviewer must approve and merge it to update main." | |
| else | |
| gh pr edit "${PR_NUMBER}" --title "${PR_TITLE}" --body "${PR_BODY}" | |
| echo "Updated existing mirror PR #${PR_NUMBER}. A Docs team reviewer must approve and merge it to update main." | |
| fi |