Skip to content

Commit 5cc4e92

Browse files
committed
feat(cli): route release asset downloads through proxy API to codebuff-community. Use NEXT_PUBLIC_CODEBUFF_APP_URL to resolve /api/releases/download/{version}/{fileName}; fallback to codebuff.com/api/releases/download when not configured. Generated with Codebuff. Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 3b0691a commit 5cc4e92

File tree

11 files changed

+129
-92
lines changed

11 files changed

+129
-92
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: 'Setup Project'
2+
description: 'Setup Bun, cache dependencies, and install packages'
3+
4+
inputs:
5+
bun-version:
6+
description: 'Bun version to install'
7+
required: false
8+
default: '1.3.0'
9+
10+
runs:
11+
using: 'composite'
12+
steps:
13+
- name: Set up Bun
14+
uses: oven-sh/setup-bun@v2
15+
with:
16+
bun-version: ${{ inputs.bun-version }}
17+
18+
- name: Cache dependencies
19+
uses: actions/cache@v4
20+
with:
21+
path: |
22+
node_modules
23+
*/node_modules
24+
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock*', '**/package.json') }}
25+
restore-keys: |
26+
${{ runner.os }}-deps-${{ hashFiles('**/bun.lock*') }}
27+
${{ runner.os }}-deps-
28+
29+
- name: Install dependencies
30+
shell: bash
31+
run: bun install --frozen-lockfile

.github/knowledge.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,39 @@
1-
# GitHub Actions Knowledge
1+
# GitHub Workflows
2+
3+
## Refactoring Patterns
4+
5+
### Composite Actions
6+
7+
Common setup steps (checkout, Bun setup, caching, installation) have been extracted to `.github/actions/setup-project/action.yml`.
8+
9+
Usage:
10+
11+
```yaml
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
# checkout-specific params
16+
17+
- uses: ./.github/actions/setup-project
18+
```
19+
20+
Note: Checkout must be separate from the composite action to avoid circular dependencies.
21+
22+
### Environment Variables
23+
24+
GitHub API URLs are extracted as environment variables to avoid duplication:
25+
26+
```yaml
27+
env:
28+
GITHUB_API_URL: https://api.github.com/repos/CodebuffAI/codebuff
29+
GITHUB_UPLOADS_URL: https://uploads.github.com/repos/CodebuffAI/codebuff
30+
```
31+
32+
This pattern:
33+
34+
- Reduces duplication across workflow steps
35+
- Makes repository changes easier (single point of change)
36+
- Improves readability and maintainability
237
338
## CI/CD Pipeline Overview
439

.github/workflows/cli-release-build.yml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,15 @@ jobs:
6565
with:
6666
ref: ${{ inputs.checkout-ref || github.sha }}
6767

68+
- uses: ./.github/actions/setup-project
69+
6870
- name: Download staging metadata
6971
if: inputs.artifact-name != ''
7072
uses: actions/download-artifact@v4
7173
with:
7274
name: ${{ inputs.artifact-name }}
7375
path: cli/release-staging/
7476

75-
- name: Set up Bun
76-
uses: oven-sh/setup-bun@v2
77-
with:
78-
bun-version: '1.3.0'
79-
80-
- name: Cache dependencies
81-
uses: actions/cache@v4
82-
with:
83-
path: |
84-
node_modules
85-
*/node_modules
86-
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock*', '**/package.json') }}
87-
restore-keys: |
88-
${{ runner.os }}-deps-${{ hashFiles('**/bun.lock*') }}
89-
${{ runner.os }}-deps-
90-
91-
- name: Install dependencies
92-
run: bun install --frozen-lockfile
93-
9477
- name: Ensure CLI dependencies
9578
run: bun install --frozen-lockfile --cwd cli
9679

.github/workflows/cli-release-staging.yml

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,13 @@ jobs:
2727
token: ${{ secrets.GITHUB_TOKEN }}
2828
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
2929

30-
- name: Set up Bun
31-
uses: oven-sh/setup-bun@v2
32-
with:
33-
bun-version: '1.3.0'
34-
35-
- name: Cache dependencies
36-
uses: actions/cache@v4
37-
with:
38-
path: |
39-
node_modules
40-
*/node_modules
41-
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock*', '**/package.json') }}
42-
restore-keys: |
43-
${{ runner.os }}-deps-${{ hashFiles('**/bun.lock*') }}
44-
${{ runner.os }}-deps-
45-
46-
- name: Install dependencies
47-
run: bun install --frozen-lockfile
30+
- uses: ./.github/actions/setup-project
4831

