Files
TelegramMemeVault/.gitea/workflows/ci.yaml
T
CrazyHackGUT 22c0bf7697
CI / CD / Unit tests (push) Successful in 39s
CI / CD / Build & push frontend-static (push) Successful in 1m17s
CI / CD / Build & push frontend (nginx) (push) Successful in 1m13s
CI / CD / Build & push backend (push) Successful in 2m52s
fix: pipelines for building frontend
2026-10-11 01:04:06 +04:00

181 lines
6.2 KiB
YAML

name: CI / CD
on:
push:
branches: ['**']
tags: ['v*']
pull_request:
env:
REGISTRY: code.kruzya.dev
# backend: api + bot + migrator (единый образ, разные CMD)
BACKEND_IMAGE: code.kruzya.dev/crazyhackgut/telegrammemevault/backend
# frontend: miniapp nginx (для docker-compose)
FRONTEND_IMAGE: code.kruzya.dev/crazyhackgut/telegrammemevault/frontend
# frontend-static: FROM scratch, используется как image volume в k8s
FRONTEND_STATIC_IMAGE: code.kruzya.dev/crazyhackgut/telegrammemevault/frontend-static
jobs:
# ─────────────────────────────── TESTS ──────────────────────────────────────
test:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Restore
run: dotnet restore MemeVault.sln
- name: Test
run: |
dotnet test src/MemeVault.Tests.Unit \
--configuration Release \
--no-restore \
--logger "console;verbosity=normal"
# ─────────────────────────────── BACKEND ────────────────────────────────────
build-backend:
name: Build & push backend
needs: test
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
- name: Compute image tags
id: meta
run: |
SHA="${GITHUB_SHA:0:12}"
SAFE_REF=$(echo "$GITHUB_REF_NAME" \
| tr '[:upper:]' '[:lower:]' \
| sed 's/[^a-z0-9._-]/-/g')
IMG="${{ env.BACKEND_IMAGE }}"
TAGS="${IMG}:sha-${SHA},${IMG}:${SAFE_REF}"
if [ "$GITHUB_REF_TYPE" = "tag" ]; then
TAGS="${TAGS},${IMG}:latest"
fi
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
- name: Log in to registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: CrazyHackGUT
password: ${{ secrets.IMAGE_PUSH_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=registry,ref=${{ env.BACKEND_IMAGE }}:cache
cache-to: type=registry,ref=${{ env.BACKEND_IMAGE }}:cache,mode=max
# ─────────────────────── FRONTEND-STATIC (FROM scratch) ─────────────────────
build-frontend-static:
name: Build & push frontend-static
needs: test
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
packages: write
outputs:
# Передаём точный sha-тег следующему джобу
image: ${{ steps.meta.outputs.image }}
steps:
- uses: actions/checkout@v4
- name: Compute image tags
id: meta
run: |
SHA="${GITHUB_SHA:0:12}"
SAFE_REF=$(echo "$GITHUB_REF_NAME" \
| tr '[:upper:]' '[:lower:]' \
| sed 's/[^a-z0-9._-]/-/g')
IMG="${{ env.FRONTEND_STATIC_IMAGE }}"
TAGS="${IMG}:sha-${SHA},${IMG}:${SAFE_REF}"
if [ "$GITHUB_REF_TYPE" = "tag" ]; then
TAGS="${TAGS},${IMG}:latest"
fi
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
echo "image=${IMG}:sha-${SHA}" >> "$GITHUB_OUTPUT"
- name: Log in to registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: CrazyHackGUT
password: ${{ secrets.IMAGE_PUSH_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
context: miniapp
file: miniapp/Dockerfile.frontend
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=registry,ref=${{ env.FRONTEND_STATIC_IMAGE }}:cache
cache-to: type=registry,ref=${{ env.FRONTEND_STATIC_IMAGE }}:cache,mode=max
# ─────────────────────── FRONTEND (nginx поверх static) ─────────────────────
build-frontend:
name: Build & push frontend (nginx)
needs: build-frontend-static
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
- name: Compute image tags
id: meta
run: |
SHA="${GITHUB_SHA:0:12}"
SAFE_REF=$(echo "$GITHUB_REF_NAME" \
| tr '[:upper:]' '[:lower:]' \
| sed 's/[^a-z0-9._-]/-/g')
IMG="${{ env.FRONTEND_IMAGE }}"
TAGS="${IMG}:sha-${SHA},${IMG}:${SAFE_REF}"
if [ "$GITHUB_REF_TYPE" = "tag" ]; then
TAGS="${TAGS},${IMG}:latest"
fi
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
- name: Log in to registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: CrazyHackGUT
password: ${{ secrets.IMAGE_PUSH_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
context: miniapp
file: miniapp/Dockerfile.nginx
push: true
tags: ${{ steps.meta.outputs.tags }}
# Передаём точный тег собранного frontend-static
build-args: |
STATIC_IMAGE=${{ needs.build-frontend-static.outputs.image }}
cache-from: type=registry,ref=${{ env.FRONTEND_IMAGE }}:cache
cache-to: type=registry,ref=${{ env.FRONTEND_IMAGE }}:cache,mode=max