Skip to content

feat: Polished readmes #139

feat: Polished readmes

feat: Polished readmes #139

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: 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: 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: 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