-
Notifications
You must be signed in to change notification settings - Fork 1.2k
217 lines (186 loc) · 7.25 KB
/
ci.yml
File metadata and controls
217 lines (186 loc) · 7.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: Docker build and push
on:
push:
branches:
- "**"
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
workflow_dispatch:
jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
# Go setup and cache
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.24'
cache: true
cache-dependency-path: backend/go.sum
# Cache Go dependencies
- name: Go Mod Cache
uses: actions/cache@v5
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('backend/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# Node.js setup and cache
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '23'
cache: 'npm'
cache-dependency-path: 'frontend/package-lock.json'
# Cache npm dependencies
- name: Get npm cache directory
id: npm-cache-dir
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
- name: Cache npm packages
uses: actions/cache@v5
id: npm-cache
with:
path: |
${{ steps.npm-cache-dir.outputs.dir }}
frontend/node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('frontend/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
# Frontend lint and test
- name: Frontend - Install dependencies
if: steps.npm-cache.outputs.cache-hit != 'true'
working-directory: frontend
run: npm ci
continue-on-error: true
- name: Frontend - Prettier
working-directory: frontend
run: npm run prettier
continue-on-error: true
- name: Frontend - Lint
working-directory: frontend
run: npm run lint
continue-on-error: true
- name: Frontend - Test
working-directory: frontend
run: npm run test
continue-on-error: true
# Backend lint and test
- name: Backend - Download dependencies
working-directory: backend
run: go mod download
continue-on-error: true
- name: Backend - Lint
uses: golangci/golangci-lint-action@v9
with:
version: latest
working-directory: backend
args: --timeout=5m --issues-exit-code=0
continue-on-error: true
- name: Backend - Test
working-directory: backend
run: go test ./... -v
continue-on-error: true
- name: Backend - Test Build
working-directory: backend
env:
CGO_ENABLED: 0
GO111MODULE: on
run: |
# Get version information
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
PACKAGE_VER=${LATEST_TAG#v}
CURRENT_COMMIT=$(git rev-parse HEAD)
TAG_COMMIT=$(git rev-list -n 1 "$LATEST_TAG" 2>/dev/null || echo "")
if [ "$CURRENT_COMMIT" != "$TAG_COMMIT" ]; then
PACKAGE_REV=$(git rev-parse --short HEAD)
else
PACKAGE_REV=""
fi
LDFLAGS="-X pentagi/pkg/version.PackageName=pentagi -X pentagi/pkg/version.PackageVer=${PACKAGE_VER} -X pentagi/pkg/version.PackageRev=${PACKAGE_REV}"
echo "Building with version: ${PACKAGE_VER}${PACKAGE_REV:+-$PACKAGE_REV}"
# Build for AMD64
GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "$LDFLAGS" -o /tmp/pentagi-amd64 ./cmd/pentagi
echo "✓ Successfully built for linux/amd64"
# Build for ARM64
GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "$LDFLAGS" -o /tmp/pentagi-arm64 ./cmd/pentagi
echo "✓ Successfully built for linux/arm64"
continue-on-error: true
docker-build:
needs: lint-and-test
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Extract version from tag (without 'v' prefix) and split into parts
- name: Extract version and revision
id: version
run: |
# Get latest tag version (without 'v' prefix)
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
VERSION=${LATEST_TAG#v}
# Get current commit hash
CURRENT_COMMIT=$(git rev-parse HEAD)
# Get commit hash of the latest tag
TAG_COMMIT=$(git rev-list -n 1 "$LATEST_TAG" 2>/dev/null || echo "")
# Set revision only if current commit differs from tag commit
if [ "$CURRENT_COMMIT" != "$TAG_COMMIT" ]; then
PACKAGE_REV=$(git rev-parse --short HEAD)
echo "revision=${PACKAGE_REV}" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
echo "Building development version: ${VERSION}-${PACKAGE_REV}"
echo " Docker tags: latest only"
else
echo "revision=" >> $GITHUB_OUTPUT
echo "is_release=true" >> $GITHUB_OUTPUT
echo "Building release version: ${VERSION}"
# Split version into major.minor.patch for Docker tags (only for releases)
IFS='.' read -r major minor patch <<< "$VERSION"
echo "major=${major}" >> $GITHUB_OUTPUT
echo "minor=${major}.${minor}" >> $GITHUB_OUTPUT
echo "patch=${VERSION}" >> $GITHUB_OUTPUT
echo " Docker tags: latest, ${major}, ${major}.${minor}, ${VERSION}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: vxcontrol/pentagi
tags: |
# For master branch - latest tag
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
# For release builds only - tag with major, minor and patch versions
type=raw,value=${{ steps.version.outputs.major }},enable=${{ steps.version.outputs.is_release == 'true' }}
type=raw,value=${{ steps.version.outputs.minor }},enable=${{ steps.version.outputs.is_release == 'true' }}
type=raw,value=${{ steps.version.outputs.patch }},enable=${{ steps.version.outputs.is_release == 'true' }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64/v8
push: true
provenance: true
sbom: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
PACKAGE_VER=${{ steps.version.outputs.version }}
PACKAGE_REV=${{ steps.version.outputs.revision }}