BCards/.gitea/workflows/release-deploy.yml
2025-07-23 15:42:58 -03:00

127 lines
3.8 KiB
YAML

name: Release Deployment Pipeline
on:
push:
branches:
- 'Release/*'
# Também pode executar manualmente
workflow_dispatch:
inputs:
skip_tests:
description: 'Skip tests (true/false)'
required: false
default: 'false'
env:
REGISTRY: registry.redecarneir.us
IMAGE_NAME: bcards
MONGODB_HOST: 192.168.0.100:27017
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Check if tests should run
run: |
# Prioridade: manual input > variável do repo
SKIP_TESTS="${{ github.event.inputs.skip_tests || vars.SKIP_TESTS }}"
if [ "$SKIP_TESTS" == "true" ]; then
echo "⚠️ Testes PULADOS"
echo "TESTS_SKIPPED=true" >> $GITHUB_ENV
else
echo "✅ Executando testes"
echo "TESTS_SKIPPED=false" >> $GITHUB_ENV
fi
echo "🎯 Trigger: ${{ github.event_name }}"
echo "📂 Branch: ${{ github.ref_name }}"
- name: Checkout code
if: env.TESTS_SKIPPED == 'false'
uses: actions/checkout@v4
- name: Setup .NET 8
if: env.TESTS_SKIPPED == 'false'
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
if: env.TESTS_SKIPPED == 'false'
run: dotnet restore
- name: Build solution
if: env.TESTS_SKIPPED == 'false'
run: dotnet build --no-restore --configuration Release
- name: Run unit tests
if: env.TESTS_SKIPPED == 'false'
run: dotnet test --no-build --configuration Release --verbosity normal
build-and-deploy:
name: Build and Deploy
runs-on: ubuntu-latest
needs: [test]
if: always() && (needs.test.result == 'success' || needs.test.result == 'failure')
steps:
- name: Deployment info
run: |
echo "🚀 Iniciando deployment para ${{ github.ref_name }}"
echo "🧪 Tests: ${{ vars.SKIP_TESTS == 'true' && 'SKIPPED' || 'EXECUTED' }}"
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Extract version info
id: version
run: |
BRANCH_NAME="${{ github.ref_name }}"
VERSION_RAW=${BRANCH_NAME#Release/}
VERSION=$(echo "$VERSION_RAW" | sed 's/^[Vv]//')
if [ -z "$VERSION" ]; then
VERSION="0.0.1"
fi
COMMIT_SHA=${{ github.sha }}
SHORT_COMMIT=${COMMIT_SHA:0:7}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "commit=$SHORT_COMMIT" >> $GITHUB_OUTPUT
echo "tag=$VERSION-$SHORT_COMMIT" >> $GITHUB_OUTPUT
echo "📦 Version: $VERSION"
echo "🔑 Commit: $SHORT_COMMIT"
echo "🏷️ Tag: $VERSION-$SHORT_COMMIT"
- name: Build and push multi-arch image
run: |
echo "🏗️ Building multi-arch image..."
docker buildx build \
--platform linux/amd64,linux/arm64 \
--file Dockerfile.release \
--tag $REGISTRY/$IMAGE_NAME:${{ steps.version.outputs.tag }} \
--tag $REGISTRY/$IMAGE_NAME:${{ steps.version.outputs.version }}-latest \
--tag $REGISTRY/$IMAGE_NAME:release-latest \
--push \
--build-arg VERSION=${{ steps.version.outputs.version }} \
--build-arg COMMIT=${{ steps.version.outputs.commit }} \
--progress=plain
# Resto do deployment...
- name: Deploy notification
run: |
echo "✅ Deployment concluído!"
echo "📦 Image: $REGISTRY/$IMAGE_NAME:${{ steps.version.outputs.tag }}"
echo "🎯 Trigger: ${{ github.event_name }}"
echo "📂 Branch: ${{ github.ref_name }}"