feat: add sns notification email when deploy is success #22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI - Build and Test | |
| on: | |
| push: | |
| branches: [main, develop, 'feature/*'] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| GO_VERSION: '1.24.5' | |
| AWS_REGION: us-east-1 | |
| jobs: | |
| # Job 1: Lint e validação de código básica | |
| lint: | |
| name: Lint and Code Quality | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Make test script executable | |
| run: chmod +x run_tests.sh | |
| - name: Download dependencies and verify | |
| run: | | |
| go mod download | |
| go mod verify | |
| - name: Run go vet | |
| run: go vet ./... | |
| - name: Check formatting | |
| run: | | |
| if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then | |
| echo "The following files are not properly formatted:" | |
| gofmt -s -l . | |
| exit 1 | |
| fi | |
| - name: Run linting with our script | |
| run: ./run_tests.sh lint | |
| # Job 2: Testes unitários | |
| test: | |
| name: Unit Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Make test script executable | |
| run: chmod +x run_tests.sh | |
| - name: Run unit tests | |
| run: ./run_tests.sh unit | |
| - name: Upload coverage reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: | | |
| coverage/coverage.out | |
| coverage/coverage.html | |
| if: always() | |
| # Job 3: Cobertura completa e benchmarks | |
| coverage: | |
| name: Coverage & Benchmarks | |
| runs-on: ubuntu-latest | |
| needs: [test] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Make test script executable | |
| run: chmod +x run_tests.sh | |
| - name: Run coverage tests | |
| run: ./run_tests.sh coverage | |
| - name: Run benchmarks | |
| run: ./run_tests.sh bench | |
| - name: Run race detector tests | |
| run: ./run_tests.sh race | |
| - name: Upload detailed coverage reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: detailed-coverage-report | |
| path: | | |
| coverage/ | |
| if: always() | |
| # Job 4: Build e validação do Docker | |
| build: | |
| name: Build Docker Image | |
| runs-on: ubuntu-latest | |
| needs: [lint, test, coverage] | |
| outputs: | |
| image-digest: ${{ steps.build.outputs.digest }} | |
| build-success: ${{ steps.build.outputs.success }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build Docker image | |
| id: build | |
| run: | | |
| set -euo pipefail | |
| echo "🐳 Building Docker image..." | |
| # Build da imagem com platform específica para Lambda | |
| docker build \ | |
| --platform linux/amd64 \ | |
| --tag test-image:${{ github.sha }} \ | |
| --load \ | |
| . | |
| # Verificar se a imagem foi criada com sucesso | |
| echo "✅ Docker image built successfully" | |
| echo "success=true" >> "$GITHUB_OUTPUT" | |
| # Verificar se a imagem existe | |
| if docker inspect test-image:${{ github.sha }} >/dev/null 2>&1; then | |
| echo "✅ Image verification passed" | |
| echo "digest=local-build-${{ github.sha }}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "❌ Docker image verification failed" | |
| echo "success=false" >> "$GITHUB_OUTPUT" | |
| exit 1 | |
| fi | |
| - name: Test Docker image | |
| run: | | |
| set -euo pipefail | |
| echo "🧪 Testing Docker image..." | |
| # Verificar se a imagem existe e é válida | |
| if docker inspect test-image:${{ github.sha }} >/dev/null 2>&1; then | |
| echo "✅ Docker image exists and is valid" | |
| # Obter informações básicas da imagem | |
| CREATED=$(docker inspect test-image:${{ github.sha }} --format='{{.Created}}' | cut -c1-19) | |
| SIZE=$(docker inspect test-image:${{ github.sha }} --format='{{.Size}}') | |
| echo "Created: ${CREATED}" | |
| echo "Size: ${SIZE} bytes" | |
| echo "✅ Container validation passed" | |
| else | |
| echo "❌ Docker image validation failed" | |
| exit 1 | |
| fi | |
| - name: Validate Terraform syntax | |
| run: | | |
| set -euo pipefail | |
| echo "🔍 Validating Terraform syntax..." | |
| # Install Terraform | |
| wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg | |
| echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list | |
| sudo apt update && sudo apt install terraform | |
| # Validate Terraform files | |
| cd terraform | |
| terraform init -backend=false | |
| terraform validate | |
| terraform fmt -check -recursive | |
| # Job 5: Relatório final do CI | |
| ci-success: | |
| name: CI Success | |
| runs-on: ubuntu-latest | |
| needs: [lint, test, coverage, build] | |
| if: always() | |
| steps: | |
| - name: Check CI status | |
| run: | | |
| set -euo pipefail | |
| echo "=== CI RESULTS ===" | |
| echo "Lint: ${{ needs.lint.result }}" | |
| echo "Test: ${{ needs.test.result }}" | |
| echo "Coverage: ${{ needs.coverage.result }}" | |
| echo "Build: ${{ needs.build.result }}" | |
| if [[ "${{ needs.lint.result }}" == "success" && | |
| "${{ needs.test.result }}" == "success" && | |
| "${{ needs.coverage.result }}" == "success" && | |
| "${{ needs.build.result }}" == "success" ]]; then | |
| echo "✅ All CI checks passed! Ready for deployment." | |
| exit 0 | |
| else | |
| echo "❌ Some CI checks failed. Deployment will be blocked." | |
| exit 1 | |
| fi |