-
-
Notifications
You must be signed in to change notification settings - Fork 364
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
Selective Execution based on input file and code changes #4091
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
b88b299
basic input change selection works
lihaoyi ac2c65a
basic input change selection works
lihaoyi fd1561b
.
lihaoyi b470d81
selective-changed-code test case
lihaoyi 4d2f5eb
.
lihaoyi 88c9102
.
lihaoyi 87bcfee
.
lihaoyi eeccc66
.
lihaoyi 96406f0
.
lihaoyi 7cf975a
.
lihaoyi 081594b
.
lihaoyi 038cca2
cleanup
lihaoyi 3836297
basic failure test
lihaoyi 837925a
.
lihaoyi 8869615
.
lihaoyi 36e56ae
.
lihaoyi 1b93107
.
lihaoyi 6e138ba
.
lihaoyi eb3b4e8
.
lihaoyi cecc6e8
.
lihaoyi 95584f9
.
lihaoyi 2800405
.
lihaoyi 12621a8
add failing watch.show-changed-input test
lihaoyi 295b4f2
.
lihaoyi 43fda15
.
lihaoyi 4064c81
.
lihaoyi ab914ef
.
lihaoyi f2925ce
.
lihaoyi 650b0fe
.
lihaoyi 5fa8110
.
lihaoyi d589f51
.
lihaoyi d6f89f1
.
lihaoyi 2ec514d
.
lihaoyi fbb67f1
.
lihaoyi 7e13f75
.
lihaoyi eba08cd
retries
lihaoyi bf8ab42
retries
lihaoyi 32a232c
cleanup
lihaoyi 3fb4e72
cleanup
lihaoyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
example/depth/large/9-selective-execution/bar/src/bar/Bar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package bar; | ||
|
||
public class Bar { | ||
public static String generateHtml(String text) { | ||
return "<h1>" + text + "</h1>"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
example/depth/large/9-selective-execution/bar/test/src/bar/BarTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package bar; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
public class BarTests { | ||
|
||
@Test | ||
public void simple() { | ||
String result = Bar.generateHtml("hello"); | ||
assertEquals("<h1>hello</h1>", result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Mill allows you to filter the tests and other tasks you execute by limiting them | ||
// to those affected by a code change. This is useful in managing large codebases where | ||
// running the entire test suite in CI is often very slow, so you only want to run the | ||
// tests or tasks that are affected by the changes you are making. | ||
// | ||
// This is done via the following commands: | ||
// | ||
// * `mill selective.prepare <selector>`: run on the codebase before the code change, | ||
// stores a snapshot of task inputs and implementations | ||
// | ||
// * `mill selective.run <selector>`: run on the codebase after the code change, | ||
// runs tasks in the given `<selector>` which are affected by the code changes | ||
// that have happen since `selective.prepare` was run | ||
// | ||
// * `mill selective.resolve <selector>`: a dry-run version of `selective.run`, prints | ||
// out the tasks in `<selector>` that are affected by the code changes and would have | ||
// run, without actually tunning them. | ||
// | ||
// For example, if you want to run all tests related to the code changes in a pull | ||
// request branch, you can do that as follows: | ||
// | ||
// ```bash | ||
// > git checkout main # start from the target branch of the PR | ||
// | ||
// > ./mill selective.prepare __.test | ||
// | ||
// > git checkout pull-request-branch # go to the pull request branch | ||
// | ||
// > ./mill selective.run __.test | ||
// ``` | ||
// | ||
// The example below demonstrates selective test execution on a small 3-module Java build, | ||
// where `bar` depends on `foo` but `qux` is standalone: | ||
|
||
package build | ||
import mill._, javalib._ | ||
|
||
trait MyModule extends JavaModule { | ||
object test extends JavaTests with TestModule.Junit4 | ||
} | ||
|
||
object foo extends MyModule { | ||
def moduleDeps = Seq(bar) | ||
} | ||
|
||
object bar extends MyModule | ||
|
||
object qux extends MyModule | ||
|
||
// In this example, `qux.test` starts off failing with an error, while `foo.test` and | ||
// `bar.test` pass successfully. Normally, running `__.test` will run all three test | ||
// suites and show both successes and the one failure: | ||
|
||
/** Usage | ||
|
||
> mill __.test | ||
error: Test run foo.FooTests finished: 0 failed, 0 ignored, 1 total, ... | ||
Test run bar.BarTests finished: 0 failed, 0 ignored, 1 total, ... | ||
Test run qux.QuxTests finished: 1 failed, 0 ignored, 1 total, ... | ||
|
||
*/ | ||
|
||
// However, this is not always what you want. For example: | ||
// | ||
// * If you are validating a pull request | ||
// in CI that only touches `bar/`, you do not want the failure in `qux.test` to fail | ||
// your tests, because you know that `qux.test` does not depend on `bar/` and thus the | ||
// failure cannot be related to your changes. | ||
// | ||
// * Even if `qux.test` wasn't failing, running it on a pull request that changes `bar/` is | ||
// wasteful, taking up compute resources to run tests that could not possibly be affected | ||
// by the code change in question. | ||
// | ||
// To solve this, you can run `selective.prepare` before the code change, then `selective.run` | ||
// after the code change, to only run the tests downstream of the change (below, `foo.test` and `bar.test`): | ||
|
||
/** Usage | ||
|
||
> mill selective.prepare __.test | ||
|
||
> echo '//' >> bar/src/bar/Bar.java # emulate the code change | ||
|
||
> mill selective.resolve __.test # dry-run selective execution to show what would get run | ||
foo.test.test | ||
bar.test.test | ||
|
||
> mill selective.run __.test | ||
Test run foo.FooTests finished: 0 failed, 0 ignored, 1 total, ... | ||
Test run bar.BarTests finished: 0 failed, 0 ignored, 1 total, ... | ||
|
||
*/ | ||
|
||
// Similarly, if we make a change `qux/`, using selective execution will only run tests | ||
// in `qux.test`, and skip those in `foo.test` and `bar.test`. | ||
// These examples all use `__.test` to selectively run tasks named `.test`, but you can | ||
// use selective execution on any subset of tasks by specifying them in the selector. | ||
// | ||
// Selective execution is very useful for larger codebases, where you are usually changing | ||
// only small parts of it, and thus only want to run the tests related to your changes. | ||
// This keeps CI times fast and prevents unrelated breakages from affecting your CI runs. | ||
11 changes: 11 additions & 0 deletions
11
example/depth/large/9-selective-execution/foo/src/foo/Foo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package foo; | ||
|
||
public class Foo { | ||
|
||
public static final String VALUE = "hello"; | ||
|
||
public static void mainFunction(String fooText, String barText) { | ||
System.out.println("Foo.value: " + Foo.VALUE); | ||
System.out.println("Bar.value: " + bar.Bar.generateHtml(barText)); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
example/depth/large/9-selective-execution/foo/test/src/bar/FooTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package foo; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
public class FooTests { | ||
@Test | ||
public void simple() { | ||
assertEquals(Foo.VALUE, "hello"); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
example/depth/large/9-selective-execution/qux/src/qux/Qux.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package qux; | ||
|
||
public class Qux { | ||
public static String generateHtml(String text) { | ||
return "<p>" + text + "</p>"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
example/depth/large/9-selective-execution/qux/test/src/qux/QuxTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package qux; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
public class QuxTests { | ||
|
||
@Test | ||
public void simple() { | ||
String result = Qux.generateHtml("world"); | ||
assertEquals("<p>world!</p>", result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is the right place, but it might be useful to give a blueprint on how this could be implemented in CI, e.g. with github actions.
If I understand correctly, you'd want to save
mill-selective-execution.json
in the main branch and fetch it for every pull request CI run. Is that correct?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs are meant to explain how to make use of it. Not sure if I did a good job tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they're pretty clear! I guess what my comment boils down to, is that there's no mention of
mill-selective-execution.json
in the docs, which, if I understand correctly, is the file that needs to be created on CI-main runs and used in CI-PR runs.But it's a detail and we can ignore it, maybe adding examples later on.