Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci-matrix: add partition-tests-inpackage #277

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dnephin
Copy link
Member

@dnephin dnephin commented Sep 5, 2022

TODO: finish the test case for the new flag

@dnephin dnephin mentioned this pull request Sep 5, 2022
@AaronFriel
Copy link

@dnephin Could you push this to a branch and tag it? I would very much like to run this in CI and validate.

if opts.partitionTestsInPackage != "" {
p.Packages = opts.partitionTestsInPackage
p.Description = fmt.Sprintf("partition %d with %d tests", p.ID, len(bucket.Items))
p.Tests = fmt.Sprintf("-run='^%v$'", strings.Join(bucket.Items, "$,^"))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be:

Suggested change
p.Tests = fmt.Sprintf("-run='^%v$'", strings.Join(bucket.Items, "$,^"))
p.Tests = fmt.Sprintf("-run ^%v$", strings.Join(bucket.Items, "|"))

See:

https://github.com/pulumi/pulumi/blob/86fbe80b8d99fe9346bad42f4f9c88b81a50a3db/scripts/get-job-matrix.py#L317-L327

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ya, the join needs to be a pipe not a comma for sure! Good catch.

I think you're right that we don't need the ^ and $ around each test name, but I'll need to test that out again. go test has some strange handling for regex (ex: golang/go#39904). We'll need to add ( and ) if we remove those.

Both = and should work for the separator. The = is nice because you can pass it as a single quoted arg instead of it being two separate arguments.

I believe the whole string does need to be quoted with single quotes so that the pipes and $ are not interpreted by the shell. In your case that may not be a problem because you're running it from python, but most of the time I expect this to be read from bash.

Copy link

@AaronFriel AaronFriel Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wish there were a simpler (& more efficient) way to provide a list of tests.

I don't think the whole string needs to be quoted - or you should let the user do the quoting. Easier for them to add quotes of the appropriate kind, and GitHub Actions allows plenty of ways to inject a variable or string into a script, e.g.: the following will ensure that any special characters are handled correctly:

  env:
    TESTS: ${{ inputs.tests }}
  run:
    echo $TESTS

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My primary goal with this command is to make it easy to integrate into a github workflow. Having to set a value into an env var just to use it does not make it easy. I expect someone to be able to do something like this and not have to worry about escaping or formatting the values.

I see your use case is quite different. You have a lot of code already in place, and you're looking for a tool to perform the test bucketing.

I think for your use case we could add a --format flag to this command. The default would be --format=github-action-matrix would be a JSON output that you can use directly in a github actions matrix. For your use case we could do --format=json, which would output the package list and test list as an array (instead of a space separated string, or a -run flag). That should make it easier for you to consume the output, while still supporting my primary goal of making it easy to use in a github workflow.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense to me.

@dnephin dnephin force-pushed the ci-matrix branch 2 times, most recently from 255c099 to d0adc24 Compare November 26, 2022 17:53
@dnephin dnephin deleted the branch gotestyourself:main November 26, 2022 18:54
@dnephin dnephin closed this Nov 26, 2022
@dnephin
Copy link
Member Author

dnephin commented Nov 26, 2022

That's weird, I deleted the base branch and instead of re-targeting main it closed this PR and won't let me re-open or retarget it.

Edit: ok, I was able to get it back by restoring the branch

@dnephin dnephin reopened this Nov 26, 2022
@dnephin dnephin changed the base branch from ci-matrix to main November 26, 2022 19:01
@abhinav abhinav mentioned this pull request Jan 31, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants