merge: develop to main; #55
This file contains 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: '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 |