diff --git a/.github/workflows/build-index.yml b/.github/workflows/build-index.yml index d8d8500f9..ebfad978e 100644 --- a/.github/workflows/build-index.yml +++ b/.github/workflows/build-index.yml @@ -3,7 +3,13 @@ name: Build Index on: push: branches: [main] - paths: [repos.yaml, generate-index.go, go.mod, go.sum, .github/workflows/build-index.yml] + paths: + - repos.yaml + - generate-index.go + - go.mod + - go.sum + - .github/workflows/build-index.yml + - site/** workflow_dispatch: permissions: diff --git a/generate-index.go b/generate-index.go index 2f11e3b98..c063362a1 100644 --- a/generate-index.go +++ b/generate-index.go @@ -82,13 +82,14 @@ func main() { func generateSitemap(cfg Config) error { var b strings.Builder b.WriteString(`` + "\n") - b.WriteString(`` + "\n") + b.WriteString(`` + "\n") + b.WriteString(fmt.Sprintf(" \n %s/\n 1.0\n \n", baseURL)) for _, cat := range cfg.Categories { for _, repo := range cat.Repos { - b.WriteString(fmt.Sprintf(" \n %s/%s/sitemap.xml\n \n", baseURL, url.PathEscape(repo.Name))) + b.WriteString(fmt.Sprintf(" \n %s/%s/\n 0.8\n \n", baseURL, url.PathEscape(repo.Name))) } } - b.WriteString("\n") + b.WriteString("\n") return os.WriteFile("site/sitemap.xml", []byte(b.String()), 0644) } @@ -119,6 +120,10 @@ func generateRepoPages(cfg Config) error { for _, cat := range cfg.Categories { for _, repo := range cat.Repos { dir := fmt.Sprintf("site/%s", url.PathEscape(repo.Name)) + // Skip if arch-docs have already been deployed to this directory + if _, err := os.Stat(fmt.Sprintf("%s/index.html", dir)); err == nil { + continue + } if err := os.MkdirAll(dir, 0755); err != nil { return fmt.Errorf("creating dir %s: %w", dir, err) } diff --git a/setup-community-repos.sh b/setup-community-repos.sh index 4166ceccb..39243162b 100755 --- a/setup-community-repos.sh +++ b/setup-community-repos.sh @@ -51,20 +51,11 @@ on: workflow_dispatch: permissions: - contents: write - pages: write - id-token: write - -concurrency: - group: pages - cancel-in-progress: true + contents: read jobs: build-and-deploy: runs-on: ubuntu-latest - environment: - name: github-pages - url: ${{ steps.deploy.outputs.page_url }} steps: - uses: actions/checkout@v4 @@ -72,15 +63,29 @@ jobs: id: docs with: supermodel-api-key: ${{ secrets.SUPERMODEL_API_KEY }} - - - uses: actions/configure-pages@v5 - - - uses: actions/upload-pages-artifact@v3 - with: - path: ./arch-docs-output - - - uses: actions/deploy-pages@v4 - id: deploy' + base-url: https://repos.supermodeltools.com + + - name: Deploy to central site + env: + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + REPO_NAME: ${{ github.event.repository.name }} + run: | + git config --global user.name "supermodel-bot" + git config --global user.email "bot@supermodeltools.com" + git clone https://x-access-token:${BOT_TOKEN}@github.com/GraphTechnologyDevelopers/graphtechnologydevelopers.github.io.git central-site + rm -rf central-site/site/${REPO_NAME} + mkdir -p central-site/site/${REPO_NAME} + cp -r arch-docs-output/. central-site/site/${REPO_NAME}/ + cd central-site + git add site/${REPO_NAME}/ + git diff --staged --quiet && echo "No changes" && exit 0 + git commit -m "Deploy arch-docs for ${REPO_NAME}" + for i in 1 2 3 4 5; do + git push && break + echo "Push failed, retrying in ${i}0s..." + sleep $((i * 10)) + git pull --rebase origin main + done' for UPSTREAM in "${REPOS[@]}"; do REPO_NAME="${UPSTREAM##*/}" diff --git a/update-arch-docs-workflows.sh b/update-arch-docs-workflows.sh new file mode 100755 index 000000000..abb061617 --- /dev/null +++ b/update-arch-docs-workflows.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash +# update-arch-docs-workflows.sh +# +# Updates arch-docs.yml in all repos listed in repos.yaml to push output +# to the central GraphTechnologyDevelopers/graphtechnologydevelopers.github.io +# site instead of deploying to individual GitHub Pages. +# +# Prerequisites: +# - gh CLI authenticated with supermodeltools org access +# - BOT_TOKEN secret must be set on each repo (PAT with write access to +# GraphTechnologyDevelopers/graphtechnologydevelopers.github.io) +# +# Usage: +# BOT_TOKEN=ghp_... ./update-arch-docs-workflows.sh + +set -euo pipefail + +ORG="supermodeltools" + +WORKFLOW_CONTENT='name: Architecture Docs + +on: + push: + branches: [main, master] + workflow_dispatch: + +permissions: + contents: read + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: supermodeltools/arch-docs@main + id: docs + with: + supermodel-api-key: ${{ secrets.SUPERMODEL_API_KEY }} + base-url: https://repos.supermodeltools.com + + - name: Deploy to central site + env: + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + REPO_NAME: ${{ github.event.repository.name }} + run: | + git config --global user.name "supermodel-bot" + git config --global user.email "bot@supermodeltools.com" + git clone https://x-access-token:${BOT_TOKEN}@github.com/GraphTechnologyDevelopers/graphtechnologydevelopers.github.io.git central-site + rm -rf central-site/site/${REPO_NAME} + mkdir -p central-site/site/${REPO_NAME} + cp -r arch-docs-output/. central-site/site/${REPO_NAME}/ + cd central-site + git add site/${REPO_NAME}/ + git diff --staged --quiet && echo "No changes" && exit 0 + git commit -m "Deploy arch-docs for ${REPO_NAME}" + for i in 1 2 3 4 5; do + git push && break + echo "Push failed, retrying in ${i}0s..." + sleep $((i * 10)) + git pull --rebase origin main + done' + +# Read repo names from repos.yaml +REPOS=$(grep "^ - name:" repos.yaml | awk '{print $3}') + +for REPO_NAME in $REPOS; do + FORK="${ORG}/${REPO_NAME}" + echo "=== Updating ${FORK} ===" + + # Set BOT_TOKEN secret if provided + if [ -n "${BOT_TOKEN:-}" ]; then + echo " Setting BOT_TOKEN secret..." + gh secret set BOT_TOKEN --repo "${FORK}" --body "${BOT_TOKEN}" + else + echo " Warning: BOT_TOKEN not set in environment, skipping secret update" + fi + + ENCODED=$(echo -n "${WORKFLOW_CONTENT}" | base64) + DEFAULT_BRANCH=$(gh api "repos/${FORK}" --jq '.default_branch' 2>/dev/null || echo "main") + EXISTING_SHA=$(gh api "repos/${FORK}/contents/.github/workflows/arch-docs.yml" --jq '.sha' 2>/dev/null || echo "") + + if [ -n "${EXISTING_SHA}" ]; then + gh api --method PUT "repos/${FORK}/contents/.github/workflows/arch-docs.yml" \ + -f message="Update arch-docs workflow to deploy to central site" \ + -f content="${ENCODED}" \ + -f branch="${DEFAULT_BRANCH}" \ + -f sha="${EXISTING_SHA}" \ + --silent + echo " Updated arch-docs.yml" + else + echo " No arch-docs.yml found in ${FORK}, skipping" + fi + + echo "" +done + +echo "=== Done! Run workflows manually to trigger initial deploys: ===" +for REPO_NAME in $REPOS; do + echo " gh workflow run arch-docs.yml --repo ${ORG}/${REPO_NAME}" +done