-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (133 loc) · 4.66 KB
/
Copy pathrelease.yml
File metadata and controls
166 lines (133 loc) · 4.66 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
name: Release
# Triggered only when develop is merged into main.
# Runs the full test suite first. Docker images are built and pushed
# to ghcr.io ONLY if every test job passes.
# The `latest` tag is overwritten on every release, providing a
# rolling "current" image. The `sha-<commit>` tag is retained for rollback.
on:
push:
branches: [main]
env:
REGISTRY: ghcr.io
API_IMAGE: ghcr.io/${{ github.repository_owner }}/insight-engine-api
FRONTEND_IMAGE: ghcr.io/${{ github.repository_owner }}/insight-engine-frontend
jobs:
# ── 1. Full test suite (same checks as CI) ───────────────────────────────────
test:
name: Python Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip
cache-dependency-path: requirements/api.txt
- name: Install dependencies
run: |
pip install -r requirements/api.txt pytest pytest-asyncio aiosqlite
pip install "bcrypt==3.2.2" # passlib 1.7.x incompatible with bcrypt>=4.0
- name: Run unit tests
run: pytest tests/unit/ -v --no-header
security:
name: Security Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: pip install bandit[toml]
- run: |
bandit -r src/backend/ src/pipeline/ \
--severity-level high \
--confidence-level high \
--skip B101 \
-q
frontend:
name: Frontend TypeScript + ESLint
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/frontend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
cache-dependency-path: src/frontend/package-lock.json
- run: npm ci
- run: npx tsc --noEmit
- run: npx next lint
# ── 2. Build + push API image (only if all tests pass) ───────────────────────
publish-api:
name: Publish API Image
runs-on: ubuntu-latest
needs: [test, security, frontend]
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Log in to ghcr.io
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: src/backend/Dockerfile
push: true
tags: |
${{ env.API_IMAGE }}:latest
${{ env.API_IMAGE }}:sha-${{ github.sha }}
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Image digest
run: echo "API image pushed — ${{ env.API_IMAGE }}:latest"
# ── 3. Build + push frontend image (only if all tests pass) ──────────────────
publish-frontend:
name: Publish Frontend Image
runs-on: ubuntu-latest
needs: [test, security, frontend]
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Log in to ghcr.io
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: src/frontend
file: src/frontend/Dockerfile
push: true
tags: |
${{ env.FRONTEND_IMAGE }}:latest
${{ env.FRONTEND_IMAGE }}:sha-${{ github.sha }}
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
NEXT_PUBLIC_API_URL=http://localhost:8000
- name: Image digest
run: echo "Frontend image pushed — ${{ env.FRONTEND_IMAGE }}:latest"