Skip to content
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
73 changes: 73 additions & 0 deletions .github/scripts/tests/therock_configure_ci_test.py
Original file line number Diff line number Diff line change
@@ -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()
41 changes: 34 additions & 7 deletions .github/scripts/therock_configure_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -24,25 +22,54 @@ 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 = []
for project in projects:
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)
3 changes: 1 addition & 2 deletions .github/workflows/therock-ci-linux.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: TheRock CI
name: TheRock CI Linux

on:
workflow_call:
Expand Down Expand Up @@ -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 }}
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/therock-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: TheRock CI

on:
push:
branches:
- develop
pull_request:
types:
- opened
Expand All @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -86,6 +93,7 @@ jobs:
id: projects
env:
SUBTREES: ${{ steps.detect.outputs.subtrees }}
PROJECTS: ${{ inputs.projects }}
run: |
python .github/scripts/therock_configure_ci.py

Expand Down