Skip to content

Commit ce4a1c9

Browse files
committed
Linked issue workflow gatekeeper
Signed-off-by: Alyssa Goins <agoins@redhat.com>
1 parent 44e26cb commit ce4a1c9

43 files changed

Lines changed: 421 additions & 46 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import re
4+
import sys
5+
6+
from github import Auth, Github
7+
8+
# removes hidden section of PR body.
9+
def clean_pr_body(body: str) -> str:
10+
if not body:
11+
return ""
12+
clean_text = re.sub(r'<!--.*?-->', '', body, flags=re.DOTALL)
13+
return clean_text.strip()
14+
15+
16+
def main() -> int:
17+
# Retrieve env vars provided by GH Action workflow
18+
token = os.getenv("GITHUB_TOKEN")
19+
pr_num = int(os.getenv("PR_NUMBER"))
20+
#todo: this var necessary for testing purposes and can utlimately be removed.
21+
repo_name = os.getenv("GITHUB_REPOSITORY")
22+
print(f"Verifying linked issues for PR #{pr_num} in {repo_name}")
23+
24+
g = Github(auth=Auth.Token(token))
25+
repo = g.get_repo(repo_name)
26+
pr = repo.get_pull(pr_num)
27+
28+
# 1. Parse PR body for linked issues (e.g., #123 or Fixes #123)
29+
pr_body_original = pr.body or ""
30+
pr_body = clean_pr_body(pr_body_original)
31+
32+
issue_numbers = re.findall(r"(?:#|issues\/)(\d+)", pr_body)
33+
print(f"Found issue numbers: {issue_numbers}")
34+
35+
if not issue_numbers:
36+
print('ERROR: No linked issues found in the PR description.')
37+
return 1
38+
39+
#2: Check each linked issue for the "ready" command.
40+
# If there is more than one issue linked, each issue must be marked /ready
41+
found_ready = False
42+
for issue_num in issue_numbers:
43+
issue = repo.get_issue(int(issue_num))
44+
comments = issue.get_comments()
45+
46+
# Check if the issue contains a comment with /ready command
47+
for comment in comments:
48+
if "/ready" in comment.body:
49+
print(f"Found '/ready' command in issue #{issue_num}")
50+
found_ready = True
51+
break
52+
#todo: is there ever a case in which "/ready" is canceled out by a later comment? (ie do not exit here)
53+
if found_ready: break
54+
55+
if not found_ready:
56+
print("ERROR: The linked issue(s) must have a '/ready' command.")
57+
return 1
58+
59+
print(f'Successfully verified linked issues: {issue_numbers}')
60+
return 0
61+
62+
if __name__ == "__main__":
63+
sys.exit(main())

.github/workflows/add-ci-passed-label.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- labeled
1212
- unlabeled
1313
workflow_run:
14-
workflows: ["CI Check"]
14+
workflows: [ "CI Check" ]
1515
types:
1616
- completed
1717

@@ -20,8 +20,12 @@ permissions:
2020
issues: write
2121

2222
jobs:
23+
gatekeeper:
24+
uses: ./.github/workflows/wait-for-gatekeeper.yml
25+
2326
fetch_data:
2427
name: Fetch PR eligibility
28+
needs: gatekeeper
2529
runs-on: ubuntu-latest
2630
outputs:
2731
pr_number: ${{ steps.pr.outputs.pr_number }}
@@ -87,6 +91,7 @@ jobs:
8791
8892
reset_ci_passed_label:
8993
name: Reset stale 'ci-passed' label
94+
needs: gatekeeper
9095
runs-on: ubuntu-latest
9196
steps:
9297
- name: Remove existing 'ci-passed' label
@@ -125,7 +130,7 @@ jobs:
125130
add_ci_passed_label:
126131
name: Add 'ci-passed' label
127132
runs-on: ubuntu-latest
128-
needs: fetch_data
133+
needs: [fetch_data,gatekeeper]
129134
steps:
130135
- name: Add 'ci-passed' label
131136
shell: bash

.github/workflows/api-server-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ concurrency:
5959
cancel-in-progress: true
6060

6161
jobs:
62+
gatekeeper:
63+
uses: ./.github/workflows/wait-for-gatekeeper.yml
64+
6265
build:
66+
needs: gatekeeper
6367
uses: ./.github/workflows/image-builds.yml
6468

6569
api-test-standalone:

