-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-community-repos.sh
More file actions
executable file
·155 lines (133 loc) · 4.6 KB
/
setup-community-repos.sh
File metadata and controls
executable file
·155 lines (133 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env bash
# setup-community-repos.sh
#
# Fork community repos into supermodeltools org, set up arch-docs workflow,
# enable GitHub Pages, and trigger the first build.
#
# Prerequisites:
# - gh CLI authenticated with supermodeltools org admin access
# - SUPERMODEL_API_KEY environment variable set
#
# Usage:
# SUPERMODEL_API_KEY=sk-... ./setup-community-repos.sh
set -euo pipefail
if [ -z "${SUPERMODEL_API_KEY:-}" ]; then
echo "Error: SUPERMODEL_API_KEY environment variable is required"
exit 1
fi
ORG="supermodeltools"
REPOS=(
"facebook/react"
"vercel/next.js"
"vuejs/vue"
"sveltejs/svelte"
"expressjs/express"
"fastify/fastify"
"pallets/flask"
"django/django"
"golang/go"
"rust-lang/rust"
"denoland/deno"
"oven-sh/bun"
"langchain-ai/langchain"
"huggingface/transformers"
"anthropics/anthropic-sdk-python"
"supabase/supabase"
"drizzle-team/drizzle-orm"
"tailwindlabs/tailwindcss"
"shadcn-ui/ui"
"astro-build/astro"
)
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'
for UPSTREAM in "${REPOS[@]}"; do
REPO_NAME="${UPSTREAM##*/}"
FORK="${ORG}/${REPO_NAME}"
echo "=== Setting up ${UPSTREAM} as ${FORK} ==="
# 1. Fork the repo (skip if already exists)
if gh repo view "${FORK}" &>/dev/null; then
echo " Fork ${FORK} already exists, skipping fork step"
else
echo " Forking ${UPSTREAM} into ${ORG}..."
gh repo fork "${UPSTREAM}" --org "${ORG}" --clone=false
sleep 2
fi
# 2. Set the SUPERMODEL_API_KEY secret
echo " Setting SUPERMODEL_API_KEY secret..."
gh secret set SUPERMODEL_API_KEY --repo "${FORK}" --body "${SUPERMODEL_API_KEY}"
# 3. Detect default branch
DEFAULT_BRANCH=$(gh api "repos/${FORK}" --jq '.default_branch')
echo " Default branch: ${DEFAULT_BRANCH}"
# 4. Push the arch-docs workflow file
echo " Creating arch-docs workflow..."
ENCODED=$(echo -n "${WORKFLOW_CONTENT}" | base64)
# Check if workflow already exists
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="Add arch-docs workflow" \
-f content="${ENCODED}" \
-f branch="${DEFAULT_BRANCH}" \
-f sha="${EXISTING_SHA}" \
--silent
else
gh api --method PUT "repos/${FORK}/contents/.github/workflows/arch-docs.yml" \
-f message="Add arch-docs workflow" \
-f content="${ENCODED}" \
-f branch="${DEFAULT_BRANCH}" \
--silent
fi
# 5. Enable GitHub Pages with Actions as source
echo " Enabling GitHub Pages..."
gh api --method POST "repos/${FORK}/pages" \
-f build_type="workflow" \
--silent 2>/dev/null || \
gh api --method PUT "repos/${FORK}/pages" \
-f build_type="workflow" \
--silent 2>/dev/null || \
echo " (Pages may already be configured)"
# 6. Trigger the workflow
echo " Triggering arch-docs workflow..."
gh workflow run arch-docs.yml --repo "${FORK}" --ref "${DEFAULT_BRANCH}" 2>/dev/null || \
echo " (Workflow trigger may need a moment, try manually if needed)"
echo " Done: ${FORK}"
echo ""
done
echo "=== All community repos set up! ==="
echo "Docs will deploy at repos.supermodeltools.com/{repo}/ as workflows complete."