Files
Pien-Studio/.github/workflows/ci-cd.yml
T

93 lines
2.2 KiB
YAML

name: CI/CD
on:
push:
branches:
- main
pull_request:
permissions:
contents: read
env:
REGISTRY: ghcr.io
TURBO_TELEMETRY_DISABLED: "1"
NEXT_TELEMETRY_DISABLED: "1"
jobs:
test:
name: Run tests
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.1.38
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Run tests
run: bun run test
docker:
name: Build and publish Docker images - ${{ matrix.app }}
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
strategy:
matrix:
include:
- app: web
image: ${{ github.repository_owner }}/pien-studio/web
dockerfile: ./apps/web/Dockerfile
- app: api
image: ${{ github.repository_owner }}/pien-studio/api
dockerfile: ./apps/api/Dockerfile
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ matrix.image }}
tags: |
type=ref,event=branch
type=sha,prefix=sha-
type=raw,value=latest
- name: Prepare build metadata
id: build-meta
run: echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_HASH=${{ steps.build-meta.outputs.short_sha }}