Skip to content

Commit 4412b5a

Browse files
authored
feat: embedded chat (#6)
* embed and serve a directory of static files in agentapi * make embed * make build * add bun.lock * build all release binaries on linux * remove package-lock.json * address flake in TestOpenAPISchema
1 parent cf52b9c commit 4412b5a

File tree

14 files changed

+1013
-6178
lines changed

14 files changed

+1013
-6178
lines changed

.github/workflows/release.yml

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,21 @@ name: Build Release Binaries
33
on:
44
release:
55
types: [created, published, edited]
6+
push:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
inputs:
10+
create-artifact:
11+
description: 'Create build artifact'
12+
required: true
13+
type: boolean
14+
default: false
615

716
jobs:
817
build:
9-
name: Build for ${{ matrix.os }}
10-
runs-on: ${{ matrix.os }}
11-
strategy:
12-
matrix:
13-
include:
14-
- os: ubuntu-latest
15-
artifact_name: agentapi
16-
asset_name: agentapi-linux-amd64
17-
goarch: amd64
18-
goos: linux
19-
- os: macos-latest
20-
artifact_name: agentapi
21-
asset_name: agentapi-darwin-amd64
22-
goarch: amd64
23-
goos: darwin
24-
- os: macos-latest
25-
artifact_name: agentapi
26-
asset_name: agentapi-darwin-arm64
27-
goarch: arm64
28-
goos: darwin
29-
- os: windows-latest
30-
artifact_name: agentapi.exe
31-
asset_name: agentapi-windows-amd64.exe
32-
goarch: amd64
33-
goos: windows
18+
name: Build Release Binaries
19+
runs-on: depot-ubuntu-22.04-4
20+
if: ${{ github.repository_owner == 'coder' }}
3421

3522
steps:
3623
- uses: actions/checkout@v4
@@ -40,18 +27,42 @@ jobs:
4027
with:
4128
go-version: 'stable'
4229

43-
- name: Build
44-
env:
45-
GOOS: ${{ matrix.goos }}
46-
GOARCH: ${{ matrix.goarch }}
47-
run: go build -v -o ${{ matrix.artifact_name }} .
30+
- name: Set up Bun
31+
uses: oven-sh/setup-bun@v2
32+
33+
- name: Install Chat Dependencies
34+
run: cd chat && bun install
4835

49-
- name: Upload Release Asset
50-
uses: actions/upload-release-asset@v1
36+
- name: Build and Upload
5137
env:
5238
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
shell: bash
40+
run: |
41+
build_variants=(
42+
"linux amd64 agentapi-linux-amd64"
43+
"darwin amd64 agentapi-darwin-amd64"
44+
"darwin arm64 agentapi-darwin-arm64"
45+
"windows amd64 agentapi-windows-amd64.exe"
46+
)
47+
48+
for variant in "${build_variants[@]}"; do
49+
read -r goos goarch artifact_name <<< "$variant"
50+
51+
echo "Building for GOOS=$goos GOARCH=$goarch..."
52+
GOOS=$goos GOARCH=$goarch BINPATH="out/$artifact_name" make build
53+
done
54+
55+
- name: Upload Build Artifact
56+
if: ${{ inputs.create-artifact }}
57+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
5358
with:
54-
upload_url: ${{ github.event.release.upload_url }}
55-
asset_path: ./${{ matrix.artifact_name }}
56-
asset_name: ${{ matrix.asset_name }}
57-
asset_content_type: application/octet-stream
59+
name: agentapi-build
60+
path: ${{ github.workspace }}/out
61+
retention-days: 7
62+
63+
- name: Upload Release Assets
64+
if: ${{ github.event_name == 'release' || github.ref == 'refs/heads/main' }}
65+
run: gh release upload "$RELEASE_TAG" "$GITHUB_WORKSPACE"/out/* --clobber
66+
env:
67+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
RELEASE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || 'preview' }}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ output-*.log
33
snapshot-*.log
44
snapshot2-*.log
55
.aider*
6-
schema.yaml
6+
schema.yaml
7+
**/.claude/settings.local.json
8+
out

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CHAT_SOURCES_STAMP = chat/.sources.stamp
2+
CHAT_SOURCES = $(shell find chat \( -path chat/node_modules -o -path chat/out -o -path chat/.next \) -prune -o -not -path chat/.sources.stamp -type f -print)
3+
BINPATH ?= out/agentapi
4+
5+
$(CHAT_SOURCES_STAMP): $(CHAT_SOURCES)
6+
@echo "Chat sources changed. Running build steps..."
7+
cd chat && bun run build
8+
rm -rf lib/httpapi/chat && mkdir -p lib/httpapi/chat && touch lib/httpapi/chat/marker
9+
cp -r chat/out/. lib/httpapi/chat/
10+
touch $@
11+
12+
.PHONY: embed
13+
embed: $(CHAT_SOURCES_STAMP)
14+
@echo "Chat build is up to date."
15+
16+
.PHONY: build
17+
build: embed
18+
go build -o ${BINPATH} main.go

chat/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ yarn-error.log*
3939
# typescript
4040
*.tsbuildinfo
4141
next-env.d.ts
42+
.sources.stamp

chat/bun.lock

Lines changed: 842 additions & 0 deletions
Large diffs are not rendered by default.

chat/next.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const nextConfig = {
1313
},
1414

1515
// Configure base path for GitHub Pages (repo/chat)
16-
basePath: isGitHubPages ? `/${repo}/${subPath}` : "",
16+
basePath: isGitHubPages ? `/${repo}/${subPath}` : `/${subPath}`,
1717

1818
// Configure asset prefix for GitHub Pages - helps with static asset loading
19-
assetPrefix: isGitHubPages ? `/${repo}/${subPath}/` : "",
19+
assetPrefix: isGitHubPages ? `/${repo}/${subPath}/` : `/${subPath}/`,
2020

2121
// Configure trailing slashes (recommended for static exports)
2222
trailingSlash: true,

0 commit comments

Comments
 (0)