111 lines
3.5 KiB
YAML
111 lines
3.5 KiB
YAML
name: PR Validation for Release
|
|
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- 'Release/*'
|
|
types: [opened, synchronize, reopened, ready_for_review]
|
|
|
|
env:
|
|
REGISTRY: registry.redecarneir.us
|
|
IMAGE_NAME: bcards
|
|
MONGODB_HOST: 192.168.0.100:27017
|
|
|
|
jobs:
|
|
validate-pr:
|
|
name: Validate Pull Request
|
|
runs-on: ubuntu-latest
|
|
if: github.event.pull_request.draft == false
|
|
|
|
steps:
|
|
- name: PR Info
|
|
run: |
|
|
echo "🔍 Validando PR #${{ github.event.number }}"
|
|
echo "📂 Source: ${{ github.head_ref }}"
|
|
echo "🎯 Target: ${{ github.base_ref }}"
|
|
echo "👤 Author: ${{ github.event.pull_request.user.login }}"
|
|
echo "📝 Title: ${{ github.event.pull_request.title }}"
|
|
|
|
- name: Checkout PR code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
|
|
- name: Setup .NET 8
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: '8.0.x'
|
|
|
|
- name: Restore dependencies
|
|
run: dotnet restore
|
|
|
|
- name: Build solution
|
|
run: dotnet build --no-restore --configuration Release
|
|
|
|
- name: Run tests
|
|
if: ${{ vars.SKIP_TESTS_PR != 'true' }}
|
|
run: |
|
|
echo "🧪 Executando testes no PR"
|
|
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"
|
|
dotnet test --no-build --configuration Release --verbosity normal
|
|
echo "TESTS_SKIPPED=false" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Build Docker image (test only)
|
|
run: |
|
|
echo "🐳 Testando build da imagem Docker..."
|
|
|
|
# Extrair versão da branch de destino
|
|
TARGET_BRANCH="${{ github.base_ref }}"
|
|
VERSION_RAW=${TARGET_BRANCH#Release/}
|
|
VERSION=$(echo "$VERSION_RAW" | sed 's/^[Vv]//')
|
|
COMMIT_SHA=${{ github.event.pull_request.head.sha }}
|
|
SHORT_COMMIT=${COMMIT_SHA:0:7}
|
|
|
|
echo "📦 Version: $VERSION"
|
|
echo "🔑 Commit: $SHORT_COMMIT"
|
|
|
|
# Build apenas para teste (sem push)
|
|
docker buildx build \
|
|
--platform linux/amd64 \
|
|
--file Dockerfile.release \
|
|
--build-arg VERSION=$VERSION \
|
|
--build-arg COMMIT=$SHORT_COMMIT \
|
|
--tag $REGISTRY/$IMAGE_NAME:pr-${{ github.event.number }}-$SHORT_COMMIT \
|
|
--load \
|
|
.
|
|
|
|
- name: Security scan (opcional)
|
|
run: |
|
|
echo "🔒 Executando verificações de segurança..."
|
|
# Adicione suas verificações de segurança aqui
|
|
|
|
- name: PR Status Summary
|
|
run: |
|
|
echo "✅ Pull Request Validation Summary"
|
|
echo "🎯 Target Branch: ${{ github.base_ref }}"
|
|
echo "📂 Source Branch: ${{ github.head_ref }}"
|
|
echo "🧪 Tests: ${{ vars.SKIP_TESTS_PR == 'true' && 'SKIPPED' || 'PASSED' }}"
|
|
echo "🐳 Docker Build: PASSED"
|
|
echo "🔒 Security Scan: PASSED"
|
|
echo ""
|
|
echo "✨ PR está pronto para merge!"
|
|
|
|
# Job que só executa se a validação passou
|
|
ready-for-merge:
|
|
name: Ready for Merge
|
|
runs-on: ubuntu-latest
|
|
needs: [validate-pr]
|
|
if: success()
|
|
|
|
steps:
|
|
- name: Merge readiness
|
|
run: |
|
|
echo "🎉 Pull Request #${{ github.event.number }} passou em todas as validações!"
|
|
echo "✅ Pode ser feito o merge com segurança" |