From 3409a0caaf9b957af7679c74460d3040863cda44 Mon Sep 17 00:00:00 2001 From: geomin12 Date: Wed, 25 Jun 2025 11:22:45 -0700 Subject: [PATCH 1/4] Adding continous CI --- .../tests/therock_configure_ci_test.py | 64 +++++++++++++++++++ .github/scripts/therock_configure_ci.py | 38 +++++++++-- .github/workflows/therock-ci-linux.yml | 10 +++ .github/workflows/therock-ci.yml | 10 +++ 4 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 .github/scripts/tests/therock_configure_ci_test.py diff --git a/.github/scripts/tests/therock_configure_ci_test.py b/.github/scripts/tests/therock_configure_ci_test.py new file mode 100644 index 000000000000..d5ec11a679ed --- /dev/null +++ b/.github/scripts/tests/therock_configure_ci_test.py @@ -0,0 +1,64 @@ +from pathlib import Path +import os +import sys +import unittest + +sys.path.insert(0, os.fspath(Path(__file__).parent.parent)) +import therock_configure_ci + +class ConfigureCITest(unittest.TestCase): + def test_pull_request(self): + args = { + "is_pull_request": True, + "input_subtrees": "projects/rocprim\nprojects/hipcub" + } + + project_to_run = therock_configure_ci.retrieve_projects(args) + self.assertEqual(len(project_to_run), 1) + + def test_pull_request_empty(self): + args = { + "is_pull_request": True, + "input_subtrees": "" + } + + project_to_run = therock_configure_ci.retrieve_projects(args) + self.assertEqual(len(project_to_run), 0) + + def test_workflow_dispatch(self): + args = { + "is_workflow_dispatch": True, + "input_projects": "projects/rocprim projects/hipcub" + } + + project_to_run = therock_configure_ci.retrieve_projects(args) + self.assertEqual(len(project_to_run), 1) + + def test_workflow_dispatch_bad_input(self): + args = { + "is_workflow_dispatch": True, + "input_projects": "projects/rocprim$$projects/hipcub" + } + + project_to_run = therock_configure_ci.retrieve_projects(args) + self.assertEqual(len(project_to_run), 0) + + def test_workflow_dispatch_empty(self): + args = { + "is_pull_request": True, + "input_subtrees": "" + } + + project_to_run = therock_configure_ci.retrieve_projects(args) + self.assertEqual(len(project_to_run), 0) + + def test_is_push(self): + args = { + "is_push": True, + } + + project_to_run = therock_configure_ci.retrieve_projects(args) + self.assertGreaterEqual(len(project_to_run), 1) + +if __name__ == "__main__": + unittest.main() diff --git a/.github/scripts/therock_configure_ci.py b/.github/scripts/therock_configure_ci.py index 9c3240eed8d1..10128e60824f 100644 --- a/.github/scripts/therock_configure_ci.py +++ b/.github/scripts/therock_configure_ci.py @@ -10,8 +10,6 @@ from typing import Mapping import os -SUBTREES = os.getenv("SUBTREES", "") - def set_github_output(d: Mapping[str, str]): """Sets GITHUB_OUTPUT values. @@ -24,15 +22,25 @@ def set_github_output(d: Mapping[str, str]): return with open(step_output_file, "a") as f: f.writelines(f"{k}={v}" + "\n" for k, v in d.items()) - - -def run(): - subtrees = SUBTREES.split("\n") + + +def retrieve_projects(args): + if args.get("is_pull_request"): + subtrees = args.get("input_subtrees").split("\n") + + if args.get("is_workflow_dispatch"): + subtrees = args.get("input_projects").split() + + # If a push event to develop happens, we run tests on all subtrees + if args.get("is_push"): + subtrees = list(subtree_to_project_map.keys()) + projects = set() # collect the associated subtree to project for subtree in subtrees: if subtree in subtree_to_project_map: projects.add(subtree_to_project_map.get(subtree)) + # retrieve the subtrees to checkout, cmake options to build, and projects to test project_to_run = [] @@ -40,9 +48,25 @@ def run(): if project in project_map: project_to_run.append(project_map.get(project)) + return project_to_run + +def run(args): + project_to_run = retrieve_projects(args) set_github_output({"projects": json.dumps(project_to_run)}) if __name__ == "__main__": - run() + github_event_name = os.getenv("GITHUB_EVENT_NAME") + args = {} + args["is_pull_request"] = github_event_name == "pull_request" + args["is_push"] = github_event_name == "push" + args["is_workflow_dispatch"] = github_event_name == "workflow_dispatch" + + input_subtrees = os.getenv("SUBTREES", "") + args["input_subtrees"] = input_subtrees + + input_projects = os.getenv("PROJECTS", "") + args["input_projects"] = input_projects + + run(args) diff --git a/.github/workflows/therock-ci-linux.yml b/.github/workflows/therock-ci-linux.yml index 570ada61b921..11385c72dbec 100644 --- a/.github/workflows/therock-ci-linux.yml +++ b/.github/workflows/therock-ci-linux.yml @@ -40,6 +40,16 @@ jobs: owner: ${{ github.repository_owner }} - name: "Checking out repository for rocm-libraries" + if: github.event_name != 'pull_request' + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + sparse-checkout: | + .github + ${{ inputs.subtree_checkout }} + token: ${{ steps.generate-token.outputs.token }} + + - name: "Checking out repository for rocm-libraries" + if: github.event_name == 'pull_request' uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: ref: refs/pull/${{ github.event.pull_request.number }}/merge diff --git a/.github/workflows/therock-ci.yml b/.github/workflows/therock-ci.yml index 4d0ec60a9ffc..9bd37a8624c9 100644 --- a/.github/workflows/therock-ci.yml +++ b/.github/workflows/therock-ci.yml @@ -1,6 +1,9 @@ name: TheRock CI on: + push: + branches: + - develop pull_request: types: - opened @@ -10,6 +13,11 @@ on: paths-ignore: - "docs/**" - "*.md" + workflow_dispatch: + inputs: + projects: + type: string + description: "Insert space-separated list of projects to test. ex: 'projects/rocprim projects/hipcub'" permissions: contents: read @@ -40,6 +48,7 @@ jobs: owner: ${{ github.repository_owner }} - name: Checkout code + if: github.event_name == 'pull_request' uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: ref: refs/pull/${{ github.event.pull_request.number }}/merge @@ -86,6 +95,7 @@ jobs: id: projects env: SUBTREES: ${{ steps.detect.outputs.subtrees }} + PROJECTS: ${{ inputs.projects }} run: | python .github/scripts/therock_configure_ci.py From 97644a34f8a6e448270a3b0db5da4021279579d8 Mon Sep 17 00:00:00 2001 From: geomin12 Date: Wed, 25 Jun 2025 11:24:12 -0700 Subject: [PATCH 2/4] Adding Linux to job name --- .github/workflows/therock-ci-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/therock-ci-linux.yml b/.github/workflows/therock-ci-linux.yml index 11385c72dbec..f40bae04689d 100644 --- a/.github/workflows/therock-ci-linux.yml +++ b/.github/workflows/therock-ci-linux.yml @@ -1,4 +1,4 @@ -name: TheRock CI +name: TheRock CI Linux on: workflow_call: From 56051efb4f184d6dfce070828360f4198d48caea Mon Sep 17 00:00:00 2001 From: geomin12 Date: Wed, 25 Jun 2025 14:05:07 -0700 Subject: [PATCH 3/4] PR comments --- .github/scripts/tests/therock_configure_ci_test.py | 13 +++++++++++-- .github/scripts/therock_configure_ci.py | 5 ++++- .github/workflows/therock-ci.yml | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/scripts/tests/therock_configure_ci_test.py b/.github/scripts/tests/therock_configure_ci_test.py index d5ec11a679ed..7933a105790d 100644 --- a/.github/scripts/tests/therock_configure_ci_test.py +++ b/.github/scripts/tests/therock_configure_ci_test.py @@ -43,10 +43,19 @@ def test_workflow_dispatch_bad_input(self): project_to_run = therock_configure_ci.retrieve_projects(args) self.assertEqual(len(project_to_run), 0) + def test_workflow_dispatch_all(self): + args = { + "is_workflow_dispatch": True, + "input_projects": "all" + } + + project_to_run = therock_configure_ci.retrieve_projects(args) + self.assertGreaterEqual(len(project_to_run), 1) + def test_workflow_dispatch_empty(self): args = { - "is_pull_request": True, - "input_subtrees": "" + "is_workflow_dispatch": True, + "input_projects": "" } project_to_run = therock_configure_ci.retrieve_projects(args) diff --git a/.github/scripts/therock_configure_ci.py b/.github/scripts/therock_configure_ci.py index 10128e60824f..98c381d79a20 100644 --- a/.github/scripts/therock_configure_ci.py +++ b/.github/scripts/therock_configure_ci.py @@ -29,7 +29,10 @@ def retrieve_projects(args): subtrees = args.get("input_subtrees").split("\n") if args.get("is_workflow_dispatch"): - subtrees = args.get("input_projects").split() + if args.get("input_projects") == "all": + subtrees = list(subtree_to_project_map.keys()) + else: + subtrees = args.get("input_projects").split() # If a push event to develop happens, we run tests on all subtrees if args.get("is_push"): diff --git a/.github/workflows/therock-ci.yml b/.github/workflows/therock-ci.yml index 9bd37a8624c9..cb6514cb5047 100644 --- a/.github/workflows/therock-ci.yml +++ b/.github/workflows/therock-ci.yml @@ -17,7 +17,7 @@ on: inputs: projects: type: string - description: "Insert space-separated list of projects to test. ex: 'projects/rocprim projects/hipcub'" + description: "Insert space-separated list of projects to test or 'all' to test all projects. ex: 'projects/rocprim projects/hipcub'" permissions: contents: read From e61ff8102d378e1097b88d5083c47ba41104ec85 Mon Sep 17 00:00:00 2001 From: geomin12 Date: Wed, 25 Jun 2025 14:52:34 -0700 Subject: [PATCH 4/4] Adding fix for checkout --- .github/workflows/therock-ci-linux.yml | 11 ----------- .github/workflows/therock-ci.yml | 2 -- 2 files changed, 13 deletions(-) diff --git a/.github/workflows/therock-ci-linux.yml b/.github/workflows/therock-ci-linux.yml index f40bae04689d..f7d305384d76 100644 --- a/.github/workflows/therock-ci-linux.yml +++ b/.github/workflows/therock-ci-linux.yml @@ -40,23 +40,12 @@ jobs: owner: ${{ github.repository_owner }} - name: "Checking out repository for rocm-libraries" - if: github.event_name != 'pull_request' uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: sparse-checkout: | .github ${{ inputs.subtree_checkout }} token: ${{ steps.generate-token.outputs.token }} - - - name: "Checking out repository for rocm-libraries" - if: github.event_name == 'pull_request' - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - ref: refs/pull/${{ github.event.pull_request.number }}/merge - sparse-checkout: | - .github - ${{ inputs.subtree_checkout }} - token: ${{ steps.generate-token.outputs.token }} - name: Checkout TheRock repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 diff --git a/.github/workflows/therock-ci.yml b/.github/workflows/therock-ci.yml index cb6514cb5047..030740e68442 100644 --- a/.github/workflows/therock-ci.yml +++ b/.github/workflows/therock-ci.yml @@ -48,10 +48,8 @@ jobs: owner: ${{ github.repository_owner }} - name: Checkout code - if: github.event_name == 'pull_request' uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: - ref: refs/pull/${{ github.event.pull_request.number }}/merge sparse-checkout: .github sparse-checkout-cone-mode: true token: ${{ steps.generate-token.outputs.token }}