|
| 1 | +#!/usr/bin/env bash |
| 2 | +# update-arch-docs-workflows.sh |
| 3 | +# |
| 4 | +# Updates arch-docs.yml in all repos listed in repos.yaml to push output |
| 5 | +# to the central GraphTechnologyDevelopers/graphtechnologydevelopers.github.io |
| 6 | +# site instead of deploying to individual GitHub Pages. |
| 7 | +# |
| 8 | +# Prerequisites: |
| 9 | +# - gh CLI authenticated with supermodeltools org access |
| 10 | +# - BOT_TOKEN secret must be set on each repo (PAT with write access to |
| 11 | +# GraphTechnologyDevelopers/graphtechnologydevelopers.github.io) |
| 12 | +# |
| 13 | +# Usage: |
| 14 | +# BOT_TOKEN=ghp_... ./update-arch-docs-workflows.sh |
| 15 | + |
| 16 | +set -euo pipefail |
| 17 | + |
| 18 | +ORG="supermodeltools" |
| 19 | + |
| 20 | +WORKFLOW_CONTENT='name: Architecture Docs |
| 21 | +
|
| 22 | +on: |
| 23 | + push: |
| 24 | + branches: [main, master] |
| 25 | + workflow_dispatch: |
| 26 | +
|
| 27 | +permissions: |
| 28 | + contents: read |
| 29 | +
|
| 30 | +jobs: |
| 31 | + build-and-deploy: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | +
|
| 36 | + - uses: supermodeltools/arch-docs@main |
| 37 | + id: docs |
| 38 | + with: |
| 39 | + supermodel-api-key: ${{ secrets.SUPERMODEL_API_KEY }} |
| 40 | + base-url: https://repos.supermodeltools.com |
| 41 | +
|
| 42 | + - name: Deploy to central site |
| 43 | + env: |
| 44 | + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} |
| 45 | + REPO_NAME: ${{ github.event.repository.name }} |
| 46 | + run: | |
| 47 | + git config --global user.name "supermodel-bot" |
| 48 | + git config --global user.email "bot@supermodeltools.com" |
| 49 | + git clone https://x-access-token:${BOT_TOKEN}@github.com/GraphTechnologyDevelopers/graphtechnologydevelopers.github.io.git central-site |
| 50 | + rm -rf central-site/site/${REPO_NAME} |
| 51 | + mkdir -p central-site/site/${REPO_NAME} |
| 52 | + cp -r arch-docs-output/. central-site/site/${REPO_NAME}/ |
| 53 | + cd central-site |
| 54 | + git add site/${REPO_NAME}/ |
| 55 | + git diff --staged --quiet && echo "No changes" && exit 0 |
| 56 | + git commit -m "Deploy arch-docs for ${REPO_NAME}" |
| 57 | + for i in 1 2 3 4 5; do |
| 58 | + git push && break |
| 59 | + echo "Push failed, retrying in ${i}0s..." |
| 60 | + sleep $((i * 10)) |
| 61 | + git pull --rebase origin main |
| 62 | + done' |
| 63 | + |
| 64 | +# Read repo names from repos.yaml |
| 65 | +REPOS=$(grep "^ - name:" repos.yaml | awk '{print $3}') |
| 66 | + |
| 67 | +for REPO_NAME in $REPOS; do |
| 68 | + FORK="${ORG}/${REPO_NAME}" |
| 69 | + echo "=== Updating ${FORK} ===" |
| 70 | + |
| 71 | + # Set BOT_TOKEN secret if provided |
| 72 | + if [ -n "${BOT_TOKEN:-}" ]; then |
| 73 | + echo " Setting BOT_TOKEN secret..." |
| 74 | + gh secret set BOT_TOKEN --repo "${FORK}" --body "${BOT_TOKEN}" |
| 75 | + else |
| 76 | + echo " Warning: BOT_TOKEN not set in environment, skipping secret update" |
| 77 | + fi |
| 78 | + |
| 79 | + ENCODED=$(echo -n "${WORKFLOW_CONTENT}" | base64) |
| 80 | + DEFAULT_BRANCH=$(gh api "repos/${FORK}" --jq '.default_branch' 2>/dev/null || echo "main") |
| 81 | + EXISTING_SHA=$(gh api "repos/${FORK}/contents/.github/workflows/arch-docs.yml" --jq '.sha' 2>/dev/null || echo "") |
| 82 | + |
| 83 | + if [ -n "${EXISTING_SHA}" ]; then |
| 84 | + gh api --method PUT "repos/${FORK}/contents/.github/workflows/arch-docs.yml" \ |
| 85 | + -f message="Update arch-docs workflow to deploy to central site" \ |
| 86 | + -f content="${ENCODED}" \ |
| 87 | + -f branch="${DEFAULT_BRANCH}" \ |
| 88 | + -f sha="${EXISTING_SHA}" \ |
| 89 | + --silent |
| 90 | + echo " Updated arch-docs.yml" |
| 91 | + else |
| 92 | + echo " No arch-docs.yml found in ${FORK}, skipping" |
| 93 | + fi |
| 94 | + |
| 95 | + echo "" |
| 96 | +done |
| 97 | + |
| 98 | +echo "=== Done! Run workflows manually to trigger initial deploys: ===" |
| 99 | +for REPO_NAME in $REPOS; do |
| 100 | + echo " gh workflow run arch-docs.yml --repo ${ORG}/${REPO_NAME}" |
| 101 | +done |
0 commit comments