Files
copilotkit__copilotkit/.github/workflows/showcase_docs-sync.yml

139 lines
4.5 KiB
YAML

name: "Showcase: Docs Sync"
on:
push:
branches: [main]
paths:
- "docs/content/docs/**"
- "docs/snippets/**"
workflow_dispatch:
concurrency:
group: showcase-docs-sync
cancel-in-progress: false
jobs:
sync-docs:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
pull-requests: write
env:
SHOWCASE_BRANCH: main
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.SHOWCASE_BRANCH }}
fetch-depth: 0
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Fetch main branch
run: git fetch origin main
- name: Run docs sync
id: sync
run: |
set +e
npx tsx showcase/scripts/sync-docs-from-main.ts > sync-output.txt 2>&1
EXIT_CODE=$?
set -e
cat sync-output.txt
if [ $EXIT_CODE -eq 2 ]; then
echo "No changes to sync"
echo "action=none" >> "$GITHUB_OUTPUT"
elif [ $EXIT_CODE -eq 0 ]; then
echo "Clean transforms only — will auto-push"
echo "action=auto_push" >> "$GITHUB_OUTPUT"
elif [ $EXIT_CODE -eq 3 ]; then
echo "Has review items — will auto-push clean transforms + open PR for review items"
echo "action=push_and_pr" >> "$GITHUB_OUTPUT"
else
echo "Sync failed with exit code $EXIT_CODE"
exit 1
fi
# Auto-push clean transforms directly to the showcase branch
- name: Auto-push clean transforms
id: push
if: steps.sync.outputs.action == 'auto_push' || steps.sync.outputs.action == 'push_and_pr'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add showcase/shell/src/content/ showcase/shell/.docs-sync-sha
CHANGED=$(git diff --cached --name-only | wc -l | tr -d ' ')
git commit -m "Auto-sync docs from main ($(date +%Y-%m-%d))" || echo "Nothing to commit"
git push origin "$SHOWCASE_BRANCH"
echo "files_changed=${CHANGED}" >> "$GITHUB_OUTPUT"
- name: Notify Slack (auto-push)
if: steps.sync.outputs.action == 'auto_push'
uses: slackapi/slack-github-action@v2.1.0
with:
webhook: ${{ secrets.SLACK_WEBHOOK_OSS_ALERTS }}
webhook-type: incoming-webhook
payload: |
{ "text": ":arrows_counterclockwise: *Docs sync*: auto-pushed ${{ steps.push.outputs.files_changed || '?' }} file(s) to showcase\n<https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|View run>" }
# Open PR only for files needing human review
- name: Create PR for review items
if: steps.sync.outputs.action == 'push_and_pr'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
SHORT_SHA=$(git rev-parse --short origin/main)
BRANCH="docs-sync-review/${SHORT_SHA}"
git checkout -b "$BRANCH"
# The review-items.txt was written by the sync script
REVIEW_ITEMS=$(cat review-items.txt 2>/dev/null || echo "See sync output for details")
gh pr create \
--title "Docs sync: review needed (${SHORT_SHA})" \
--body "$(cat <<EOF
## Docs Sync — Manual Review Needed
Clean transforms were auto-pushed to \`$SHOWCASE_BRANCH\`. These files need manual attention:
\`\`\`
${REVIEW_ITEMS}
\`\`\`
<details>
<summary>Full sync output</summary>
\`\`\`
$(cat sync-output.txt)
\`\`\`
</details>
---
Generated by Showcase Docs Sync
EOF
)" \
--base "$SHOWCASE_BRANCH" \
--head "$BRANCH"
- name: Notify Slack (review needed)
if: steps.sync.outputs.action == 'push_and_pr'
uses: slackapi/slack-github-action@v2.1.0
with:
webhook: ${{ secrets.SLACK_WEBHOOK_OSS_ALERTS }}
webhook-type: incoming-webhook
payload: |
{ "text": ":warning: *Docs sync*: auto-pushed ${{ steps.push.outputs.files_changed || '?' }} file(s) + opened PR for files needing manual review\n<https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|View run>" }