Skip to content

Commit aa49a78

Browse files
authored
feat(ci): add api and core test (#3)
1 parent 7b1210d commit aa49a78

8 files changed

Lines changed: 233 additions & 25 deletions

File tree

.github/workflows/api-test.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: go-api-test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
paths:
9+
- 'src/server/api/go/**'
10+
- '.github/workflows/api-test.yaml'
11+
pull_request:
12+
branches:
13+
- main
14+
- dev
15+
paths:
16+
- 'src/server/api/go/**'
17+
- '.github/workflows/api-test.yaml'
18+
19+
jobs:
20+
test:
21+
runs-on: ubuntu-latest
22+
defaults:
23+
run:
24+
working-directory: src/server/api/go
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v5
28+
- name: Setup Go
29+
uses: actions/setup-go@v6
30+
with:
31+
go-version-file: src/server/api/go/go.mod
32+
cache: true
33+
- run: go mod tidy
34+
- name: Run tests with coverage
35+
run: go test -v -timeout 30m -coverprofile=coverage.out -covermode=atomic ./...
36+
- name: Upload coverage artifact
37+
if: always()
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: go-api-coverage
41+
path: src/server/api/go/coverage.out

.github/workflows/core-test.yaml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: core-test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
paths:
9+
- 'src/server/core/**'
10+
- '.github/workflows/core-test.yaml'
11+
pull_request:
12+
branches:
13+
- main
14+
- dev
15+
paths:
16+
- 'src/server/core/**'
17+
- '.github/workflows/core-test.yaml'
18+
19+
jobs:
20+
test:
21+
name: Tests on ${{ matrix.os }} for ${{ matrix.python-version }}
22+
strategy:
23+
matrix:
24+
python-version: [3.13]
25+
os: [ubuntu-latest]
26+
runs-on: ${{ matrix.os }}
27+
permissions:
28+
contents: read
29+
defaults:
30+
run:
31+
working-directory: src/server/
32+
steps:
33+
- uses: actions/checkout@v4
34+
- name: Install uv
35+
uses: astral-sh/setup-uv@v6
36+
37+
- name: Set up Python
38+
run: uv python install
39+
- name: Install dependencies
40+
run: |
41+
cd core
42+
uv sync --frozen --no-dev --no-cache-dir
43+
- name: Start containers
44+
run: |
45+
cp .env.example .env
46+
cp core/config.yaml.example core/config.yaml
47+
sh scripts/local_dev_deps.sh &
48+
- name: Wait for containers to start
49+
working-directory: ./src/server
50+
run: |
51+
set -a; . ./.env; set +a
52+
until docker compose exec acontext-server-pg pg_isready -U $DATABASE_USER -d $DATABASE_NAME; do
53+
echo "Waiting for PostgreSQL to be ready..."
54+
sleep 5
55+
done
56+
57+
until docker compose exec acontext-server-minio curl -f http://127.0.0.1:9000/minio/health/ready; do
58+
echo "Waiting for MinIO to be ready..."
59+
sleep 5
60+
done
61+
62+
docker compose exec acontext-server-minio mc alias set local http://127.0.0.1:9000 $S3_ACCESS_KEY $S3_SECRET_KEY
63+
64+
until docker compose exec acontext-server-minio mc ls local/$S3_BUCKET >/dev/null 2>&1; do
65+
echo "Waiting for S3 bucket '$S3_BUCKET' to be created..."
66+
sleep 5
67+
done
68+
- name: Test with pytest
69+
run: |
70+
cd core
71+
uv run -m pytest --junit-xml=junit/test-results-${{ matrix.python-version }}.xml --cov=. --cov-report=xml:coverage-${{ matrix.python-version }}.xml tests/ -s -v
72+
- name: Upload pytest test results and coverage
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: pytest-results-${{ matrix.python-version }}
76+
path: |
77+
./src/server/core/junit/test-results-${{ matrix.python-version }}.xml
78+
./src/server/core/coverage-${{ matrix.python-version }}.xml
79+
if: ${{ always() }}
80+
- name: Stop containers
81+
if: ${{ always() }}
82+
run: |
83+
docker compose down

src/server/api/go/.goreleaser.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# This is an example .goreleaser.yml file with some sensible defaults.
2+
# Make sure to check the documentation at https://goreleaser.com
3+
4+
# The lines below are called `modelines`. See `:help modeline`
5+
# Feel free to remove those if you don't want/need to use them.
6+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
7+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
8+
9+
version: 2
10+
11+
project_name: acontext-api
12+
13+
dist: "./dist"
14+
15+
before:
16+
hooks:
17+
- go mod tidy
18+
19+
builds:
20+
- id: "acontext-api"
21+
main: "./cmd/server/main.go"
22+
env:
23+
- CGO_ENABLED=0
24+
goos:
25+
- linux
26+
#- windows
27+
- darwin
28+
goarch:
29+
- amd64
30+
- arm64
31+
binary: acontext-api
32+
33+
archives:
34+
- format: tar.gz
35+
# this name template makes the OS and Arch compatible with the results of `uname`.
36+
name_template: >-
37+
{{ .ProjectName }}_
38+
{{- title .Os }}_
39+
{{- if eq .Arch "amd64" }}x86_64
40+
{{- else if eq .Arch "386" }}i386
41+
{{- else }}{{ .Arch }}{{ end }}
42+
{{- if .Arm }}v{{ .Arm }}{{ end }}
43+
# use zip for windows archives
44+
# format_overrides:
45+
# - goos: windows
46+
# format: zip
47+
48+
dockers_v2:
49+
- id: "acontext-api"
50+
dockerfile: "Dockerfile"
51+
images:
52+
- "ghcr.io/memodb-io/acontext-api"
53+
tags:
54+
- "{{.ShortCommit}}"
55+
# - "{{.Version}}"
56+
extra_files:
57+
- "configs/config.yaml"
58+
labels:
59+
"org.opencontainers.image.description": "acontext-api"
60+
"org.opencontainers.image.created": "{{.Date}}"
61+
"org.opencontainers.image.name": "{{.ProjectName}}"
62+
"org.opencontainers.image.revision": "{{.FullCommit}}"
63+
"org.opencontainers.image.version": "{{.Version}}"
64+
"org.opencontainers.image.source": "{{.GitURL}}"
65+
66+
release:
67+
github:
68+
owner: memodb-io
69+
name: Acontext
70+
draft: false
71+
footer: >-
72+
## Docker Images
73+
* `ghcr.io/memodb-io/acontext-api:{{ .Version }}`
74+
75+
## Thanks!
76+
prerelease: auto

src/server/api/go/Dockerfile

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
1-
FROM golang:1.25 AS build-stage
2-
3-
WORKDIR /app
4-
5-
COPY go.mod go.sum ./
6-
RUN go mod download
7-
8-
COPY . .
9-
10-
RUN CGO_ENABLED=0 go build -o /acontext-api ./cmd/server/main.go
11-
12-
FROM build-stage AS run-test-stage
13-
RUN go test -v ./...
14-
15-
FROM gcr.io/distroless/static-debian12 AS build-release-stage
16-
17-
WORKDIR /
18-
19-
COPY --from=build-stage /acontext-api /acontext-api
1+
FROM scratch
2+
ARG TARGETPLATFORM
3+
COPY $TARGETPLATFORM/acontext-api /acontext-api
204
COPY ./configs/config.yaml /configs/config.yaml
21-
22-
EXPOSE 8029
23-
24-
USER nonroot:nonroot
25-
265
ENTRYPOINT ["/acontext-api"]

src/server/api/go/Dockerfile.dev

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM golang:1.25 AS build-stage
2+
3+
WORKDIR /app
4+
5+
COPY go.mod go.sum ./
6+
RUN go mod download
7+
8+
COPY . .
9+
10+
RUN CGO_ENABLED=0 go build -o /acontext-api ./cmd/server/main.go
11+
12+
FROM build-stage AS run-test-stage
13+
RUN go test -v ./...
14+
15+
FROM gcr.io/distroless/static-debian12 AS build-release-stage
16+
17+
WORKDIR /
18+
19+
COPY --from=build-stage /acontext-api /acontext-api
20+
COPY ./configs/config.yaml /configs/config.yaml
21+
22+
EXPOSE 8029
23+
24+
USER nonroot:nonroot
25+
26+
ENTRYPOINT ["/acontext-api"]

src/server/core/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ sh launch.sh -m prod -w 4 # 4 workers
3333

3434
- Test the core
3535
```bash
36+
# current path: ./src/server/core
37+
cp config.yaml.example config.yaml
3638
uv run -m pytest
3739
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
llm_api_key: YOUR-OPENAI-KEY

src/server/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ services:
9595
acontext-api:
9696
build:
9797
context: ./api/go
98-
dockerfile: Dockerfile
98+
dockerfile: Dockerfile.dev
9999
container_name: acontext-api
100100
restart: unless-stopped
101101
environment:

0 commit comments

Comments
 (0)