Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f8a1338
merge develop into main (#8) (#12)
RenanRoseno Aug 23, 2025
3b99c3b
Feature/add node version config + tests + lint (#9)
Batavoo Aug 23, 2025
945efed
💚 feat: add sonarqube scan and quality gate (#15)
v-venes Sep 1, 2025
b28fbfd
feature/add disc webhook (#16)
PedroPLSR Sep 1, 2025
ef3de09
Feature/add metrics endpoint (#18)
v-venes Sep 1, 2025
2e3d6b3
Feature/add metrics endpoint (#19)
v-venes Sep 1, 2025
3d0c4d2
💚 ci: fix deploy pipelines
v-venes Sep 1, 2025
8bba0a1
💚 ci: fix deploy pipelines
v-venes Sep 1, 2025
6aa20a4
💚 ci: fix deploy pipelines
v-venes Sep 1, 2025
888efad
💚 ci: fix deploy pipelines
v-venes Sep 1, 2025
fe182a4
💚 ci: fix deploy pipelines
v-venes Sep 1, 2025
56dfe0a
💚 ci: fix deploy pipelines
v-venes Sep 1, 2025
13d1808
💚 ci: fix deploy pipelines
v-venes Sep 2, 2025
8099580
💚 ci: backend to save terraform state
v-venes Sep 2, 2025
a5d4bf0
💚 ci: terraform output to send in notification
v-venes Sep 2, 2025
7cea0a3
💚 ci: terraform output to send in notification
v-venes Sep 2, 2025
ab39c75
💚 ci: terraform output to send in notification
v-venes Sep 2, 2025
4bb16b7
💚 ci: terraform output to send in notification
v-venes Sep 2, 2025
3ceb025
💚 ci: temp deploy to prod
v-venes Sep 5, 2025
3c73f7f
🎨 chore: fix conflicts
v-venes Sep 5, 2025
ede362e
Develop to Prod (#21) (#22)
RenanRoseno Sep 5, 2025
00ac15e
feat: update gitignore
RenanRoseno Sep 5, 2025
54d8ef8
Bugfix/change fulano not (#25)
PedroPLSR Sep 6, 2025
6138f7d
🧪 feat: increase test coverage (#26)
v-venes Sep 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 89 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,103 @@
name: CI/CD - Restaurant Management API

on:
push:
branches: [ main , develop]
pull_request:
branches: [ main, develop ]
branches: [main, develop]

jobs:

integration:
notify-fail:
runs-on: ubuntu-latest
if: failure()
needs: [check, test, build, sonar-analyze]
steps:
- name: 📣 Fail discord notification
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
username: 'fulano triste'
avatar-url: 'https://media.discordapp.net/attachments/1413674985263730709/1413677177345413171/image0.jpg?ex=68bcccf7&is=68bb7b77&hm=13bdc8f5aab111255c822cd1a973b25a6e1835d73b825256b8f5e586829cd847&=&format=webp&width=765&height=930'
embed-title: 'Pipeline CI'
embed-description: '❌ Pipeline falhou! affs...'
embed-color: 14553088
embed-thumbnail-url: 'https://media.discordapp.net/attachments/1413674985263730709/1413675507714887771/image0.jpg?ex=68bccb69&is=68bb79e9&hm=c1697b707e5afd5f4526467b135516ff06a76da633e6bc03224faf4ceaff77aa&=&format=webp&width=365&height=402'
embed-author-name: 'Github Actions'
embed-author-icon-url: 'https://cdn-icons-png.flaticon.com/512/25/25231.png'

notify-success:
runs-on: ubuntu-latest
if: success()
needs: [check, test, build, sonar-analyze]
steps:
- name: 📣 Success discord notification
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
username: 'fulano'
avatar-url: 'https://cdn.discordapp.com/attachments/1413674985263730709/1413675018742923345/3bf.jpg?ex=68bccaf5&is=68bb7975&hm=d05cc7dc1c4c16fdb2c96f147e84d59a81eb5141479779e6b584ae32ad1261d7&'
embed-title: 'Pipeline CI'
embed-description: '✅ Pipeline concluída com sucesso! eba 🎉'
embed-color: 2067276
embed-thumbnail-url: 'https://media.discordapp.net/attachments/1413674985263730709/1413675507714887771/image0.jpg?ex=68bccb69&is=68bb79e9&hm=c1697b707e5afd5f4526467b135516ff06a76da633e6bc03224faf4ceaff77aa&=&format=webp&width=365&height=402'
embed-author-name: 'Github Actions'
embed-author-icon-url: 'https://cdn-icons-png.flaticon.com/512/25/25231.png'

sonar-analyze:
runs-on: ubuntu-latest

steps:
- name: 📥 Verificar branches conflitantes
- name: 📥 Checkout do código
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: 🔑 Configurar credenciais do Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: 🔍 Testar merge main <- develop
run: |
git fetch origin
git checkout main
git merge --no-commit --no-ff origin/develop || (
echo "❌ Conflitos detectados entre main e develop" && exit 1
)
git merge --abort || true
echo "✅ Nenhum conflito entre main e develop"
fetch-depth: 0

- name: 🟢 Configurar Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: 📦 Instalar dependências
run: npm install

- name: ✅ Rodar testes e gerar cobertura
run: npm run test:coverage

- name: 🔍️ Sonar scan
uses: SonarSource/sonarqube-scan-action@v5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

# Comentando pra não ficar dando erro
# - name: 🚩 Sonar quality gate
# uses: SonarSource/sonarqube-quality-gate-action@v1
# timeout-minutes: 5
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

# Adicionar essa na de PR de DEV para PROD
# integration:
# runs-on: ubuntu-latest
#
# steps:
# - name: 📥 Verificar branches conflitantes
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
#
# - name: 🔑 Configurar credenciais do Git
# run: |
# git config user.name "github-actions[bot]"
# git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# - name: 🔍 Testar merge main <- develop
# run: |
# git fetch origin
# git checkout main
# git merge --no-commit --no-ff origin/develop || (
# echo "❌ Conflitos detectados entre main e develop" && exit 1
# )
# git merge --abort || true
# echo "✅ Nenhum conflito entre main e develop"
check:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -86,13 +154,3 @@ jobs:

- name: 🚀 Build do projeto
run: npm run build

deploy:
runs-on: ubuntu-latest

steps:
- name: 📥 Checkout do código
uses: actions/checkout@v4

- name: 📦 Instalar dependências
run: npm install
155 changes: 155 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
name: Deploy to Dev

on:
push:
branches: [develop]

env:
PROJECT_ID: ${{ secrets.GCP_PROJECT }}
REGION: us-east1
REPOSITORY: trabalho-pos
SERVICE_NAME: api-restaurant-dev
IMAGE_TAG: ${{ github.sha }}
CREDENTIALS_FILE: /tmp/gcp-credentials.json

jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Google Auth
id: auth
uses: 'google-github-actions/auth@v3'
with:
credentials_json: '${{ secrets.GCP_SA_KEY }}'
project_id: ${{ env.PROJECT_ID }}

- name: Configure Docker for Artifact Registry
run: |
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
gcloud auth list

- name: Create Repository if not exists
run: |
if ! gcloud artifacts repositories describe ${{ env.REPOSITORY }} --location=${{ env.REGION }} 2>/dev/null; then
echo "Creating repository ${{ env.REPOSITORY }} in ${{ env.REGION }}..."
gcloud artifacts repositories create ${{ env.REPOSITORY }} \
--repository-format=docker \
--location=${{ env.REGION }} \
--description="Docker repository for API"
else
echo "Repository ${{ env.REPOSITORY }} already exists"
fi

- name: Build Docker image
run: |
docker build -t ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE_NAME }}:${{ github.sha }} .

- name: Push Docker image
run: |
docker push ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE_NAME }}:${{ github.sha }}

- name: Verify Image Push
run: |
gcloud artifacts docker images list ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}

deploy:
name: Deploy to Cloud Run
runs-on: ubuntu-latest
needs: build-and-push
environment: dev
outputs:
service_url: ${{ steps.get-url.outputs.service_url }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Save GCP Credentials
run: |
echo '${{ secrets.GCP_SA_KEY }}' > ${{ env.CREDENTIALS_FILE }}

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false

- name: Terraform Init with Backend
working-directory: ./infra/dev
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ env.CREDENTIALS_FILE }}
run: |
terraform init -reconfigure \
-backend-config="bucket=tf-state-${{ env.PROJECT_ID }}" \
-backend-config="prefix=terraform/dev"

- name: Terraform Apply
working-directory: ./infra/dev
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ env.CREDENTIALS_FILE }}
run: |
terraform apply -auto-approve \
-var="project_id=${{ env.PROJECT_ID }}" \
-var="image_url=${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE_NAME }}:${{ github.sha }}"

- name: Get Cloud Run URL
id: get-url
working-directory: ./infra/dev
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ env.CREDENTIALS_FILE }}
run: |
SERVICE_URL=$(terraform output service_url)
echo "service_url=$SERVICE_URL" >> $GITHUB_OUTPUT

