From 3b1a356e35bf4db00198f6b888b5b406237ef0f6 Mon Sep 17 00:00:00 2001
From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com>
Date: Thu, 24 Jul 2025 11:07:25 -0300
Subject: [PATCH 1/7] fix: pr validation
---
.gitea/workflows/pr-validation.yml | 102 +++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/.gitea/workflows/pr-validation.yml b/.gitea/workflows/pr-validation.yml
index e69de29..8a90dee 100644
--- a/.gitea/workflows/pr-validation.yml
+++ b/.gitea/workflows/pr-validation.yml
@@ -0,0 +1,102 @@
+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"
+ dotnet test --no-build --configuration Release --verbosity normal
+
+ - 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"
\ No newline at end of file
--
2.45.2
From 4500b927ad3885728a4ccf1061cda273fa63a407 Mon Sep 17 00:00:00 2001
From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com>
Date: Fri, 25 Jul 2025 19:24:14 -0300
Subject: [PATCH 2/7] fix: pular testas se estiver nas variaveis
---
.gitea/workflows/pr-validation.yml | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/.gitea/workflows/pr-validation.yml b/.gitea/workflows/pr-validation.yml
index 8a90dee..a7b78fe 100644
--- a/.gitea/workflows/pr-validation.yml
+++ b/.gitea/workflows/pr-validation.yml
@@ -46,7 +46,16 @@ jobs:
if: ${{ vars.SKIP_TESTS_PR != 'true' }}
run: |
echo "🧪 Executando testes no PR"
- dotnet test --no-build --configuration Release --verbosity normal
+ 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: |
--
2.45.2
From 764d8a62f672db4f5dc04755542eaa356cbee520 Mon Sep 17 00:00:00 2001
From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com>
Date: Fri, 25 Jul 2025 19:37:03 -0300
Subject: [PATCH 3/7] fix: build multiplataforma
---
Dockerfile.release | 5 ++---
src/BCards.Web/BCards.Web.csproj | 1 +
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/Dockerfile.release b/Dockerfile.release
index 19c4405..b3b5662 100644
--- a/Dockerfile.release
+++ b/Dockerfile.release
@@ -39,10 +39,9 @@ COPY ["src/BCards.Web/BCards.Web.csproj", "src/BCards.Web/"]
RUN case "$TARGETPLATFORM" in \
"linux/amd64") RID="linux-x64" ;; \
"linux/arm64") RID="linux-arm64" ;; \
- *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
esac && \
- echo "🏗️ Restoring for platform: $TARGETPLATFORM -> RID: $RID" && \
- dotnet restore "src/BCards.Web/BCards.Web.csproj" --runtime $RID
+ echo "🔧 Restoring for RID: $RID" && \
+ dotnet restore "BCards.Web.csproj" --runtime $RID
# Copy source code
COPY . .
diff --git a/src/BCards.Web/BCards.Web.csproj b/src/BCards.Web/BCards.Web.csproj
index 30f20a7..33c6766 100644
--- a/src/BCards.Web/BCards.Web.csproj
+++ b/src/BCards.Web/BCards.Web.csproj
@@ -5,6 +5,7 @@
enable
enable
false
+ linux-x64;linux-arm64
--
2.45.2
From ceec4a2ef2d8f13e56e8e20a16b28d11b5fb1e72 Mon Sep 17 00:00:00 2001
From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com>
Date: Fri, 25 Jul 2025 19:40:51 -0300
Subject: [PATCH 4/7] fix: buildx
---
.gitea/workflows/pr-validation.yml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/.gitea/workflows/pr-validation.yml b/.gitea/workflows/pr-validation.yml
index a7b78fe..1a7fcc9 100644
--- a/.gitea/workflows/pr-validation.yml
+++ b/.gitea/workflows/pr-validation.yml
@@ -73,14 +73,13 @@ jobs:
# 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..."
--
2.45.2
From c25eea5f03dc2653bc26adc3ddcb2a124734fc1d Mon Sep 17 00:00:00 2001
From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com>
Date: Fri, 25 Jul 2025 19:42:45 -0300
Subject: [PATCH 5/7] fix: build para amd/x86
---
.gitea/workflows/pr-validation.yml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/.gitea/workflows/pr-validation.yml b/.gitea/workflows/pr-validation.yml
index 1a7fcc9..0110e0e 100644
--- a/.gitea/workflows/pr-validation.yml
+++ b/.gitea/workflows/pr-validation.yml
@@ -73,11 +73,12 @@ jobs:
# 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 \
+ --output type=docker \
.
- name: Security scan (opcional)
--
2.45.2
From 660959bd4c816033e9ca4b3f3d10fa6937749795 Mon Sep 17 00:00:00 2001
From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com>
Date: Fri, 25 Jul 2025 19:49:52 -0300
Subject: [PATCH 6/7] fix: dockerbuild.release
---
Dockerfile.release | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Dockerfile.release b/Dockerfile.release
index b3b5662..8f3be1c 100644
--- a/Dockerfile.release
+++ b/Dockerfile.release
@@ -41,7 +41,7 @@ RUN case "$TARGETPLATFORM" in \
"linux/arm64") RID="linux-arm64" ;; \
esac && \
echo "🔧 Restoring for RID: $RID" && \
- dotnet restore "BCards.Web.csproj" --runtime $RID
+ dotnet restore "src/BCards.Web/BCards.Web.csproj" --runtime $RID
# Copy source code
COPY . .
--
2.45.2
From efb6a4e5d7150d3a04aca9dbcd77a2327848e981 Mon Sep 17 00:00:00 2001
From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com>
Date: Fri, 25 Jul 2025 19:55:45 -0300
Subject: [PATCH 7/7] fix: novo publish stage no dockerfile.release
---
Dockerfile.release | 31 ++++++-------------------------
1 file changed, 6 insertions(+), 25 deletions(-)
diff --git a/Dockerfile.release b/Dockerfile.release
index 8f3be1c..334c100 100644
--- a/Dockerfile.release
+++ b/Dockerfile.release
@@ -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
@@ -39,6 +39,7 @@ COPY ["src/BCards.Web/BCards.Web.csproj", "src/BCards.Web/"]
RUN case "$TARGETPLATFORM" in \
"linux/amd64") RID="linux-x64" ;; \
"linux/arm64") RID="linux-arm64" ;; \
+ *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
esac && \
echo "🔧 Restoring for RID: $RID" && \
dotnet restore "src/BCards.Web/BCards.Web.csproj" --runtime $RID
@@ -47,37 +48,17 @@ RUN case "$TARGETPLATFORM" in \
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 \
@@ -102,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 \
@@ -136,4 +117,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
USER bcards
# Entry point with optimized runtime settings
-ENTRYPOINT ["dotnet", "BCards.Web.dll"]
\ No newline at end of file
+ENTRYPOINT ["dotnet", "BCards.Web.dll"]
--
2.45.2