Skip to content

Commit 9d8e668

Browse files
authored
Merge branch 'opendatahub-io:main' into main
2 parents 329ce52 + fe65421 commit 9d8e668

36 files changed

Lines changed: 1084 additions & 176 deletions

.github/workflows/add-remove-labels.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ jobs:
1919
contains(github.event.comment.body, '/verified') ||
2020
contains(github.event.comment.body, '/lgtm') ||
2121
contains(github.event.comment.body, '/hold') ||
22-
contains(github.event.comment.body, '/cherry-pick')
22+
contains(github.event.comment.body, '/cherry-pick') ||
23+
contains(github.event.comment.body, '/build-push-pr-image')
2324
runs-on: ubuntu-latest
2425

2526
steps:
@@ -41,7 +42,7 @@ jobs:
4142

4243
- name: Run add remove labels
4344
env:
44-
GITHUB_TOKEN: ${{ secrets.OPENDATAHUB_TESTS_BOT_PAT }}
45+
GITHUB_TOKEN: ${{ secrets.RHODS_CI_BOT_PAT }}
4546
GITHUB_PR_NUMBER: "${{ github.event.pull_request.number || github.event.issue.number }}"
4647
GITHUB_EVENT_ACTION: ${{ github.event.action }}
4748
GITHUB_EVENT_REVIEW_STATE: ${{ github.event.review.state }}

.github/workflows/cherry-pick-comment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
- name: Checkout the latest code
1818
uses: actions/checkout@v4
1919
with:
20-
token: ${{ secrets.OPENDATAHUB_TESTS_BOT_PAT }}
20+
token: ${{ secrets.RHODS_CI_BOT_PAT }}
2121
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo
2222
- name: Automatic Cherry Pick
2323
uses: dbasunag/cherry-pick-pr@master
2424
env:
25-
GITHUB_TOKEN: ${{ secrets.OPENDATAHUB_TESTS_BOT_PAT }}
25+
GITHUB_TOKEN: ${{ secrets.RHODS_CI_BOT_PAT }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Delete PR Image On PR Close Action
2+
3+
on:
4+
pull_request_target:
5+
types: [closed]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: write
10+
issues: write
11+
12+
jobs:
13+
delete-quay-tag:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Install regctl
17+
run: |
18+
curl -LO https://github.com/regclient/regclient/releases/latest/download/regctl-linux-amd64
19+
chmod +x regctl-linux-amd64
20+
sudo mv regctl-linux-amd64 /usr/local/bin/regctl
21+
regctl version
22+
23+
- name: Configure regctl authentication
24+
run: |
25+
regctl registry login quay.io -u ${{ secrets.QUAY_USERNAME }} -p ${{ secrets.QUAY_PASSWORD }}
26+
echo "PR number: ${{ github.event.pull_request.number }}"
27+
echo "TAG_TO_DELETE=$(regctl tag ls quay.io/opendatahub/opendatahub-tests --include pr-${{ github.event.pull_request.number }})" >> $GITHUB_ENV
28+
- name: Delete Quay Tag
29+
if: env.TAG_TO_DELETE != ''
30+
run: |
31+
echo "Deleting tag '$TAG_TO_DELETE' from repository..."
32+
regctl tag rm quay.io/opendatahub/opendatahub-tests:pr-${{ github.event.pull_request.number }}

.github/workflows/on-review-add-label.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ jobs:
8383
uses: astral-sh/setup-uv@v6
8484
- name: 'Run add-remove-labels action'
8585
env:
86-
GITHUB_TOKEN: ${{ secrets.OPENDATAHUB_TESTS_BOT_PAT }}
86+
GITHUB_TOKEN: ${{ secrets.RHODS_CI_BOT_PAT }}
8787
GITHUB_EVENT_NAME: ${{ needs.download_context_artifact.outputs.event_name }}
8888
run: uv run python .github/workflows/scripts/pr_workflow.py
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Push Container Image On PR Comment
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: write
10+
issues: write
11+
12+
jobs:
13+
push-container-on-comment:
14+
if: contains(github.event.comment.body, '/build-push-pr-image')
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout pull request
18+
uses: actions/checkout@v4
19+
with:
20+
ref: refs/pull/${{ github.event.issue.number }}/head
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v6
23+
24+
- name: Check if the user is authorized
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.RHODS_CI_BOT_PAT }}
27+
GITHUB_PR_NUMBER: ${{ github.event.issue.number }}
28+
GITHUB_EVENT_ACTION: ${{ github.event.action }}
29+
GITHUB_EVENT_REVIEW_STATE: ${{ github.event.review.state }}
30+
GITHUB_EVENT_NAME: ${{ github.event_name }}
31+
COMMENT_BODY: ${{ github.event.comment.body }}
32+
REVIEW_COMMENT_BODY: ${{ github.event.review.body }}
33+
GITHUB_USER_LOGIN: ${{ github.event.sender.login }}
34+
ACTION: "push-container-on-comment"
35+
run: uv run python .github/workflows/scripts/pr_workflow.py
36+
- name: Set env TAG for image
37+
run: |
38+
echo "TAG=pr-${{ github.event.issue.number }}" >> "$GITHUB_ENV"
39+
- name: Build Image to push
40+
id: build-image
41+
uses: redhat-actions/buildah-build@v2
42+
with:
43+
image: opendatahub-tests
44+
tags: ${{ env.TAG }}
45+
containerfiles: |
46+
./Dockerfile
47+
- name: Push To Image Registry
48+
id: push-to-registry
49+
uses: redhat-actions/push-to-registry@v2
50+
with:
51+
image: ${{ steps.build-image.outputs.image }}
52+
tags: ${{ steps.build-image.outputs.tags }}
53+
registry: quay.io/opendatahub
54+
username: ${{ secrets.QUAY_USERNAME }}
55+
password: ${{ secrets.QUAY_PASSWORD }}
56+
57+
- name: Add comment to PR
58+
if: always()
59+
env:
60+
URL: ${{ github.event.issue.comments_url }}
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
run: |
63+
curl \
64+
-X POST \
65+
$URL \
66+
-H "Content-Type: application/json" \
67+
-H "Authorization: token $GITHUB_TOKEN" \
68+
--data '{ "body": "Status of building tag ${{ env.TAG }}: ${{ steps.build-image.outcome }}. \nStatus of pushing tag ${{ env.TAG }} to image registry: ${{ steps.push-to-registry.outcome }}." }'

