Public Access
72 lines
2.2 KiB
YAML
72 lines
2.2 KiB
YAML
name: Build, Test & Push Frontend
|
|
|
|
# Trigger the workflow
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
# ------------------------------------------------------------------
|
|
# JOB 1: Code integrity and quality gates (CI)
|
|
# ------------------------------------------------------------------
|
|
quality-check:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '24'
|
|
cache: 'npm'
|
|
|
|
- name: Install Dependencies
|
|
run: npm ci
|
|
|
|
# Run ESLint if configured in package.json
|
|
- name: Lint & Type Check
|
|
run: npm run lint --if-present
|
|
|
|
# Build the Vite React application
|
|
- name: Build Production
|
|
run: npm run build
|
|
|
|
# ------------------------------------------------------------------
|
|
# JOB 2: Docker Build & Push (CD)
|
|
# Runs only if 'quality-check' is successful and we are on branch main
|
|
# ------------------------------------------------------------------
|
|
docker:
|
|
needs: quality-check
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Prepare tag
|
|
id: prep
|
|
shell: bash
|
|
run: |
|
|
# Sanitize branch name for valid Docker tags
|
|
BRANCH="${GITHUB_REF_NAME}"
|
|
BRANCH="${BRANCH//\//-}"
|
|
BRANCH="$(echo "$BRANCH" | tr '[:upper:]' '[:lower:]')"
|
|
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
|
|
echo "sha=${GITHUB_SHA::12}" >> "$GITHUB_OUTPUT"
|
|
|
|
- uses: docker/setup-buildx-action@v3
|
|
|
|
- uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Build & Push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: |
|
|
docker.io/${{ secrets.DOCKERHUB_USERNAME }}/tobeplayed-frontend:${{ steps.prep.outputs.branch }}
|
|
docker.io/${{ secrets.DOCKERHUB_USERNAME }}/tobeplayed-frontend:${{ steps.prep.outputs.branch }}-${{ steps.prep.outputs.sha }}
|
|
docker.io/${{ secrets.DOCKERHUB_USERNAME }}/tobeplayed-frontend:latest |