Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflows/pr-subscriber: Use our own custom concurrency implementation #66263

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/pr-subscriber-wait.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import github
import os
import sys
import time


def needs_to_wait(repo):
workflow_name = os.environ.get("GITHUB_WORKFLOW")
run_number = os.environ.get("GITHUB_RUN_NUMBER")
print("Workflow Name:", workflow_name, "Run Number:", run_number)
for status in ["in_progress", "queued"]:
for workflow in repo.get_workflow_runs(status=status):
print("Looking at ", workflow.name, "#", workflow.run_number)
if workflow.name != workflow_name:
continue
if workflow.run_number < int(run_number):
print("Workflow {} still {} ".format(workflow.run_number, status))
return True
return False


repo_name = os.environ.get("GITHUB_REPOSITORY")
token = os.environ.get("GITHUB_TOKEN")
gh = github.Github(token)
repo = gh.get_repo(repo_name)
while needs_to_wait(repo):
time.sleep(30)
33 changes: 18 additions & 15 deletions .github/workflows/pr-subscriber.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@ on:
- completed

permissions:
actions: read
contents: read

concurrency:
# Ideally, we would use the PR number in the concurrency group, but we don't
# have access to it here. We need to ensure only one job is running for
# each PR at a time, because there is a potential race condition when
# updating the issue comment.
group: "PR Subscriber"
cancel-in-progress: false

jobs:
auto-subscribe:
runs-on: ubuntu-latest
Expand All @@ -25,6 +18,23 @@ jobs:
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Setup Automation Script
run: |
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/github-automation.py
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/requirements.txt
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/.github/workflows/pr-subscriber-wait.py
chmod a+x github-automation.py
pip install -r requirements.txt

- name: 'Wait for other actions'
# We can't use the concurrency tag for these jobs, because it will
# cancel pending jobs if another job is running.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python3 pr-subscriber-wait.py


# From: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
# Updated version here: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
- name: 'Download artifact'
Expand All @@ -50,13 +60,6 @@ jobs:

- run: unzip pr.zip

- name: Setup Automation Script
run: |
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/github-automation.py
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/requirements.txt
chmod a+x github-automation.py
pip install -r requirements.txt

- name: Update watchers
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
run: |
Expand Down
12 changes: 9 additions & 3 deletions llvm/utils/git/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ certifi==2023.7.22
# -r requirements.txt.in
# requests
cffi==1.15.1
# via pynacl
# via
# cryptography
# pynacl
charset-normalizer==2.1.1
# via requests
cryptography==41.0.3
# via pyjwt
deprecated==1.2.13
# via pygithub
gitdb==4.0.9
Expand All @@ -22,16 +26,18 @@ idna==3.4
# via requests
pycparser==2.21
# via cffi
pygithub==1.55
pygithub==1.59.1
# via -r requirements.txt.in
pyjwt==2.5.0
pyjwt[crypto]==2.5.0
# via pygithub
pynacl==1.5.0
# via pygithub
requests==2.28.1
# via pygithub
smmap==5.0.0
# via gitdb
types-cryptography==3.3.23.2
# via pyjwt
urllib3==1.26.12
# via requests
wrapt==1.14.1
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/git/requirements.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# pip-compile -o requirements.txt requirements.txt.in

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