-
Notifications
You must be signed in to change notification settings - Fork 3
73 lines (58 loc) · 2.33 KB
/
repository-cleanup.yml
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
# **what?**
# Repository cleanup.
# Cleans up both branches and draft releases left over from test and pre release automations.
#
# **why?**
# Our automated processes leave behind branches and draft releases that are cluttering up the repo.
# **when?**
# As scheduled by calling workflow_call.
name: Repository Cleanup
on: workflow_call
permissions:
contents: write
jobs:
delete-branches:
name: "Delete ${{ matrix.branch }} Branches"
runs-on: ubuntu-latest
strategy:
matrix:
branch: ["cutting_release_branch/*", "prep-release/*"]
steps:
- name: "Check out ${{ github.repository }}"
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
fetch-depth: 0
- name: "List Branch to be Deleted for: ${{ matrix.branch }}"
run: |
git branch -a --list "origin/${{ matrix.branch }}" | sed 's|.*remotes/origin/||'
- name: "Delete Prerelease Branches: ${{ matrix.branch }}"
run: |
for b in $(git branch -a --list "origin/${{ matrix.branch }}" | sed 's|.*remotes/origin/||'); do
git push origin --delete $b
done
- name: "[Expect None] List Branch matching: ${{ matrix.branch }}"
run: |
git branch -a --list "origin/${{ matrix.branch }}" | sed 's|.*remotes/origin/||'
delete-draft-releases:
name: "Delete Draft Releases in ${{ github.repository }}"
runs-on: ubuntu-latest
steps:
- name: "List Draft Releases"
run: |
gh release --repo ${{ github.repository }} list --limit 100 | awk -F '\t' '$2 == "Draft" {print $3}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Delete Draft Releases in ${{ github.repository }}"
run: |
for release in $(gh release --repo ${{ github.repository }} list --limit 100 | awk -F '\t' '$2 == "Draft" {print $3}'); do
echo "Deleting Draft Release: $release"
gh release --repo ${{ github.repository }} delete --yes $release
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "[Expect None] List Draft Releases"
run: |
gh release --repo ${{ github.repository }} list --limit 100 | awk -F '\t' '$2 == "Draft" {print $3}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}