4932
- name: Calculate staging version
5033
id: bump_version
5134
env:
5235
GITHUB_TOKEN: ${{ secrets.CODEBUFF_GITHUB_TOKEN }}
36+
GITHUB_API_URL: https://api.github.com/repos/CodebuffAI/codebuff-community
5337
run: |
5438
cd cli/release-staging
5539
@@ -58,7 +42,7 @@ jobs:
5842
5943
echo "Fetching latest CLI prerelease from GitHub..."
6044
RELEASES_JSON=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" \
61-
"https://api.github.com/repos/CodebuffAI/codebuff/releases?per_page=100")
45+
"${GITHUB_API_URL}/releases?per_page=100")
6246
6347
LATEST_TAG=$(echo "$RELEASES_JSON" | jq -r '.[] | select(.prerelease == true and (.name // "" | test("Codebuff CLI v"))) | .tag_name' | sort -V | tail -n 1)
6448
@@ -152,12 +136,14 @@ jobs:
152136
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
153137

154138
- name: Clean up old CLI prereleases
139+
env:
140+
GITHUB_API_URL: https://api.github.com/repos/CodebuffAI/codebuff-community
155141
run: |
156142
ONE_WEEK_AGO=$(date -d '7 days ago' -u +%Y-%m-%dT%H:%M:%SZ)
157143
echo "Removing CLI prereleases older than: $ONE_WEEK_AGO"
158144
159145
RELEASES=$(curl -s -H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \
160-
"https://api.github.com/repos/CodebuffAI/codebuff/releases?per_page=100")
146+
"${GITHUB_API_URL}/releases?per_page=100")
161147
162148
if echo "$RELEASES" | jq -e . >/dev/null 2>&1; then
163149
OLD=$(echo "$RELEASES" | jq -r '.[] | select(.prerelease == true and .created_at < "'$ONE_WEEK_AGO'" and (.tag_name | test("^v[0-9].*-beta\\.[0-9]+$"))) | "\(.id):\(.tag_name)"')
@@ -168,7 +154,7 @@ jobs:
168154
echo "$OLD" | while IFS=: read -r RELEASE_ID TAG_NAME; do
169155
curl -s -X DELETE \
170156
-H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \
171-
"https://api.github.com/repos/CodebuffAI/codebuff/releases/$RELEASE_ID"
157+
"${GITHUB_API_URL}/releases/$RELEASE_ID"
172158
done
173159
else
174160
echo "No stale prereleases found."
@@ -192,6 +178,7 @@ jobs:
192178
- name: Create GitHub prerelease
193179
env:
194180
VERSION: ${{ needs.prepare-and-commit-staging.outputs.new_version }}
181+
GITHUB_API_URL: https://api.github.com/repos/CodebuffAI/codebuff
195182
run: |
196183
CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
197184
RELEASE_BODY=$(cat <<'EOF'
@@ -214,7 +201,7 @@ jobs:
214201
-H "Accept: application/vnd.github.v3+json" \
215202
-H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \
216203
-H "Content-Type: application/json" \
217-
https://api.github.com/repos/CodebuffAI/codebuff/releases \
204+
${GITHUB_API_URL}/releases \
218205
-d "{
219206
\"tag_name\": \"v${VERSION}\",
220207
\"name\": \"Codecane v${VERSION} (Staging)\",
@@ -226,9 +213,11 @@ jobs:
226213
- name: Upload release assets
227214
env:
228215
VERSION: ${{ needs.prepare-and-commit-staging.outputs.new_version }}
216+
GITHUB_API_URL: https://api.github.com/repos/CodebuffAI/codebuff
217+
GITHUB_UPLOADS_URL: https://uploads.github.com/repos/CodebuffAI/codebuff
229218
run: |
230219
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \
231-
"https://api.github.com/repos/CodebuffAI/codebuff/releases/tags/v${VERSION}" | jq -r '.id')
220+
"${GITHUB_API_URL}/releases/tags/v${VERSION}" | jq -r '.id')
232221
233222
if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "null" ]; then
234223
echo "Failed to resolve release ID for v${VERSION}"
@@ -243,12 +232,17 @@ jobs:
243232
-H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \
244233
-H "Content-Type: application/octet-stream" \
245234
--data-binary @"$file" \
246-
"https://uploads.github.com/repos/CodebuffAI/codebuff/releases/$RELEASE_ID/assets?name=$FILENAME"
235+
"${GITHUB_UPLOADS_URL}/releases/$RELEASE_ID/assets?name=$FILENAME"
247236
fi
248237
done
249238
250239
publish-staging-npm:
251-
needs: [prepare-and-commit-staging, build-staging-binaries, create-staging-release]
240+
needs:
241+
[
242+
prepare-and-commit-staging,
243+
build-staging-binaries,
244+
create-staging-release,
245+
]
252246
runs-on: ubuntu-latest
253247
permissions:
254248
contents: read

.github/workflows/npm-app-release-build.yml

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,34 +62,14 @@ jobs:
6262
with:
6363
ref: ${{ inputs.checkout-ref || github.sha }}
6464

