Skip to content

Commit 76696ce

Browse files
tstellarkstoimenov
authored andcommitted
workflows/pr-subscriber: Use our own custom concurrency implementation (llvm#66263)
The builtin concurrency functionality for the workflows will cancel a pending job if there is another job from the same workflow running. For the pr-subscriber job, this means that if multiple labels are added at the same time, then some of the pr-subscriber jobs will be cancelled and the PR will not have all the necessary mentions.
1 parent 59b5ae8 commit 76696ce

File tree

4 files changed

+55
-19
lines changed

4 files changed

+55
-19
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import github
2+
import os
3+
import sys
4+
import time
5+
6+
7+
def needs_to_wait(repo):
8+
workflow_name = os.environ.get("GITHUB_WORKFLOW")
9+
run_number = os.environ.get("GITHUB_RUN_NUMBER")
10+
print("Workflow Name:", workflow_name, "Run Number:", run_number)
11+
for status in ["in_progress", "queued"]:
12+
for workflow in repo.get_workflow_runs(status=status):
13+
print("Looking at ", workflow.name, "#", workflow.run_number)
14+
if workflow.name != workflow_name:
15+
continue
16+
if workflow.run_number < int(run_number):
17+
print("Workflow {} still {} ".format(workflow.run_number, status))
18+
return True
19+
return False
20+
21+
22+
repo_name = os.environ.get("GITHUB_REPOSITORY")
23+
token = os.environ.get("GITHUB_TOKEN")
24+
gh = github.Github(token)
25+
repo = gh.get_repo(repo_name)
26+
while needs_to_wait(repo):
27+
time.sleep(30)

.github/workflows/pr-subscriber.yml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@ on:
77
- completed
88

99
permissions:
10+
actions: read
1011
contents: read
1112

12-
concurrency:
13-
# Ideally, we would use the PR number in the concurrency group, but we don't
14-
# have access to it here. We need to ensure only one job is running for
15-
# each PR at a time, because there is a potential race condition when
16-
# updating the issue comment.
17-
group: "PR Subscriber"
18-
cancel-in-progress: false
19-
2013
jobs:
2114
auto-subscribe:
2215
runs-on: ubuntu-latest
@@ -25,6 +18,23 @@ jobs:
2518
github.event.workflow_run.event == 'pull_request' &&
2619
github.event.workflow_run.conclusion == 'success'
2720
steps:
21+
- name: Setup Automation Script
22+
run: |
23+
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/github-automation.py
24+
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/requirements.txt
25+
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/.github/workflows/pr-subscriber-wait.py
26+
chmod a+x github-automation.py
27+
pip install -r requirements.txt
28+
29+
- name: 'Wait for other actions'
30+
# We can't use the concurrency tag for these jobs, because it will
31+
# cancel pending jobs if another job is running.
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
run: |
35+
python3 pr-subscriber-wait.py
36+
37+
2838
# From: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
2939
# Updated version here: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
3040
- name: 'Download artifact'
@@ -50,13 +60,6 @@ jobs:
5060
5161
- run: unzip pr.zip
5262

53-
- name: Setup Automation Script
54-
run: |
55-
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/github-automation.py
56-
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/requirements.txt
57-
chmod a+x github-automation.py
58-
pip install -r requirements.txt
59-
6063
- name: Update watchers
6164
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
6265
run: |

llvm/utils/git/requirements.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ certifi==2023.7.22
99
# -r requirements.txt.in
1010
# requests
1111
cffi==1.15.1
12-
# via pynacl
12+
# via
13+
# cryptography
14+
# pynacl
1315
charset-normalizer==2.1.1
1416
# via requests
17+
cryptography==41.0.3
18+
# via pyjwt
1519
deprecated==1.2.13
1620
# via pygithub
1721
gitdb==4.0.9
@@ -22,16 +26,18 @@ idna==3.4
2226
# via requests
2327
pycparser==2.21
2428
# via cffi
25-
pygithub==1.55
29+
pygithub==1.59.1
2630
# via -r requirements.txt.in
27-
pyjwt==2.5.0
31+
pyjwt[crypto]==2.5.0
2832
# via pygithub
2933
pynacl==1.5.0
3034
# via pygithub
3135
requests==2.28.1
3236
# via pygithub
3337
smmap==5.0.0
3438
# via gitdb
39+
types-cryptography==3.3.23.2
40+
# via pyjwt
3541
urllib3==1.26.12
3642
# via requests
3743
wrapt==1.14.1

llvm/utils/git/requirements.txt.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
# pip-compile -o requirements.txt requirements.txt.in
55

66
certifi>=2023.7.22 # https://security.snyk.io/vuln/SNYK-PYTHON-CERTIFI-5805047
7-
PyGithub
7+
PyGithub==1.59.1 # For WorkflowRun.name
88
GitPython>=3.1.32 # https://security.snyk.io/vuln/SNYK-PYTHON-GITPYTHON-5840584

0 commit comments

Comments
 (0)