.github/workflows/scripts/pr_workflow.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ class SupportedActions:
3434
add_remove_labels_action_name: str = "add-remove-labels"
3535
pr_size_action_name: str = "add-pr-size-label"
3636
welcome_comment_action_name: str = "add-welcome-comment-set-assignee"
37+
build_push_pr_image_action_name: str = "push-container-on-comment"
3738
supported_actions: set[str] = {
3839
pr_size_action_name,
3940
add_remove_labels_action_name,
4041
welcome_comment_action_name,
42+
build_push_pr_image_action_name,
4143
}
4244

4345
def __init__(self) -> None:
@@ -58,7 +60,7 @@ def __init__(self) -> None:
5860
def verify_base_config(self) -> None:
5961
if not self.action or self.action not in self.SupportedActions.supported_actions:
6062
sys.exit(
61-
"`ACTION` is not set in workflow or is not supported. "
63+
f"{self.action} is not set in workflow or is not supported. "
6264
f"Supported actions: {self.SupportedActions.supported_actions}"
6365
)
6466

@@ -97,10 +99,9 @@ def __init__(self) -> None:
9799
self.comment_body = os.getenv("REVIEW_COMMENT_BODY", "")
98100
self.last_commit = list(self.pr.get_commits())[-1]
99101
self.last_commit_sha = self.last_commit.sha
100-
101102
self.verify_labeler_config()
102103

103-
def verify_allowed_user(self) -> None:
104+
def verify_allowed_user(self) -> bool:
104105
org: Organization = self.gh_client.get_organization("opendatahub-io")
105106
# slug is the team name with replaced special characters,
106107
# all words to lowercase and spaces replace with a -
@@ -109,9 +110,10 @@ def verify_allowed_user(self) -> None:
109110
# check if the user is a member of opendatahub-tests-contributors
110111
membership = team.get_team_membership(member=self.user_login)
111112
LOGGER.info(f"User {self.user_login} is a member of the test contributor team. {membership}")
113+
return True
112114
except UnknownObjectException:
113115
LOGGER.error(f"User {self.user_login} is not allowed for this action. Exiting.")
114-
sys.exit(0)
116+
return False
115117

