-
Notifications
You must be signed in to change notification settings - Fork 1
98 lines (90 loc) · 3.83 KB
/
cleanup.yml
File metadata and controls
98 lines (90 loc) · 3.83 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
#
# __ __
# / /____ ___ ____ ___ ___ _/ / This file is provided to you by https://github.com/tegonal/github-commons
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <info@tegonal.com>
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Creative Commons Zero v1.0 Universal
# /___/ Please report bugs and contribute back your improvements
#
# Version: v5.1.0-SNAPSHOT
###################################
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# DO NOT MODIFY HERE BUT IN src/.github/workflows/cleanup.yml
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
name: Cleanup
#gt-placeholder-trigger-start
on:
push:
branches:
- main
#gt-placeholder-trigger-end
#gt-placeholder-permissions.v2-start
permissions:
contents: read
pull-requests: write
#gt-placeholder-permissions.v2-end
jobs:
build:
#gt-placeholder-runs-on-start
runs-on: ubuntu-latest
#gt-placeholder-runs-on-end
steps:
#gt-placeholder-gh-action-checkout-start
- uses: actions/checkout@v6
#gt-placeholder-gh-action-checkout-end
#gt-placeholder-install-dependencies-start
- name: install shfmt
run: ./lib/tegonal-scripts/src/ci/install-shfmt.sh
#gt-placeholder-install-dependencies-end
- name: Cleanup Sources
run: ./scripts/cleanup-on-push-to-main.sh
#gt-placeholder-additional-steps-start
#gt-placeholder-additional-steps-end
- name: Check if actor is collaborator
id: check-collaborator
run: |
user="${{ github.actor }}"
repo="${{ github.repository }}"
status=$(curl -L -s -o /dev/null -w '%{http_code}' \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$repo/collaborators/$user"
)
echo "status $status for user $user"
if [ "$status" = "204" ]; then
echo "reviewer=$user" >> $GITHUB_OUTPUT
else
echo "reviewer=" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request if necessary
id: create-pr
#gt-placeholder-gh-action-create-pull-request-start
uses: peter-evans/create-pull-request@v8
#gt-placeholder-gh-action-create-pull-request-end
with:
#gt-placeholder-branch-start
branch: auto-cleanup
#gt-placeholder-branch-end
#gt-placeholder-title-and-co-start
title: Auto Cleanup
commit-message: auto cleanup sources
body: Looks like someone forgot to run ./scripts/cleanup-on-push-to-main.sh before committing. I did it for them :)
#gt-placeholder-title-and-co-end
delete-branch: true
#gt-placeholder-token-and-co-start
token: ${{ secrets.AUTO_PR_TOKEN }}
push-to-fork: ${{ vars.AUTO_PR_FORK_NAME != '' && vars.AUTO_PR_FORK_NAME || secrets.AUTO_PR_FORK_NAME }}
#gt-placeholder-token-and-co-end
- name: set reviewer
if: ${{ steps.check-collaborator.outputs.reviewer != '' && steps.check-collaborator.outputs.reviewer != null && steps.create-pr.outputs.pull-request-operation == 'created' }}
run: |
repo="${{ github.repository }}"
status=$(curl -L -s -o /dev/null -w '%{http_code}' \
-X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$repo/pulls/${{steps.create-pr.outputs.pull-request-number}}/requested_reviewers \
-d '{"reviewers":["${{ steps.check-collaborator.outputs.reviewer }}"]}'
)
echo "status $status"
[ "$status" = "201" ]