Files
project-template/.gitea/workflows/ci.yml
T
xiaoxia 40b9711940
CI Pipeline / Lint & Build (push) Has been cancelled
CI Pipeline / Build & Push Docker Image (push) Has been cancelled
Add CI/CD pipeline configuration
2026-07-08 18:30:20 +08:00

84 lines
2.1 KiB
YAML

name: CI Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
env:
REGISTRY: git.xiaoxiajianji.com
IMAGE_NAME: ${{ gitea.repository }}
jobs:
lint-and-build:
name: Lint & Build
runs-on: ubuntu-latest
container:
image: git.xiaoxiajianji.com/xiaoxia/base/node:20
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
- name: Code lint
run: npm run lint
- name: Type check (if applicable)
run: npm run typecheck 2>/dev/null || echo "Typecheck script not found, skipping"
- name: Build
run: npm run build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
docker-build:
name: Build & Push Docker Image
runs-on: ubuntu-latest
needs: lint-and-build
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Set up Docker Buildx
uses: actions/setup-buildx-action@v3
- name: Login to Gitea Registry
uses: actions/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ gitea.actor }}
password: ${{ secrets.GITEA_TOKEN }}
- name: Build and push
uses: actions/build-push-action@v6
with:
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max