.github/workflows/backend-visualization.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ on:
1717
- '!**/OWNERS'
1818

1919
jobs:
20+
gatekeeper:
21+
uses: ./.github/workflows/wait-for-gatekeeper.yml
22+
2023
backend-visualization-test:
24+
needs: gatekeeper
2125
runs-on: ubuntu-latest
2226
steps:
2327
- name: Checkout code

.github/workflows/build-master.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- main
77
- stable
88
- 'rhoai-*'
9+
910
concurrency:
1011
group: ${{ github.workflow }}
1112
cancel-in-progress: true

.github/workflows/build-prs-trigger.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ concurrency:
1515
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1616
cancel-in-progress: true
1717
jobs:
18+
gatekeeper:
19+
uses: ./.github/workflows/wait-for-gatekeeper.yml
20+
1821
upload-data:
22+
needs: gatekeeper
1923
runs-on: ubuntu-latest
2024
steps:
2125
- uses: actions/checkout@v2

.github/workflows/build-prs.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Build images for PRs
22
on:
33
workflow_run:
4-
workflows: ["Trigger PR CI"]
4+
workflows: [ "Trigger PR CI" ]
55
types:
66
- completed
77
env:
@@ -11,7 +11,11 @@ env:
1111
GH_USER_EMAIL: 140449482+dsp-developers@users.noreply.github.com
1212
GH_USER_NAME: dsp-developers
1313
jobs:
14+
gatekeeper:
15+
uses: ./.github/workflows/wait-for-gatekeeper.yml
16+
1417
fetch-data:
18+
needs: gatekeeper
1519
name: Fetch workflow payload
1620
runs-on: ubuntu-latest
1721
if: >

.github/workflows/build-tools-images.yml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
name: Build tools images
22

33
# This workflow is disabled for downstream.
4-
on: []
5-
# push:
6-
# branches:
7-
# - master
8-
# - main
9-
# - stable
10-
# - 'release-*'
11-
# - 'rhoai-*'
12-
# pull_request:
13-
# branches:
14-
# - master
15-
# - 'release-*'
16-
# workflow_dispatch: {}
4+
on:
5+
push:
6+
branches:
7+
- master
8+
- main
9+
- stable
10+
- 'release-*'
11+
- 'rhoai-*'
12+
pull_request:
13+
branches:
14+
- master
15+
- 'release-*'
16+
workflow_dispatch:
1717

1818
permissions:
1919
contents: read
@@ -29,7 +29,11 @@ concurrency:
2929
cancel-in-progress: false
3030

3131
jobs:
32+
gatekeeper:
33+
uses: ./.github/workflows/wait-for-gatekeeper.yml
34+
3235
build-tools:
36+
needs: gatekeeper
3337
name: Build tools images
3438
runs-on: ubuntu-latest
3539
steps:

.github/workflows/cancel.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Cancel
2+
on: []
3+
# workflow_run:
4+
# id: gatekeeper
5+
# workflows: [ "Gatekeeper" ]
6+
# types:
7+
# - completed
8+
9+
jobs:
10+
cancel:
11+
name: 'Cancel Previous Runs'
12+
if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion != 'success' }}
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 3
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
sparse-checkout: .github/workflows
19+
sparse-checkout-cone-mode: false
20+
21+
- name: Build workflow list
22+
id: workflows
23+
run: |
24+
ids=$(ls .github/workflows/ \
25+
| grep -v -e '^cancel\.yml$' -e '^gatekeeper\.yml$' \
26+
| paste -sd ',' -)
27+
echo "ids=$ids" >> "$GITHUB_OUTPUT"
28+
29+
- uses: styfle/cancel-workflow-action
30+
with:
31+
workflow_id: ${{ steps.workflows.outputs.ids }}

.github/workflows/ci-checks.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ name: CI Check
44
on:
55
pull_request_target:
66
types: [opened, synchronize, reopened, labeled, unlabeled]
7-
workflow_run:
8-
workflows: [ "Stable Merge Integration Test Check" ] # Triggers when "Stable Merge Integration Test Check" succeeds
9-
types: [completed]
10-
branches: [stable]
117

128
jobs:
9+
gatekeeper:
10+
uses: ./.github/workflows/wait-for-gatekeeper.yml
11+
1312
check_ci_status:
13+
needs: gatekeeper
1414
runs-on: ubuntu-latest
1515
permissions:
1616
checks: read

0 commit comments

Comments
 (0)