Skip to content

Commit

Permalink
Merge pull request #519 from LerianStudio/feature/MIDAZ-515
Browse files Browse the repository at this point in the history
feature/MIDAZ-515
  • Loading branch information
MartinezAvellan authored Feb 14, 2025
2 parents 22e353d + 2568d2b commit 7e251ff
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
79 changes: 79 additions & 0 deletions .github/workflows/env-vars-pr-notification.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/update-env-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e251ff

Please sign in to comment.