Skip to content

Commit 09cddea

Browse files
bundling pre-indexed repos
1 parent 273c5a0 commit 09cddea

7 files changed

Lines changed: 1072 additions & 1 deletion

File tree

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
name: Generate Bundle On-Demand
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
repo_url:
7+
description: 'GitHub Repository URL (e.g., https://github.com/owner/repo)'
8+
required: true
9+
type: string
10+
repo_owner:
11+
description: 'Repository Owner (auto-filled by API)'
12+
required: false
13+
type: string
14+
repo_name:
15+
description: 'Repository Name (auto-filled by API)'
16+
required: false
17+
type: string
18+
19+
permissions:
20+
contents: write # Required to create/update releases
21+
22+
jobs:
23+
generate-bundle:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Checkout CodeGraphContext
28+
uses: actions/checkout@v4
29+
30+
- name: Set up Python
31+
uses: actions/setup-python@v5
32+
with:
33+
python-version: '3.12'
34+
35+
- name: Install CodeGraphContext
36+
run: |
37+
pip install -e .
38+
pip install tree-sitter tree-sitter-language-pack
39+
40+
- name: Parse repository URL
41+
id: parse-url
42+
run: |
43+
REPO_URL="${{ github.event.inputs.repo_url }}"
44+
45+
# Extract owner and repo name from URL
46+
if [[ "$REPO_URL" =~ github\.com/([^/]+)/([^/]+) ]]; then
47+
OWNER="${BASH_REMATCH[1]}"
48+
REPO="${BASH_REMATCH[2]}"
49+
# Remove .git suffix if present
50+
REPO="${REPO%.git}"
51+
else
52+
echo "Error: Invalid GitHub URL format"
53+
exit 1
54+
fi
55+
56+
echo "owner=$OWNER" >> $GITHUB_OUTPUT
57+
echo "repo=$REPO" >> $GITHUB_OUTPUT
58+
echo "Parsed: $OWNER/$REPO"
59+
60+
- name: Checkout target repository
61+
uses: actions/checkout@v4
62+
with:
63+
repository: ${{ steps.parse-url.outputs.owner }}/${{ steps.parse-url.outputs.repo }}
64+
path: target-repo
65+
fetch-depth: 1
66+
67+
- name: Get repository metadata
68+
id: repo-meta
69+
run: |
70+
cd target-repo
71+
72+
# Get commit SHA
73+
COMMIT_SHA=$(git rev-parse HEAD)
74+
COMMIT_SHORT=$(git rev-parse --short HEAD)
75+
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT
76+
echo "commit_short=$COMMIT_SHORT" >> $GITHUB_OUTPUT
77+
78+
# Try to get the latest tag
79+
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "main")
80+
echo "tag=$TAG" >> $GITHUB_OUTPUT
81+
82+
# Get current date
83+
DATE=$(date +%Y%m%d)
84+
echo "date=$DATE" >> $GITHUB_OUTPUT
85+
86+
# Get repository size
87+
REPO_SIZE=$(du -sh . | cut -f1)
88+
echo "repo_size=$REPO_SIZE" >> $GITHUB_OUTPUT
89+
90+
- name: Index repository
91+
id: index
92+
run: |
93+
cd target-repo
94+
echo "🔍 Indexing ${{ steps.parse-url.outputs.owner }}/${{ steps.parse-url.outputs.repo }}..."
95+
96+
# Run indexing with timeout (30 minutes max)
97+
timeout 30m cgc index . || {
98+
echo "Error: Indexing timed out or failed"
99+
exit 1
100+
}
101+
102+
echo "✅ Indexing complete"
103+
104+
- name: Export to .cgc bundle
105+
id: export
106+
run: |
107+
BUNDLE_NAME="${{ steps.parse-url.outputs.repo }}-${{ steps.repo-meta.outputs.tag }}-${{ steps.repo-meta.outputs.commit_short }}.cgc"
108+
echo "📦 Creating bundle: $BUNDLE_NAME"
109+
110+
cgc bundle export "$BUNDLE_NAME" --repo "$(pwd)/target-repo"
111+
112+
# Get bundle size
113+
BUNDLE_SIZE=$(du -h "$BUNDLE_NAME" | cut -f1)
114+
echo "bundle_name=$BUNDLE_NAME" >> $GITHUB_OUTPUT
115+
echo "bundle_size=$BUNDLE_SIZE" >> $GITHUB_OUTPUT
116+
117+
echo "✅ Bundle created: $BUNDLE_SIZE"
118+
119+
- name: Generate bundle metadata
120+
run: |
121+
cat > bundle-metadata.json <<EOF
122+
{
123+
"repository": "${{ steps.parse-url.outputs.owner }}/${{ steps.parse-url.outputs.repo }}",
124+
"commit": "${{ steps.repo-meta.outputs.commit_sha }}",
125+
"commit_short": "${{ steps.repo-meta.outputs.commit_short }}",
126+
"tag": "${{ steps.repo-meta.outputs.tag }}",
127+
"generated_at": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
128+
"bundle_name": "${{ steps.export.outputs.bundle_name }}",
129+
"bundle_size": "${{ steps.export.outputs.bundle_size }}",
130+
"repo_size": "${{ steps.repo-meta.outputs.repo_size }}",
131+
"workflow_run_id": "${{ github.run_id }}",
132+
"workflow_run_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
133+
}
134+
EOF
135+
136+
cat bundle-metadata.json
137+
138+
- name: Upload bundle as artifact
139+
uses: actions/upload-artifact@v4
140+
with:
141+
name: ${{ steps.parse-url.outputs.repo }}-bundle
142+
path: |
143+
${{ steps.export.outputs.bundle_name }}
144+
bundle-metadata.json
145+
retention-days: 30
146+
147+
- name: Create or update on-demand release
148+
uses: softprops/action-gh-release@v1
149+
with:
150+
tag_name: on-demand-bundles
151+
name: On-Demand Generated Bundles
152+
body: |
153+
# On-Demand Generated Bundles
154+
155+
This release contains bundles generated on-demand by users.
156+
157+
## Latest Bundle
158+
159+
- **Repository**: ${{ steps.parse-url.outputs.owner }}/${{ steps.parse-url.outputs.repo }}
160+
- **Commit**: ${{ steps.repo-meta.outputs.commit_short }}
161+
- **Tag/Version**: ${{ steps.repo-meta.outputs.tag }}
162+
- **Generated**: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
163+
- **Bundle Size**: ${{ steps.export.outputs.bundle_size }}
164+
165+
## Usage
166+
167+
```bash
168+
# Download the bundle
169+
wget https://github.com/${{ github.repository }}/releases/download/on-demand-bundles/${{ steps.export.outputs.bundle_name }}
170+
171+
# Load into your database
172+
cgc load ${{ steps.export.outputs.bundle_name }}
173+
```
174+
175+
---
176+
177+
**Note**: Bundles are kept for 30 days. Popular bundles may be moved to the weekly pre-indexed releases.
178+
files: |
179+
${{ steps.export.outputs.bundle_name }}
180+
bundle-metadata.json
181+
draft: false
182+
prerelease: false
183+
env:
184+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
185+
186+
- name: Update manifest
187+
run: |
188+
echo "📝 Updating bundle manifest..."
189+
190+
# Download existing manifest if it exists
191+
wget https://github.com/${{ github.repository }}/releases/download/on-demand-bundles/manifest.json -O manifest.json 2>/dev/null || echo '{"bundles":[]}' > manifest.json
192+
193+
# Add new bundle to manifest
194+
cat manifest.json | jq --argjson new '{
195+
"repo": "${{ steps.parse-url.outputs.owner }}/${{ steps.parse-url.outputs.repo }}",
196+
"bundle_name": "${{ steps.export.outputs.bundle_name }}",
197+
"commit": "${{ steps.repo-meta.outputs.commit_short }}",
198+
"tag": "${{ steps.repo-meta.outputs.tag }}",
199+
"generated_at": "'$(date -u +"%Y-%m-%dT%H:%M:%SZ")'",
200+
"download_url": "https://github.com/${{ github.repository }}/releases/download/on-demand-bundles/${{ steps.export.outputs.bundle_name }}",
201+
"size": "${{ steps.export.outputs.bundle_size }}",
202+
"status": "ready"
203+
}' '.bundles += [$new]' > manifest-updated.json
204+
205+
mv manifest-updated.json manifest.json
206+
207+
echo "✅ Manifest updated"
208+
209+
- name: Upload updated manifest
210+
uses: softprops/action-gh-release@v1
211+
with:
212+
tag_name: on-demand-bundles
213+
files: manifest.json
214+
env:
215+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
216+
217+
- name: Summary
218+
run: |
219+
echo "## 🎉 Bundle Generation Complete!" >> $GITHUB_STEP_SUMMARY
220+
echo "" >> $GITHUB_STEP_SUMMARY
221+
echo "**Repository**: ${{ steps.parse-url.outputs.owner }}/${{ steps.parse-url.outputs.repo }}" >> $GITHUB_STEP_SUMMARY
222+
echo "**Bundle**: ${{ steps.export.outputs.bundle_name }}" >> $GITHUB_STEP_SUMMARY
223+
echo "**Size**: ${{ steps.export.outputs.bundle_size }}" >> $GITHUB_STEP_SUMMARY
224+
echo "" >> $GITHUB_STEP_SUMMARY
225+
echo "### Download" >> $GITHUB_STEP_SUMMARY
226+
echo '```bash' >> $GITHUB_STEP_SUMMARY
227+
echo "wget https://github.com/${{ github.repository }}/releases/download/on-demand-bundles/${{ steps.export.outputs.bundle_name }}" >> $GITHUB_STEP_SUMMARY
228+
echo "cgc load ${{ steps.export.outputs.bundle_name }}" >> $GITHUB_STEP_SUMMARY
229+
echo '```' >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)