65+
- uses: ./.github/actions/setup-project
66+
6567
- name: Download updated package
6668
uses: actions/download-artifact@v4
6769
with:
6870
name: ${{ inputs.artifact-name }}
6971
path: ${{ inputs.artifact-name == 'updated-staging-package' && 'npm-app/release-staging/' || 'npm-app/release/' }}
7072

71-
- name: Set up Bun
72-
uses: oven-sh/setup-bun@v2
73-
with:
74-
bun-version: '1.3.0'
75-
76-
# Cache dependencies for speed
77-
- name: Cache dependencies
78-
uses: actions/cache@v4
79-
with:
80-
path: |
81-
node_modules
82-
*/node_modules
83-
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock*', '**/package.json') }}
84-
restore-keys: |
85-
${{ runner.os }}-deps-${{ hashFiles('**/bun.lock*') }}
86-
${{ runner.os }}-deps-
87-
88-
- name: Install dependencies
89-
run: bun install --frozen-lockfile
90-
env:
91-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92-
9373
- name: Set environment variables
9474
env:
9575
SECRETS_CONTEXT: ${{ toJSON(secrets) }}

.github/workflows/npm-app-release-prod.yml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,7 @@ jobs:
2727
with:
2828
token: ${{ secrets.GITHUB_TOKEN }}
2929

30-
- name: Set up Bun
31-
uses: oven-sh/setup-bun@v2
32-
with:
33-
bun-version: '1.3.0'
34-
35-
# Cache dependencies for speed
36-
- name: Cache dependencies
37-
uses: actions/cache@v4
38-
with:
39-
path: |
40-
node_modules
41-
*/node_modules
42-
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock*', '**/package.json') }}
43-
restore-keys: |
44-
${{ runner.os }}-deps-${{ hashFiles('**/bun.lock*') }}
45-
${{ runner.os }}-deps-
46-
47-
- name: Install dependencies
48-
run: bun install --frozen-lockfile
30+
- uses: ./.github/actions/setup-project
4931

5032
- name: Calculate and update production version
5133
id: bump_version

cli/release-staging/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ async function downloadBinary(version) {
240240
throw new Error(`Unsupported platform: ${process.platform} ${process.arch}`)
241241
}
242242

243-
const downloadUrl = `https://github.com/CodebuffAI/codebuff/releases/download/v${version}/${fileName}`
243+
const downloadUrl = `${process.env.NEXT_PUBLIC_CODEBUFF_APP_URL || 'https://codebuff.com'}/api/releases/download/${version}/${fileName}`
244244

245245
fs.mkdirSync(CONFIG.configDir, { recursive: true })
246246

npm-app/release-staging/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,10 @@ async function downloadBinary(version) {
250250
throw new Error(`Unsupported platform: ${process.platform} ${process.arch}`)
251251
}
252252

253-
// For now, we get version info from npm but still download binaries from GitHub
254-
// TODO: This assumes GitHub releases still exist with the same naming convention
255-
const downloadUrl = `https://github.com/CodebuffAI/codebuff-community/releases/download/v${version}/${fileName}`
253+
// Use proxy endpoint that handles version mapping from npm to GitHub releases
254+
const downloadUrl = process.env.NEXT_PUBLIC_CODEBUFF_APP_URL
255+
? `${process.env.NEXT_PUBLIC_CODEBUFF_APP_URL}/api/releases/download/${version}/${fileName}`
256+
: `https://codebuff.com/api/releases/download/${version}/${fileName}`
256257

257258
// Ensure config directory exists
258259
fs.mkdirSync(CONFIG.configDir, { recursive: true })

npm-app/release/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ async function downloadBinary(version) {
215215
throw new Error(`Unsupported platform: ${process.platform} ${process.arch}`)
216216
}
217217

218-
const downloadUrl = `https://github.com/${CONFIG.githubRepo}/releases/download/v${version}/${fileName}`
218+
// Use proxy endpoint that handles version mapping
219+
const downloadUrl = process.env.NEXT_PUBLIC_CODEBUFF_APP_URL
220+
? `${process.env.NEXT_PUBLIC_CODEBUFF_APP_URL}/api/releases/download/${version}/${fileName}`
221+
: `https://codebuff.com/api/releases/download/${version}/${fileName}`
219222

220223
// Ensure config directory exists
221224
fs.mkdirSync(CONFIG.configDir, { recursive: true })

web/next.config.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const nextConfig = {
3232
'pino-pretty',
3333
'encoding',
3434
'perf_hooks',
35-
'async_hooks'
35+
'async_hooks',
3636
)
3737

3838
// Suppress contentlayer webpack cache warnings
@@ -125,6 +125,12 @@ const nextConfig = {
125125
destination: 'https://discord.gg/mcWTGjgTj3',
126126
permanent: false,
127127
},
128+
{
129+
source: '/releases',
130+
destination:
131+
'https://github.com/CodebuffAI/codebuff-community/releases',
132+
permanent: false,
133+
},
128134
]
129135
},
130136
images: {

0 commit comments

Comments
 (0)