forked from OISF/suricata
-
Notifications
You must be signed in to change notification settings - Fork 2
80 lines (66 loc) · 2.39 KB
/
Copy pathclose-updated-prs.yml
File metadata and controls
80 lines (66 loc) · 2.39 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
name: Close updated PRs
on:
pull_request_target:
types:
- synchronize
permissions:
actions: write
contents: read
issues: write
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
close-updated-pr:
name: Close updated PR
if: ${{ github.event.pull_request.draft == false }}
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
AFTER: ${{ github.event.after }}
steps:
- name: Close updated PR
run: |
set -euo pipefail
body=$(cat <<'EOF'
Closing this pull request: its branch was updated after the pull
request was opened.
Per our workflow, a new pull request is required when changes are made
to an existing one. Please open a new pull request with the updated
changes.
If you wish to create an in progress pull request that you can push to,
please create a draft pull request.
Please see [GitHub Pull Request Workflow](https://docs.suricata.io/en/latest/devguide/contributing/github-pr-workflow.html).
EOF
)
gh api \
--method POST \
"/repos/${REPOSITORY}/issues/${PR_NUMBER}/comments" \
-f body="${body}" \
--silent
gh api \
--method PATCH \
"/repos/${REPOSITORY}/pulls/${PR_NUMBER}" \
-f state=closed \
--silent
# Run last, after the PR has been closed. Our own run is skipped so this
# job does not show up as cancelled in the checks list.
- name: Cancel running workflows for this push
run: |
set -euo pipefail
for status in queued in_progress; do
gh api --paginate \
"/repos/${REPOSITORY}/actions/runs?head_sha=${AFTER}&status=${status}" \
--jq '.workflow_runs[].id' | while read -r run_id; do
if [ "${run_id}" = "${GITHUB_RUN_ID}" ]; then
continue
fi
gh api \
--method POST \
"/repos/${REPOSITORY}/actions/runs/${run_id}/cancel" \
--silent || true
done
done