feat: CI
This commit is contained in:
@@ -0,0 +1,125 @@
|
|||||||
|
name: CI / CD
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ['**']
|
||||||
|
tags: ['v*']
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: code.kruzya.dev
|
||||||
|
BACKEND_IMAGE: code.kruzya.dev/crazyhackgut/telegrammemevault/backend
|
||||||
|
MINIAPP_IMAGE: code.kruzya.dev/crazyhackgut/telegrammemevault/miniapp
|
||||||
|
|
||||||
|
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
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# Вычисляем теги образа:
|
||||||
|
# sha-<короткий хеш> — всегда
|
||||||
|
# <ветка / git-тег> — всегда (слеши заменяются дефисами)
|
||||||
|
# latest — только при пуше git-тега
|
||||||
|
- 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: ${{ gitea.actor }}
|
||||||
|
password: ${{ secrets.GITEA_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 }}
|
||||||
|
# Кэш хранится в самом реджистри — BuildKit достаёт его при следующей сборке
|
||||||
|
cache-from: type=registry,ref=${{ env.BACKEND_IMAGE }}:cache
|
||||||
|
cache-to: type=registry,ref=${{ env.BACKEND_IMAGE }}:cache,mode=max
|
||||||
|
|
||||||
|
# ─────────────────────────────── MINIAPP ────────────────────────────────────
|
||||||
|
build-miniapp:
|
||||||
|
name: Build & push miniapp
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
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.MINIAPP_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: ${{ gitea.actor }}
|
||||||
|
password: ${{ secrets.GITEA_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
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
cache-from: type=registry,ref=${{ env.MINIAPP_IMAGE }}:cache
|
||||||
|
cache-to: type=registry,ref=${{ env.MINIAPP_IMAGE }}:cache,mode=max
|
||||||
Reference in New Issue
Block a user