Skip to content

Commit 7ce7482

Browse files
committed
Add GitHub Actions workflow for PR checks including linting, testing, and building
1 parent 3a246bc commit 7ce7482

1 file changed

Lines changed: 170 additions & 0 deletions

File tree

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
name: Agent Manager Service PR Checks
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
paths:
7+
- "agent-manager-service/**"
8+
- ".github/workflows/agent-manager-service-pr-checks.yml"
9+
pull_request:
10+
branches: ["main"]
11+
paths:
12+
- "agent-manager-service/**"
13+
- ".github/workflows/agent-manager-service-pr-checks.yml"
14+
15+
jobs:
16+
lint:
17+
name: Lint
18+
runs-on: ubuntu-latest
19+
defaults:
20+
run:
21+
working-directory: ./agent-manager-service
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Go
27+
uses: actions/setup-go@v5
28+
with:
29+
go-version: "1.24.2"
30+
cache-dependency-path: agent-manager-service/go.sum
31+
32+
- name: Install golangci-lint
33+
run: |
34+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.1.0
35+
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
36+
37+
- name: Install goimports
38+
run: go install golang.org/x/tools/cmd/goimports@latest
39+
40+
- name: Run lint
41+
run: make lint
42+
43+
test:
44+
name: Test
45+
runs-on: ubuntu-latest
46+
defaults:
47+
run:
48+
working-directory: ./agent-manager-service
49+
50+
services:
51+
postgres:
52+
image: postgres:15-alpine
53+
env:
54+
POSTGRES_USER: agentmanager
55+
POSTGRES_PASSWORD: agentmanager
56+
POSTGRES_DB: agentmanager
57+
options: >-
58+
--health-cmd pg_isready
59+
--health-interval 10s
60+
--health-timeout 5s
61+
--health-retries 5
62+
ports:
63+
- 5432:5432
64+
65+
steps:
66+
- name: Checkout code
67+
uses: actions/checkout@v4
68+
69+
- name: Setup Go
70+
uses: actions/setup-go@v5
71+
with:
72+
go-version: "1.24.2"
73+
cache-dependency-path: agent-manager-service/go.sum
74+
75+
- name: Create test .env file
76+
run: |
77+
cat > .env << 'EOF'
78+
DB_HOST=localhost
79+
DB_PORT=5432
80+
DB_USER=agentmanager
81+
DB_PASSWORD=agentmanager
82+
DB_NAME=agentmanager
83+
SERVER_PORT=8080
84+
API_KEY_VALUE=test-key
85+
IS_LOCAL_DEV_ENV=true
86+
AMP_VERSION=v0.1.0-rc7
87+
EOF
88+
89+
- name: Wait for PostgreSQL
90+
run: |
91+
until pg_isready -h localhost -p 5432 -U agentmanager; do
92+
echo "Waiting for postgres..."
93+
sleep 1
94+
done
95+
timeout-minutes: 2
96+
97+
- name: Run tests
98+
run: make test
99+
100+
- name: Upload test logs on failure
101+
if: failure()
102+
uses: actions/upload-artifact@v4
103+
with:
104+
name: test-logs
105+
path: agent-manager-service/localdata/test_output.log
106+
if-no-files-found: ignore
107+
108+
build:
109+
name: Build
110+
runs-on: ubuntu-latest
111+
defaults:
112+
run:
113+
working-directory: ./agent-manager-service
114+
steps:
115+
- name: Checkout code
116+
uses: actions/checkout@v4
117+
118+
- name: Setup Go
119+
uses: actions/setup-go@v5
120+
with:
121+
go-version: "1.24.2"
122+
cache-dependency-path: agent-manager-service/go.sum
123+
124+
- name: Build
125+
run: go build -v ./...
126+
127+
codegen-format:
128+
name: Code Generation & Format Check
129+
runs-on: ubuntu-latest
130+
defaults:
131+
run:
132+
working-directory: ./agent-manager-service
133+
steps:
134+
- name: Checkout code
135+
uses: actions/checkout@v4
136+
137+
- name: Setup Go
138+
uses: actions/setup-go@v5
139+
with:
140+
go-version: "1.24.2"
141+
cache-dependency-path: agent-manager-service/go.sum
142+
143+
- name: Install wire
144+
run: go install github.com/google/wire/cmd/wire@latest
145+
146+
- name: Install goimports
147+
run: go install golang.org/x/tools/cmd/goimports@latest
148+
149+
- name: Run wire code generation
150+
run: make wire
151+
152+
- name: Run go generate
153+
run: make codegen
154+
155+
- name: Run formatting
156+
run: make fmt
157+
158+
- name: Run go mod tidy
159+
run: go mod tidy
160+
161+
- name: Check for uncommitted changes
162+
run: |
163+
if [ ! -z "$(git status --porcelain)" ]; then
164+
echo "Code generation or formatting produced changes:"
165+
git diff
166+
git status
167+
echo ""
168+
echo "Please run 'make wire && make codegen && make fmt && go mod tidy' locally and commit the changes."
169+
exit 1
170+
fi

0 commit comments

Comments
 (0)