diff --git a/.github/workflows/env-vars-pr-notification.yml b/.github/workflows/env-vars-pr-notification.yml new file mode 100644 index 00000000..9ab32be8 --- /dev/null +++ b/.github/workflows/env-vars-pr-notification.yml @@ -0,0 +1,79 @@ +name: 'Notify DevOps Team on PR with .env.example file' + +on: + pull_request: + branches: + - 'main' # Apenas para PRs direcionados para a main + paths: + - 'components/*/.env.example' # Tracking env vars file + +jobs: + notify_devops: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetches the full commit history + + - name: Check the current branch + run: | + echo "Current branch:" + git branch + echo "Current commit history:" + git log --oneline -n 5 # Shows the last 5 commits to verify if the commit is present + + - name: Check for changes in .env.example files + run: | + echo "Checking for changes in .env.example..." + + # Definindo os commits dinamicamente + PREVIOUS_COMMIT=$(git rev-parse HEAD~1) + CURRENT_COMMIT=$(git rev-parse HEAD) + + # Inicializando variável CHANGED + CHANGED=false + + # Verificando se os arquivos .env.example mudaram + for file in $(git diff --name-only $PREVIOUS_COMMIT $CURRENT_COMMIT | grep -E 'components/(audit|auth|infra|ledger|mdz|transaction)/.*\.env.example'); do + # Exibindo qual arquivo estamos verificando + echo "Checking file: $file" + + # Verificando as mudanças no arquivo, mas excluindo as linhas que começam com 'VERSION=' + if git diff --ignore-matching-lines='^VERSION=.*' $PREVIOUS_COMMIT $CURRENT_COMMIT -- "$file" | grep -q .; then + echo "File $file has changes!" + CHANGED=true + break + else + echo "No relevant changes in $file" + fi + done # Fechando o loop "for" aqui + + # Determinando se o arquivo mudou ou não (fora do loop) + if [ "$CHANGED" = true ]; then + echo "File .env.example changed!" + echo "file_changed=true" >> $GITHUB_ENV + else + echo "File .env.example not changed." + echo "file_changed=false" >> $GITHUB_ENV + fi + + - name: Send Slack Notification if file changed + if: env.file_changed == 'true' # Only send notification if the file was changed + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_WEBHOOK: ${{ secrets.RELEASE_WEBHOOK_NOTIFICATION_URL }} + SLACK_COLOR: "#ff0000" # Red color + SLACK_CHANNEL: "Marvin" + SLACK_ICON_EMOJI: ":memo:" + SLACK_TITLE: "New PR with .env.example changes!" + SLACK_MESSAGE: | + :bell: **A new PR has changes in the `.env.example` file!** :warning: + + **PR Title:** ${{ github.event.pull_request.title }} + **PR URL:** ${{ github.event.pull_request.html_url }} + + Please review the changes made to the `.env.example` file. + + @LerianStudio/G_Github_Devops @LerianStudio/G_Github_Dev diff --git a/.github/workflows/update-env-version.yml b/.github/workflows/update-env-version.yml index 2b4521b2..5101f850 100644 --- a/.github/workflows/update-env-version.yml +++ b/.github/workflows/update-env-version.yml @@ -72,7 +72,7 @@ jobs: run: | sed -i "s/^VERSION=.*/VERSION=${{ steps.latest_release.outputs.tag }}/" ./components/audit/.env.example - - name: Update LEDGER Env + - name: Update ONBOARDING Env if: steps.latest_release.outputs.tag != steps.env_release.outputs.version run: | sed -i "s/^VERSION=.*/VERSION=${{ steps.latest_release.outputs.tag }}/" ./components/onboarding/.env.example