Skip to content

Commit faf6119

Browse files
authored
Merge branch 'main' into feat-file-upload
2 parents 59af739 + 517d0de commit faf6119

File tree

6 files changed

+228
-35
lines changed

6 files changed

+228
-35
lines changed

.github/workflows/go-test.yml

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
11
name: Go Tests
22

33
on:
4-
push:
5-
branches: [main]
6-
pull_request:
4+
push:
5+
branches: [main]
6+
pull_request:
77

88
jobs:
9-
test:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v4
13-
14-
- name: Set up Go
15-
uses: actions/setup-go@v5
16-
with:
17-
go-version: "stable"
18-
19-
- name: Test
20-
run: CGO_ENABLED=0 go test -count=1 -v ./...
21-
22-
lint:
23-
runs-on: ubuntu-latest
24-
steps:
25-
- uses: actions/checkout@v4
26-
27-
- name: Set up Go
28-
uses: actions/setup-go@v5
29-
with:
30-
go-version: "stable"
31-
32-
- name: golangci-lint
33-
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
34-
with:
35-
version: v2.1
36-
37-
- name: Check for unstaged changes
38-
run: |
39-
make gen
40-
./check_unstaged.sh
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Set up Go
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version: "stable"
18+
19+
- name: Test
20+
run: CGO_ENABLED=0 go test -count=1 -v ./...
21+
22+
lint:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- name: Set up Go
28+
uses: actions/setup-go@v5
29+
with:
30+
go-version: "stable"
31+
32+
- name: Set up Bun
33+
uses: oven-sh/setup-bun@v2
34+
35+
- name: Install Chat Dependencies
36+
run: cd chat && bun install
37+
38+
- name: run linters
39+
run: make lint
40+
41+
- name: Check for unstaged changes
42+
run: |
43+
make gen
44+
./check_unstaged.sh
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: PR Preview Build
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
build:
8+
name: Build Release Binaries
9+
runs-on: depot-ubuntu-22.04-4
10+
permissions:
11+
contents: write
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version: 'stable'
20+
21+
- name: Set up Bun
22+
uses: oven-sh/setup-bun@v2
23+
24+
- name: Install Chat Dependencies
25+
run: cd chat && bun install
26+
27+
- name: Run make gen and check for unstaged changes
28+
run: |
29+
make gen
30+
./check_unstaged.sh
31+
32+
- name: Build
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
shell: bash
36+
run: |
37+
build_variants=(
38+
"linux amd64 agentapi-linux-amd64"
39+
"linux arm64 agentapi-linux-arm64"
40+
"darwin amd64 agentapi-darwin-amd64"
41+
"darwin arm64 agentapi-darwin-arm64"
42+
"windows amd64 agentapi-windows-amd64.exe"
43+
)
44+
45+
for variant in "${build_variants[@]}"; do
46+
read -r goos goarch artifact_name <<< "$variant"
47+
48+
echo "Building for GOOS=$goos GOARCH=$goarch..."
49+
CGO_ENABLED=0 GOOS=$goos GOARCH=$goarch BINPATH="out/$artifact_name" make build
50+
done
51+
52+
- name: Upload Build Artifact
53+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
54+
with:
55+
name: agentapi-build-${{ github.event.pull_request.number }}
56+
path: ${{ github.workspace }}/out
57+
retention-days: 7
58+
59+
- name: Save PR number
60+
run: |
61+
mkdir -p ./pr
62+
echo ${{ github.event.pull_request.number }} > ./pr/number
63+
64+
- name: Upload PR number
65+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
66+
with:
67+
name: pr-number
68+
path: pr/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: PR Preview Cleanup
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
cleanup:
12+
name: Delete PR Release
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Delete PR Release
17+
env:
18+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
RELEASE_TAG: 'agentapi_${{ github.event.pull_request.number }}'
20+
run: |
21+
gh release delete "$RELEASE_TAG" --cleanup-tag --yes --repo ${{ github.repository }} || true
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: PR Preview Release
2+
3+
on:
4+
workflow_run:
5+
workflows: ["PR Preview Build"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
release:
15+
name: Create Release
16+
runs-on: ubuntu-latest
17+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
18+
19+
steps:
20+
- name: Download PR number
21+
uses: actions/download-artifact@v4
22+
with:
23+
name: pr-number
24+
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
run-id: ${{ github.event.workflow_run.id }}
26+
27+
- name: Read PR number
28+
id: pr
29+
run: echo "number=$(cat number)" >> "${GITHUB_OUTPUT}"
30+
31+
- name: Download Build Artifacts
32+
uses: actions/download-artifact@v4
33+
with:
34+
name: agentapi-build-${{ steps.pr.outputs.number }}
35+
path: ./out
36+
github-token: ${{ secrets.GITHUB_TOKEN }}
37+
run-id: ${{ github.event.workflow_run.id }}
38+
39+
- name: Create or Update PR Release
40+
env:
41+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
RELEASE_TAG: "agentapi_${{ steps.pr.outputs.number }}"
43+
PR_NUMBER: ${{ steps.pr.outputs.number }}
44+
run: |
45+
# Check if release exists
46+
if gh release view "$RELEASE_TAG" --repo ${{ github.repository }} &>/dev/null; then
47+
echo "Updating release $RELEASE_TAG"
48+
gh release upload "$RELEASE_TAG" ./out/* --clobber --repo ${{ github.repository }}
49+
else
50+
echo "Creating release $RELEASE_TAG"
51+
gh release create "$RELEASE_TAG" ./out/* \
52+
--title "$RELEASE_TAG" \
53+
--notes "Preview release for PR #${PR_NUMBER}" \
54+
--repo ${{ github.repository }} \
55+
--latest=false \
56+
--prerelease
57+
fi
58+
59+
- name: Comment on PR
60+
uses: actions/github-script@v7
61+
with:
62+
script: |
63+
const prNumber = ${{ steps.pr.outputs.number }};
64+
const releaseTag = `agentapi_${prNumber}`;
65+
const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`;
66+
github.rest.issues.createComment({
67+
issue_number: prNumber,
68+
owner: context.repo.owner,
69+
repo: context.repo.repo,
70+
body: `✅ Preview binaries are ready!\n\nTo test with modules: \`\`\`agentapi_version = "agentapi_${prNumber}"\`\`\` or download from: ${repoUrl}/releases/tag/${releaseTag}`
71+
});

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ CHAT_SOURCES = $(shell find chat \( -path chat/node_modules -o -path chat/out -o
33
BINPATH ?= out/agentapi
44
# This must be kept in sync with the magicBasePath in lib/httpapi/embed.go.
55
BASE_PATH ?= /magic-base-path-placeholder
6+
FIND_EXCLUSIONS= \
7+
-not \( \( -path '*/.git/*' -o -path './out/*' -o -path '*/node_modules/*' -o -path '*/.terraform/*' \) -prune \)
8+
SHELL_SRC_FILES := $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.sh')
69

710
$(CHAT_SOURCES_STAMP): $(CHAT_SOURCES)
811
@echo "Chat sources changed. Running build steps..."
@@ -22,3 +25,24 @@ build: embed
2225
.PHONY: gen
2326
gen:
2427
go generate ./...
28+
29+
lint: lint/shellcheck lint/go lint/ts lint/actions/actionlint
30+
.PHONY: lint
31+
32+
lint/go:
33+
go run github.com/golangci/golangci-lint/v2/cmd/[email protected] run
34+
go run github.com/coder/paralleltestctx/cmd/[email protected] ./...
35+
.PHONY: lint/go
36+
37+
lint/shellcheck: $(SHELL_SRC_FILES)
38+
echo "--- shellcheck"
39+
shellcheck --external-sources $(SHELL_SRC_FILES)
40+
.PHONY: lint/shellcheck
41+
42+
lint/ts:
43+
cd ./chat && bun lint
44+
.PHONY: lint/ts
45+
46+
lint/actions/actionlint:
47+
go run github.com/rhysd/actionlint/cmd/[email protected] --config-file actionlint.yaml
48+
.PHONY: lint/actions/actionlint

actionlint.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Configuration related to self-hosted runner.
2+
self-hosted-runner:
3+
# Labels of self-hosted runner in array of strings.
4+
labels:
5+
- depot-ubuntu-22.04-4

0 commit comments

Comments
 (0)