- name: Cleanup Credentials
if: always()
run: rm -f ${{ env.CREDENTIALS_FILE }}

notify-fail:
runs-on: ubuntu-latest
if: failure()
needs: [build-and-push, deploy]
steps:
- name: Generate Action Link
run: |
ACTION_LINK="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
echo "ACTION_LINK=$ACTION_LINK" >> $GITHUB_ENV

- name: 📣 Fail discord notification
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
username: 'fulano triste'
avatar-url: 'https://media.discordapp.net/attachments/1413674985263730709/1413677177345413171/image0.jpg?ex=68bcccf7&is=68bb7b77&hm=13bdc8f5aab111255c822cd1a973b25a6e1835d73b825256b8f5e586829cd847&=&format=webp&width=765&height=930'
embed-title: 'Deploy DEV'
embed-description: '❌ Falha ao fazer deploy da api em DEV! oh céus...'
embed-color: 14553088
embed-thumbnail-url: 'https://e7.pngegg.com/pngimages/834/472/png-clipart-google-cloud-icon-google-cloud-platform-cloud-computing-amazon-web-services-virtual-private-cloud-cloud-computing-text-trademark.png'
embed-author-name: 'Github Actions'
embed-author-icon-url: 'https://cdn-icons-png.flaticon.com/512/25/25231.png'
embed-footer-text: 'URL da execução: ${{ env.ACTION_LINK }}'
embed-footer-icon-url: 'https://cdn-icons-png.flaticon.com/512/25/25231.png'

notify-success:
runs-on: ubuntu-latest
if: success()
needs: [build-and-push, deploy]
steps:
- name: 📣 Success discord notification
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
username: 'fulano'
avatar-url: 'https://cdn.discordapp.com/attachments/1413674985263730709/1413675018742923345/3bf.jpg?ex=68bccaf5&is=68bb7975&hm=d05cc7dc1c4c16fdb2c96f147e84d59a81eb5141479779e6b584ae32ad1261d7&'
embed-title: 'Deploy DEV'
embed-description: '✅ O Deploy da api em DEV foi realizado com sucesso! eba 🎉'
embed-color: 2067276
embed-thumbnail-url: 'https://e7.pngegg.com/pngimages/834/472/png-clipart-google-cloud-icon-google-cloud-platform-cloud-computing-amazon-web-services-virtual-private-cloud-cloud-computing-text-trademark.png'
embed-author-name: 'Github Actions'
embed-author-icon-url: 'https://cdn-icons-png.flaticon.com/512/25/25231.png'
embed-footer-text: 'URL da api: ${{ needs.deploy.outputs.service_url }}'
embed-footer-icon-url: 'https://cdn-icons-png.flaticon.com/512/25/25231.png'
Loading