-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (122 loc) · 5.03 KB
/
post-merge-cleanup.yml
File metadata and controls
138 lines (122 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Post-Merge Cleanup
on:
pull_request:
types: [closed]
branches:
- master
- main
jobs:
cleanup-consolidated-prs:
name: Clean up consolidated PRs and branches
runs-on: ubuntu-latest
# Only run if PR was merged (not just closed)
if: github.event.pull_request.merged == true
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check if this is the consolidation PR
id: check_consolidation
run: |
# Check if PR title or description mentions consolidation
PR_TITLE="${{ github.event.pull_request.title }}"
PR_BODY="${{ github.event.pull_request.body }}"
if [[ "$PR_TITLE" == *"Consolidate"* ]] || [[ "$PR_TITLE" == *"consolidate"* ]] || \
[[ "$PR_BODY" == *"PRs Consolidated"* ]] || [[ "$PR_BODY" == *"consolidat"* ]]; then
echo "is_consolidation=true" >> $GITHUB_OUTPUT
echo "This is a consolidation PR - will perform cleanup"
else
echo "is_consolidation=false" >> $GITHUB_OUTPUT
echo "Not a consolidation PR - skipping cleanup"
fi
- name: Close consolidated PRs
if: steps.check_consolidation.outputs.is_consolidation == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
// List of PR numbers to close (from consolidation)
const prsToClose = [1, 7, 8, 10, 12, 14, 15];
// Add comment and close each PR
for (const prNumber of prsToClose) {
try {
// Check if PR exists and is open
const { data: pr } = await github.rest.pulls.get({
owner,
repo,
pull_number: prNumber
});
if (pr.state === 'open') {
// Add comment explaining consolidation
await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: `This PR has been consolidated into #${{ github.event.pull_request.number }} and merged to master.\n\nAll changes from this PR are included in the consolidated merge. Closing as completed.`
});
// Close the PR
await github.rest.pulls.update({
owner,
repo,
pull_number: prNumber,
state: 'closed'
});
console.log(`✅ Closed PR #${prNumber}`);
} else {
console.log(`ℹ️ PR #${prNumber} is already ${pr.state}`);
}
} catch (error) {
console.log(`⚠️ Could not process PR #${prNumber}: ${error.message}`);
}
}
- name: Delete consolidated branches
if: steps.check_consolidation.outputs.is_consolidation == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
// List of branches to delete (from consolidation)
const branchesToDelete = [
'refactor-cleanup',
'phase1-refactor-pyscript-deps',
'fix/eslint-errors',
'snyk-upgrade-element-plus-2.9.1',
'snyk-upgrade-element-plus-2.9.5',
'snyk-upgrade-element-plus-2.10.5'
];
for (const branch of branchesToDelete) {
try {
await github.rest.git.deleteRef({
owner,
repo,
ref: `heads/${branch}`
});
console.log(`✅ Deleted branch: ${branch}`);
} catch (error) {
console.log(`⚠️ Could not delete branch ${branch}: ${error.message}`);
}
}
- name: Create cleanup summary
if: steps.check_consolidation.outputs.is_consolidation == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
// Add comment to the merged PR summarizing cleanup
await github.rest.issues.createComment({
owner,
repo,
issue_number: context.issue.number,
body: `## 🧹 Post-Merge Cleanup Complete\n\n` +
`✅ Consolidated PRs have been closed\n` +
`✅ Obsolete branches have been deleted\n\n` +
`The repository is now clean and ready for future development.`
});