Merge pull request 'fix: pr validation' (#6) from feat/live-preview into Release/V0.0.3
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/BCards/pulls/6
This commit is contained in:
commit
71a214bd13
@ -0,0 +1,111 @@
|
||||
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 \
|
||||
--output type=docker \
|
||||
.
|
||||
|
||||
- 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"
|
||||
@ -24,7 +24,7 @@ RUN apt-get update && \
|
||||
RUN mkdir -p /app/uploads /app/logs \
|
||||
&& chmod 755 /app/uploads /app/logs
|
||||
|
||||
# Build stage - use build platform for compilation
|
||||
# Build stage - restore and publish
|
||||
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG TARGETPLATFORM
|
||||
ARG VERSION
|
||||
@ -41,44 +41,24 @@ RUN case "$TARGETPLATFORM" in \
|
||||
"linux/arm64") RID="linux-arm64" ;; \
|
||||
*) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
|
||||
esac && \
|
||||
echo "🏗️ Restoring for platform: $TARGETPLATFORM -> RID: $RID" && \
|
||||
echo "🔧 Restoring for RID: $RID" && \
|
||||
dotnet restore "src/BCards.Web/BCards.Web.csproj" --runtime $RID
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
WORKDIR "/src/src/BCards.Web"
|
||||
|
||||
# Build application with Release configuration
|
||||
RUN case "$TARGETPLATFORM" in \
|
||||
"linux/amd64") RID="linux-x64" ;; \
|
||||
"linux/arm64") RID="linux-arm64" ;; \
|
||||
esac && \
|
||||
echo "🔨 Building for RID: $RID" && \
|
||||
dotnet build "BCards.Web.csproj" \
|
||||
-c Release \
|
||||
-o /app/build \
|
||||
--no-restore \
|
||||
--runtime $RID \
|
||||
-p:Version=$VERSION \
|
||||
-p:InformationalVersion=$COMMIT
|
||||
|
||||
# Publish stage - optimize for target platform
|
||||
FROM build AS publish
|
||||
ARG TARGETPLATFORM
|
||||
ARG VERSION
|
||||
ARG COMMIT
|
||||
|
||||
# Publish with cross-compilation friendly settings
|
||||
# Publish diretamente (build + publish em um comando)
|
||||
RUN case "$TARGETPLATFORM" in \
|
||||
"linux/amd64") RID="linux-x64" ;; \
|
||||
"linux/arm64") RID="linux-arm64" ;; \
|
||||
*) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
|
||||
esac && \
|
||||
echo "📦 Publishing for RID: $RID" && \
|
||||
dotnet publish "BCards.Web.csproj" \
|
||||
-c Release \
|
||||
-o /app/publish \
|
||||
--no-restore \
|
||||
--no-build \
|
||||
--runtime $RID \
|
||||
--self-contained false \
|
||||
-p:PublishReadyToRun=false \
|
||||
@ -103,7 +83,7 @@ LABEL environment="release"
|
||||
WORKDIR /app
|
||||
|
||||
# Copy published application
|
||||
COPY --from=publish /app/publish .
|
||||
COPY --from=build /app/publish .
|
||||
|
||||
# Create non-root user for security
|
||||
RUN groupadd -r bcards && useradd -r -g bcards bcards \
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
|
||||
<RuntimeIdentifiers>linux-x64;linux-arm64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user