Merge pull request #3855 from expsa/dev_odex25_purchase_dummy

Update delete-merged-branches.yml
This commit is contained in:
شركة خبير المحدودة 2025-07-10 16:48:00 +03:00 committed by GitHub
commit ffa86be8bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 42 additions and 40 deletions

View File

@ -1,41 +1,43 @@
# Author: Ahmad Samir <a.atta@exp-sa.com>
name: Auto Delete Branch After Merge
on:
pull_request:
types: [closed] # triggers when PR is closed (merged or just closed)
jobs:
delete-merged-branch:
if: github.event.pull_request.merged == true
name: Delete Merged Branch
runs-on: app-sever-project-runner # your self-hosted runner
steps:
- name: Delete merged branch (with rules)
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
REPO: ${{ github.repository }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
echo "🔍 Base branch: $BASE_REF"
echo "🔍 Head branch: $HEAD_REF"
# ❌ Do not delete dev_* merged into preprod_*
if [[ "$HEAD_REF" == dev_* && "$BASE_REF" == preprod_* ]]; then
echo "🚫 Rule: Do not delete dev_* merged into preprod_*"
exit 0
fi
# ❌ Do not delete preprod_* merged into master_*
if [[ "$HEAD_REF" == preprod_* && "$BASE_REF" == master_* ]]; then
echo "🚫 Rule: Do not delete preprod_* merged into master_*"
exit 0
fi
echo "✅ Allowed to delete '$HEAD_REF' from '$REPO'"
curl -s -X DELETE -H "Authorization: token $GH_TOKEN" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/$REPO/git/refs/heads/$HEAD_REF -w "
🧹 Deleted branch '$HEAD_REF' from '$REPO' — HTTP %{http_code}
"
name: Auto Delete Branch After Merge
on:
pull_request:
types: [closed]
jobs:
delete-merged-branch:
if: github.event.pull_request.merged == true
name: Delete Merged Branch
runs-on: app-sever-project-runner
steps:
- name: Delete merged branch (with rules)
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
REPO: ${{ github.repository }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
echo "🔍 Base branch: $BASE_REF"
echo "🔍 Head branch: $HEAD_REF"
# ❌ Do not delete dev_* merged into preprod_*
if [[ "$HEAD_REF" == dev_* && "$BASE_REF" == preprod_* ]]; then
echo "🚫 Rule: Do not delete dev_* merged into preprod_*"
exit 0
fi
# ❌ Do not delete preprod_* merged into master_*
if [[ "$HEAD_REF" == preprod_* && "$BASE_REF" == master_* ]]; then
echo "🚫 Rule: Do not delete preprod_* merged into master_*"
exit 0
fi
echo "✅ Allowed to delete '$HEAD_REF' from '$REPO'"
curl -s -X DELETE \
-H "Authorization: token $GH_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$REPO/git/refs/heads/$HEAD_REF \
-w "🧹 Deleted branch '$HEAD_REF' from '$REPO' — HTTP %{http_code}\n"