Skip to content

Commit c88a98a

Browse files
authored
Merge branch 'mendix:development' into run/4677-add-tracing-filter-docs
2 parents 17ea882 + cde4b03 commit c88a98a

44 files changed

Lines changed: 599 additions & 855 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/branch-deletion-pr-creation.yml

Lines changed: 40 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
required: true
1313
default: 27
1414
type: number
15+
1516
jobs:
1617
identify-branches:
1718
if: github.repository_owner == 'mendix'
@@ -23,125 +24,85 @@ jobs:
2324
fetch-depth: 0
2425
token: ${{ secrets.GITHUB_TOKEN }}
2526
persist-credentials: true
26-
27+
28+
- name: Setup jq
29+
run: sudo apt-get install -y jq
30+
31+
- name: Create timestamp file
32+
run: |
33+
echo "Last scan for stale merged branches: $(TZ='Europe/Amsterdam' date +'%Y-%m-%d %H:%M:%S %Z (UTC%:z)')" > branch-cleanup-timestamp.txt
34+
2735
- name: Fetch all branches
2836
run: |
29-
echo "Fetching all branches from remote..."
3037
git fetch origin '+refs/heads/*:refs/remotes/origin/*' --prune
31-
echo "Fetched branches:"
32-
git branch -r
3338
3439
- name: Process branches
3540
id: branch-data
3641
run: |
3742
set -e
38-
echo "Finding all branches for processing..."
3943
ALL_BRANCHES=$(git branch -r | grep -v "origin/HEAD" | sed 's/origin\///')
40-
41-
echo "All branches found:"
42-
printf "%s\n" "${ALL_BRANCHES[@]}"
43-
4444
MIN_AGE_DAYS=${{ github.event.inputs.min_age_days || 27 }}
45-
46-
# Arrays to hold branches
45+
4746
PROTECTED_BRANCHES=()
4847
MERGED_BRANCHES_TO_PROCESS=()
4948
BRANCHES_TO_DELETE=()
5049
BRANCHES_TOO_RECENT=()
50+
UNMERGED_BRANCHES=()
5151
5252
CURRENT_DATE=$(date +%Y%m%d)
5353
echo "CURRENT_DATE=$CURRENT_DATE" >> $GITHUB_ENV
5454
55-
# Check branches
5655
for BRANCH in $ALL_BRANCHES; do
5756
branch_lower=$(echo "$BRANCH" | tr '[:upper:]' '[:lower:]')
58-
# Identify protected branches
5957
if [[ $branch_lower =~ (backup|development|main|master|production) ]]; then
60-
if git branch -r --merged origin/development | grep -q "origin/$BRANCH"; then
61-
PROTECTED_BRANCHES+=("$BRANCH (protected name, merged)")
62-
else
63-
PROTECTED_BRANCHES+=("$BRANCH (protected name, not merged)")
64-
fi
58+
PROTECTED_BRANCHES+=("$BRANCH (protected)")
59+
elif git branch -r --merged origin/development | grep -q "origin/$BRANCH"; then
60+
MERGED_BRANCHES_TO_PROCESS+=("$BRANCH")
6561
else
66-
# Process non-protected merged branches
67-
if git branch -r --merged origin/development | grep -q "origin/$BRANCH"; then
68-
MERGED_BRANCHES_TO_PROCESS+=("$BRANCH")
69-
else
70-
UNMERGED_BRANCHES+=("$BRANCH (not merged)")
71-
fi
62+
UNMERGED_BRANCHES+=("$BRANCH (not merged)")
7263
fi
7364
done
7465
75-
# Process potential deletion
7666
for BRANCH in "${MERGED_BRANCHES_TO_PROCESS[@]}"; do
77-
MERGE_HASH=$(git log --grep="Merge branch.*$BRANCH" origin/development -n 1 --pretty=format:"%H" ||
78-
git log --grep="Merge pull request.*$BRANCH" origin/development -n 1 --pretty=format:"%H")
67+
MERGE_HASH=$(git log --grep="Merge branch.*$BRANCH" origin/development -n 1 --pretty=format:"%H" || true)
7968
[ -z "$MERGE_HASH" ] && MERGE_HASH=$(git log -n 1 origin/$BRANCH --pretty=format:"%H")
80-
69+
8170
MERGE_DATE=$(git show -s --format=%ct $MERGE_HASH)
8271
DAYS_AGO=$(( ($(date +%s) - MERGE_DATE) / 86400 ))
83-
72+
8473
if [[ $DAYS_AGO -ge $MIN_AGE_DAYS ]]; then
85-
BRANCHES_TO_DELETE+=("$BRANCH ($DAYS_AGO days)")
74+
BRANCHES_TO_DELETE+=("$BRANCH")
8675
else
87-
BRANCHES_TOO_RECENT+=("$BRANCH ($DAYS_AGO days)")
76+
BRANCHES_TOO_RECENT+=("$BRANCH (too recent: ${DAYS_AGO}d)")
8877
fi
8978
done
9079
91-
# Display non-deleted branches for logging
92-
ALL_NON_DELETED_BRANCHES=("${PROTECTED_BRANCHES[@]}" "${BRANCHES_TOO_RECENT[@]}" "${UNMERGED_BRANCHES[@]}")
93-
IFS=$'\n' ALL_NON_DELETED_BRANCHES=($(sort <<<"${ALL_NON_DELETED_BRANCHES[*]}"))
94-
unset IFS
95-
96-
if [ ${#BRANCHES_TO_DELETE[@]} -eq 0 ]; then
97-
echo "No branches found for deletion."
98-
echo "NO_BRANCHES=true" >> $GITHUB_ENV
99-
exit 0
100-
else
101-
echo "NO_BRANCHES=false" >> $GITHUB_ENV
102-
fi
80+
ALL_NON_DELETED=(
81+
"${PROTECTED_BRANCHES[@]}"
82+
"${BRANCHES_TOO_RECENT[@]}"
83+
"${UNMERGED_BRANCHES[@]}"
84+
)
10385
104-
# Create report
105-
echo "# Branch Cleanup Report - $(date +%Y-%m-%d)" > branch-report.branchreport
106-
echo "## Branches for deletion (merged >=${MIN_AGE_DAYS} days ago):" >> branch-report.branchreport
107-
echo '```' >> branch-report.branchreport
108-
printf "%s\n" "${BRANCHES_TO_DELETE[@]}" >> branch-report.branchreport
109-
echo '```' >> branch-report.branchreport
110-
echo "## Branches not eligible for deletion:" >> branch-report.branchreport
111-
echo '```' >> branch-report.branchreport
112-
printf "%s\n" "${ALL_NON_DELETED_BRANCHES[@]}" >> branch-report.branchreport
113-
echo '```' >> branch-report.branchreport
114-
115-
echo "BRANCHES_TO_DELETE<<EOF" >> $GITHUB_ENV
116-
printf "%s\n" "${BRANCHES_TO_DELETE[@]}" >> $GITHUB_ENV
117-
echo "EOF" >> $GITHUB_ENV
118-
echo "ALL_NON_DELETED_BRANCHES<<EOF" >> $GITHUB_ENV
119-
printf "%s\n" "${ALL_NON_DELETED_BRANCHES[@]}" >> $GITHUB_ENV
120-
echo "EOF" >> $GITHUB_ENV
86+
echo "HAS_BRANCHES=$([ ${#BRANCHES_TO_DELETE[@]} -gt 0 ] && echo true || echo false)" >> $GITHUB_ENV
87+
echo "BRANCHES_TO_DELETE=$(printf -- '- %s\n' "${BRANCHES_TO_DELETE[@]}" | jq -Rs .)" >> $GITHUB_ENV
88+
echo "ALL_NON_DELETED=$(printf -- '- %s\n' "${ALL_NON_DELETED[@]}" | jq -Rs .)" >> $GITHUB_ENV
12189
12290
- name: Create Deletion PR
123-
if: env.NO_BRANCHES != 'true'
91+
if: env.HAS_BRANCHES == 'true'
12492
uses: peter-evans/create-pull-request@v6
12593
with:
126-
commit-message: "Branch cleanup proposal"
127-
title: "[AUTO] Branch Deletion Candidates - ${{ env.CURRENT_DATE }}"
94+
token: ${{ secrets.GITHUB_TOKEN }}
95+
title: "[Auto] Branch Deletion Candidates - ${{ env.CURRENT_DATE }}"
12896
body: |
129-
## Branches for deletion (merged to development)
130-
```
131-
${{ env.BRANCHES_TO_DELETE }}
132-
```
133-
134-
## Branches not eligible for deletion
135-
```
136-
${{ env.ALL_NON_DELETED_BRANCHES }}
137-
```
138-
## ⚠️ Warning
139-
Merging this PR will:
140-
1. Delete the branches listed in the "Branches for deletion" section.
141-
2. Remove the temporary branch-report.branchreport file.
142-
branch: branch-cleanup-${{ env.CURRENT_DATE }}
97+
### Branches for Deletion
98+
${{ fromJSON(env.BRANCHES_TO_DELETE) }}
99+
100+
### Protected/Recent Branches
101+
${{ fromJSON(env.ALL_NON_DELETED) }}
102+
base: development
103+
labels: Internal WIP
143104
assignees: MarkvanMents,OlufunkeMoronfolu
144105
reviewers: MarkvanMents,OlufunkeMoronfolu
145-
labels: Internal WIP
106+
commit-message: "Add branch cleanup candidates for ${{ env.CURRENT_DATE }}"
146107
add-paths: |
147-
branch-report.branchreport
108+
branch-cleanup-timestamp.txt
Lines changed: 34 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,62 @@
11
name: Branch Deletion Phase Two (PR Processing)
22
on:
33
pull_request:
4-
types:
5-
- closed
6-
branches:
7-
- 'development'
4+
types: [closed]
5+
branches: [development]
86
paths:
9-
- '**.branchreport'
7+
- 'branch-cleanup-timestamp.txt'
8+
109
permissions:
1110
contents: write
11+
1212
jobs:
13-
delete-branches-and-cleanup:
13+
process-approved-deletion:
1414
if: |
1515
github.event.pull_request.merged == true &&
16-
startsWith(github.event.pull_request.title, '[AUTO] Branch Deletion Candidates')
16+
startsWith(github.event.pull_request.title, '[Auto] Branch Deletion Candidates') &&
17+
contains(github.event.pull_request.labels.*.name, 'Internal WIP')
1718
runs-on: ubuntu-latest
1819
steps:
1920
- name: Checkout code
2021
uses: actions/checkout@v4
2122
with:
2223
fetch-depth: 0
23-
token: ${{ secrets.GITHUB_TOKEN }}
24-
ref: ${{ github.event.repository.default_branch }}
25-
- name: Delete branch report file
26-
run: |
27-
# Check if file exists and delete it
28-
if [ -f "branch-report.branchreport" ]; then
29-
# Configure Git with your username
30-
git config --global user.name "github-actions[bot]"
31-
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
3224

33-
git rm branch-report.branchreport
34-
git commit -m "Remove temporary branch report file"
35-
git push
36-
echo "Removed branch-report.branchreport file"
37-
else
38-
echo "branch-report.branchreport file not found"
39-
fi
40-
- name: Extract branches and delete
25+
- name: Extract branches
26+
id: extract-branches
4127
env:
4228
PR_BODY: ${{ github.event.pull_request.body }}
4329
run: |
44-
echo "PR Body Content:"
45-
echo "$PR_BODY"
46-
echo "-----------------------------------"
47-
48-
echo "Extracting branch names for deletion..."
49-
50-
# Extract lines between the markers using awk
51-
DELETION_LIST=$(echo "$PR_BODY" | awk '
52-
BEGIN { print_lines = 0; }
53-
/Branches for deletion/ { print_lines = 1; next; }
54-
/Branches not eligible for deletion/ { print_lines = 0; }
55-
print_lines == 1 && !/^```/ && NF > 0 {
56-
print $1;
57-
}
30+
BRANCHES=$(echo "$PR_BODY" | awk '
31+
/### Branches for Deletion/ {flag=1; next}
32+
/### Protected\/Recent Branches/ {flag=0}
33+
flag && /^-/ {gsub(/^-[ \t]*/, ""); print}
5834
')
35+
36+
CLEAN_BRANCHES=$(echo "$BRANCHES" | tr -d '\r' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
37+
echo "branches=$(jq -nc '$ARGS.positional' --args $CLEAN_BRANCHES)" >> $GITHUB_OUTPUT
38+
echo "Extracted branches: $BRANCHES"
5939
60-
echo "Branches identified for deletion:"
61-
echo "$DELETION_LIST"
62-
echo "-----------------------------------"
63-
64-
if [ -z "$DELETION_LIST" ]; then
65-
echo "No branches found for deletion"
66-
exit 0
67-
fi
68-
# Configure Git with your username
40+
- name: Delete branches
41+
env:
42+
BRANCHES: ${{ steps.extract-branches.outputs.branches }}
43+
run: |
6944
git config --global user.name "github-actions[bot]"
70-
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
71-
72-
# Process each branch
73-
echo "$DELETION_LIST" | while read -r BRANCH; do
74-
# Skip empty lines
75-
[ -z "$BRANCH" ] && continue
45+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
7646
77-
echo "Processing branch: '$BRANCH'"
78-
79-
# Final protection check
80-
branch_lower=$(echo "$BRANCH" | tr '[:upper:]' '[:lower:]')
81-
if [[ $branch_lower =~ (backup|development|main|master|production) ]]; then
82-
echo "Skipping protected branch: $BRANCH"
47+
echo "$BRANCHES" | jq -r '.[]' | while read -r branch; do
48+
branch_lower=$(echo "$branch" | tr '[:upper:]' '[:lower:]')
49+
50+
if [[ $branch_lower =~ ^(backup|development|main|master|production)(-[0-9]+)?$ ]]; then
51+
echo "Skipping protected branch: $branch"
8352
continue
8453
fi
85-
echo "Attempting to delete branch: $BRANCH"
86-
# Check if branch exists before trying to delete
87-
if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then
88-
echo "Branch exists, proceeding with deletion"
89-
git push origin --delete "$BRANCH" || {
90-
echo "Failed to delete branch: $BRANCH"
91-
echo "Error code: $?"
92-
}
54+
55+
if git ls-remote --exit-code --heads origin "$branch" >/dev/null; then
56+
echo "Deleting $branch"
57+
git push origin --delete "$branch"
58+
sleep 1
9359
else
94-
echo "Branch $BRANCH does not exist or is not accessible"
60+
echo "Branch $branch does not exist"
9561
fi
9662
done

branch-cleanup-timestamp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Last scan: Fri Nov 7 09:17:19 UTC 2025

0 commit comments

Comments
 (0)