116118
def verify_labeler_config(self) -> None:
117119
if self.action == self.SupportedActions.add_remove_labels_action_name and self.event_name in (
@@ -131,9 +133,13 @@ def run_pr_label_action(self) -> None:
131133
if self.action == self.SupportedActions.pr_size_action_name:
132134
self.set_pr_size()
133135

136+
if self.action == self.SupportedActions.build_push_pr_image_action_name:
137+
if not self.verify_allowed_user():
138+
sys.exit(1)
139+
134140
if self.action == self.SupportedActions.add_remove_labels_action_name:
135-
self.verify_allowed_user()
136-
self.add_remove_pr_labels()
141+
if self.verify_allowed_user():
142+
self.add_remove_pr_labels()
137143

138144
if self.action == self.SupportedActions.welcome_comment_action_name:
139145
self.add_welcome_comment_set_assignee()

.github/workflows/workflow-review.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# https://stackoverflow.com/questions/67247752/how-to-use-secret-in-pull-request-review-similar-to-pull-request-target
12
name: Dummy Workflow on review
23

34
on:

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ repos:
3535
- id: detect-secrets
3636

3737
- repo: https://github.com/astral-sh/ruff-pre-commit
38-
rev: v0.11.8
38+
rev: v0.11.9
3939
hooks:
4040
- id: ruff
4141
- id: ruff-format

docs/GITHUB_WORKFLOWS.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
### On user action
1212
- Add to or remove a label from PR; supported labels: `wip`, `lgtm`, `verified`, and `hold`.
13-
To add a new label, add `/<label name>` in a comment.
14-
To remove a label, add `/<label name> cancel` in a comment.
13+
- To add a new label, add `/<label name>` in a comment.
14+
- To remove a label, add `/<label name> cancel` in a comment.
1515
`verified` and `lgtm` are removed on new commits.
16+
- To build and push image to quay, add `/build-push-pr-image` in a comment.
17+
This would create an image with tag pr-<pr_number> to quay repository. This image tag,
18+
however would be deleted on PR merge or close action.
1619

1720
## How to add a new workflow
1821
1. Create a new file in `.github/workflows` directory.
@@ -25,7 +28,6 @@
2528
## To be added
2629
- Block merging if not all defined checks pass. For example: a `verified` label was added and at least 2 approvals.
2730
- When a PR is opened, add reviewers (requires updates to OWNERS file(s))
28-
- When a PR is reviewed/commented by a user who's not the PR owner, add `reviewed|commented|approved-by-<username>` label
2931
- When a PR is ready to be merged (all checks passed), add `ready-to-merge` label
3032
- If a label is missing from the repository (i.e was manually deleted), add it back (label colors should be defined as well)
3133
- Tests

tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ocp_resources.pod import Pod
1515
from ocp_resources.secret import Secret
1616
from ocp_resources.service import Service
17+
from ocp_utilities.monitoring import Prometheus
1718
from pyhelper_utils.shell import run_command
1819
from pytest import FixtureRequest, Config
1920
from kubernetes.dynamic import DynamicClient
@@ -23,6 +24,7 @@
2324
from pytest_testconfig import config as py_config
2425
from simple_logger.logger import get_logger
2526

27+
from utilities.certificates_utils import create_ca_bundle_file
2628
from utilities.data_science_cluster_utils import update_components_in_dsc
2729
from utilities.exceptions import ClusterLoginError
2830
from utilities.infra import (
@@ -520,3 +522,15 @@ def cluster_sanity_scope_session(
520522
dsci_resource=dsci_resource,
521523
junitxml_property=junitxml_plugin,
522524
)
525+
526+
527+
@pytest.fixture(scope="session")
528+
def prometheus(admin_client: DynamicClient) -> Prometheus:
529+
return Prometheus(
530+
client=admin_client,
531+
resource_name="thanos-querier",
532+
verify_ssl=create_ca_bundle_file(
533+
client=admin_client, ca_type="openshift"
534+
), # TODO: Verify SSL with appropriate certs
535+
bearer_token=get_openshift_token(),
536+
)

0 commit comments

Comments
 (0)