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..7933a105790d --- /dev/null +++ b/.github/scripts/tests/therock_configure_ci_test.py @@ -0,0 +1,73 @@ +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_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_workflow_dispatch": True, + "input_projects": "" + } + + 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..98c381d79a20 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,28 @@ 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"): + 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"): + 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 +51,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..f7d305384d76 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: @@ -42,7 +42,6 @@ jobs: - name: "Checking out repository for rocm-libraries" uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: - ref: refs/pull/${{ github.event.pull_request.number }}/merge sparse-checkout: | .github ${{ inputs.subtree_checkout }} diff --git a/.github/workflows/therock-ci.yml b/.github/workflows/therock-ci.yml index 4d0ec60a9ffc..030740e68442 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 or 'all' to test all projects. ex: 'projects/rocprim projects/hipcub'" permissions: contents: read @@ -42,7 +50,6 @@ jobs: - name: Checkout code 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 }} @@ -86,6 +93,7 @@ jobs: id: projects env: SUBTREES: ${{ steps.detect.outputs.subtrees }} + PROJECTS: ${{ inputs.projects }} run: | python .github/scripts/therock_configure_ci.py