|
5 | 5 | # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Creative Commons Zero v1.0 Universal |
6 | 6 | # /___/ Please report bugs and contribute back your improvements |
7 | 7 | # |
8 | | -# Version: v3.1.0 |
| 8 | +# Version: v5.0.0 |
9 | 9 | ################################### |
10 | 10 | name: Cleanup |
11 | 11 |
|
| 12 | +#gt-placeholder-trigger-start |
12 | 13 | on: |
13 | 14 | push: |
14 | 15 | branches: |
15 | 16 | - main |
| 17 | +#gt-placeholder-trigger-end |
| 18 | + |
| 19 | +#gt-placeholder-permissions-start |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + pull-requests: write |
| 23 | +#gt-placeholder-permissions-end |
16 | 24 |
|
17 | 25 | jobs: |
18 | 26 | build: |
| 27 | + #gt-placeholder-runs-on-start |
19 | 28 | runs-on: ubuntu-latest |
| 29 | + #gt-placeholder-runs-on-end |
20 | 30 | steps: |
21 | | - - uses: actions/checkout@v4 |
| 31 | + #gt-placeholder-gh-action-checkout-start |
| 32 | + - uses: actions/checkout@v6 |
| 33 | + #gt-placeholder-gh-action-checkout-end |
| 34 | + |
| 35 | + #gt-placeholder-install-dependencies-start |
| 36 | + #gt-placeholder-install-dependencies-end |
| 37 | + |
22 | 38 | - name: Cleanup Sources |
23 | 39 | run: ./scripts/cleanup-on-push-to-main.sh |
| 40 | + |
| 41 | + - name: Check if actor is collaborator |
| 42 | + id: check-collaborator |
| 43 | + run: | |
| 44 | + user="${{ github.actor }}" |
| 45 | + repo="${{ github.repository }}" |
| 46 | + status=$(curl -L -s -o /dev/null -w '%{http_code}' \ |
| 47 | + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 48 | + -H "Accept: application/vnd.github+json" \ |
| 49 | + "https://api.github.com/repos/$repo/collaborators/$user" |
| 50 | + ) |
| 51 | + echo "status $status for user $user" |
| 52 | + if [ "$status" = "204" ]; then |
| 53 | + echo "reviewer=$user" >> $GITHUB_OUTPUT |
| 54 | + else |
| 55 | + echo "reviewer=" >> $GITHUB_OUTPUT |
| 56 | + fi |
| 57 | +
|
24 | 58 | - name: Create Pull Request if necessary |
| 59 | + id: create-pr |
| 60 | + #gt-placeholder-gh-action-create-pull-request-start |
25 | 61 | uses: peter-evans/create-pull-request@v7 |
| 62 | + #gt-placeholder-gh-action-create-pull-request-end |
26 | 63 | with: |
27 | 64 | branch: auto-cleanup |
28 | 65 | title: Auto Cleanup |
|
31 | 68 | delete-branch: true |
32 | 69 | token: ${{ secrets.AUTO_PR_TOKEN }} |
33 | 70 | push-to-fork: ${{ vars.AUTO_PR_FORK_NAME != '' && vars.AUTO_PR_FORK_NAME || secrets.AUTO_PR_FORK_NAME }} |
| 71 | + |
| 72 | + |
| 73 | + - name: set reviewer |
| 74 | + if: ${{ steps.check-collaborator.outputs.reviewer != '' && steps.check-collaborator.outputs.reviewer != null && steps.create-pr.outputs.pull-request-operation == 'created' }} |
| 75 | + run: | |
| 76 | + repo="${{ github.repository }}" |
| 77 | + status=$(curl -L -s -o /dev/null -w '%{http_code}' \ |
| 78 | + -X POST \ |
| 79 | + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 80 | + -H "Accept: application/vnd.github+json" \ |
| 81 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 82 | + https://api.github.com/repos/$repo/pulls/${{steps.create-pr.outputs.pull-request-number}}/requested_reviewers \ |
| 83 | + -d '{"reviewers":["${{ steps.check-collaborator.outputs.reviewer }}"]}' |
| 84 | + ) |
| 85 | + echo "status $status" |
| 86 | + [ "$status" = "201" ] |
0 commit comments