-
Notifications
You must be signed in to change notification settings - Fork 57
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
Add change calculation tool #1975
base: main
Are you sure you want to change the base?
Conversation
Add a new tool changecalc that calculates all packages that need to be re-tested given a list of changed files. Without a list, uses git to compare with main branch. 'make viewchanges' runs the tool. 'make testchanges' runs the test suite over affected packages. New tests-changes github job is added in shadow mode that takes advantage of this tool.
a081a1e
to
b0c4645
Compare
Example test:
|
Run make testchanges cat: changed-packages.txt: No such file or directory ✓ Running tests based on changes relative to main... changecalc/changecalc > changed-packages.txt || echo "./..." > changed-packages.txt fatal: bad revision 'main' failed to execute [git diff main --name-only -- .]: exit status 128 gotestsum --format pkgname-and-test-fails --no-summary=skipped --raw-command go test -v -json -short -coverprofile=coverage.txt ✓ . (32ms) (coverage: 0.0% of statements)
Getting this error changecalc/changecalc > changed-packages.txt || echo "./..." > changed-packages.txt fatal: bad revision 'main' failed to execute [git diff main --name-only -- .]: exit status 128 https://stackoverflow.com/a/76769122
recommended here actions/checkout#118
This reverts commit 7954f92.
64b0958
to
bc6fa65
Compare
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
Test Details: go/deco-tests/12202420953 |
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.
Thanks! This would be nice to have for local development but I'm not sure we can use this for our unit testing workflow since there might be implicit dependencies that are not captured by the import dependencies.
Could you clarify the intention behind adding this functionality?
- windows-latest | ||
|
||
steps: | ||
- name: Checkout repository and submodules |
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.
Create a reusable workflow for the first 5 steps since they are the same for both all and partial unit tests?
https://dev.to/n3wt0n/avoid-duplication-github-actions-reusable-workflows-3ae8
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 command to run can be passed as an arg to the common workflow.
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 intent is to replace the existing one with this one, so we can keep the dup for a little while.
@@ -57,6 +57,57 @@ jobs: | |||
- name: Publish test coverage | |||
uses: codecov/codecov-action@v4 | |||
|
|||
tests-changes: |
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 presume the intention behind this is to facilitate faster local development since now you can simply run make testchanges
? For the push workflow we would still need to run everything since import dependencies are not enough to track all relevant tests.
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.
Could you add a comment here explaining the intention of running this as a workflow? Presumably to ensure the test changes section works correctly?
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 intention for this tool to be used for running both unit tests and integration tests on CI. It can save significant time, especially in this cases:
- test only change; in that case
- change is local affects only set of tests (e.g. bundle tests).
In that case we won't need 2 workflows, only workflow via this tool will remain. Engineers will be able to opt out, e.g. by adding /fulltests in description or comment.
For the push workflow we would still need to run everything since import dependencies are not enough to track all relevant tests.
Can you give counter-example? Note, it also establishes data dependencies (with some assumptions).
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.
changecalc
can be a package in internal
instead of a top-level CLI package.
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.
+1, or "tools". I'm sure there are more we'd like to check in and take advantage of.
As long as it is not top-level.
// GetChangedFiles compares the current branch to the base branch | ||
// and returns a slice of file paths that have been modified. | ||
func GetChangedFiles(baseBranch string) ([]string, error) { | ||
command := []string{"git", "diff", baseBranch, "--name-only", "--", "."} |
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.
Should we use git status
here if this is meant to facilitate local development?
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 what you mean? Could you clarify how "git status" would be used?
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.
Looks cool!
- windows-latest | ||
|
||
steps: | ||
- name: Checkout repository and submodules |
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 intent is to replace the existing one with this one, so we can keep the dup for a little while.
xargs gotestsum --format pkgname-and-test-fails --no-summary=skipped --raw-command go test -v -json -short -coverprofile=coverage.txt < affected-packages.txt | ||
|
||
changecalc/changecalc: changecalc/*.go | ||
@go build -o changecalc/changecalc changecalc/main.go |
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 prefer to not have targets for Go builds if we can rely on go run
to do the caching and invalidation for us.
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.
+1, or "tools". I'm sure there are more we'd like to check in and take advantage of.
As long as it is not top-level.
@@ -0,0 +1,6 @@ | |||
base_branch: refs/remotes/origin/main |
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.
Do we need to configure this in a config file?
} | ||
} | ||
return false | ||
} |
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.
Some of these functions could move into a dedicated and testable package.
Changes
Add a new tool changecalc that calculates all packages that need to be re-tested given a list of changed files. Without a list, uses git to compare with main branch.
'make viewchanges' runs the tool.
'make testchanges' runs the test suite over affected packages.
New tests-changes github job is added in shadow mode that takes advantage of this tool.
Tests
Manually. If we land this, we can observe the job on real PRs and how it compares with full runs.