-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (130 loc) · 4.18 KB
/
Copy pathtest-build-push.yml
File metadata and controls
152 lines (130 loc) · 4.18 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
name: Test, Build and Push Images
# Runs tests and builds images on every branch.
# Pushes to the registry only on main, or on a manual workflow_dispatch run.
on:
push:
branches:
- '**'
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
test-java:
name: Run Java Tests
runs-on: ubuntu-latest
strategy:
matrix:
service: [api-gateway, user-service, grocery-service]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Check formatting with Spotless
run: cd server/${{ matrix.service }} && ./mvnw -B spotless:check
- name: Run tests with Maven
run: cd server/${{ matrix.service }} && ./mvnw -B test
test-client:
name: Run Client Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: npm
cache-dependency-path: client/package-lock.json
- name: Install dependencies
run: cd client && npm ci
- name: Lint with ESLint
run: cd client && npm run lint
- name: Run tests
run: cd client && npm test
test-gen-ai:
name: Run Gen-AI Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: pip
cache-dependency-path: gen-ai/requirements*.txt
- name: Install dependencies
run: pip install -r gen-ai/requirements-dev.txt
- name: Lint with Ruff
run: ruff check gen-ai
- name: Run tests with pytest
run: pytest gen-ai
test-gatekeeper:
# Branch protection on main requires a status check named exactly "Run Java Tests".
# Renaming this job when the protection rule is updated to match.
name: Run Java Tests
needs: [test-java, test-client, test-gen-ai]
runs-on: ubuntu-latest
steps:
- name: Success Gate
run: echo "All server, client, and gen-ai tests passed successfully!"
build:
name: Build ${{ matrix.image }}
needs: test-gatekeeper
runs-on: ubuntu-latest
strategy:
matrix:
include:
- image: client
context: ./client
- image: api-gateway
context: ./server/api-gateway
- image: user-service
context: ./server/user-service
- image: grocery-service
context: ./server/grocery-service
- image: gen-ai
context: ./gen-ai
- image: user-db
context: ./databases/user-db
- image: grocery-db
context: ./databases/grocery-db
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
# metadata-action lowercases the image name for ghcr.io automatically.
images: ghcr.io/${{ github.repository }}/${{ matrix.image }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=sha,format=long,prefix=
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
file: ${{ matrix.context }}/Dockerfile
push: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max