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

Compute affected tests in CI workflow is omitting targets affected by committed renamed files #4035

Open
BenHenning opened this issue Dec 10, 2021 · 5 comments
Assignees
Labels
bug End user-perceivable behaviors which are not desirable. Impact: Low Low perceived user impact (e.g. edge cases). Z-ibt Temporary label for Ben to keep track of issues he's triaged.

Comments

@BenHenning
Copy link
Member

BenHenning commented Dec 10, 2021

See #4020 (comment) for specifics. However, because the script is computing the wrong base branch, in some cases it may miss changes (such as was noticed in #4020) which is a serious problem since we won't end up running affected targets until after the PR is merged.

#4034 is my working PR to investigate.

@BenHenning
Copy link
Member Author

BenHenning commented Dec 11, 2021

Follow-up: I thought the issue was because the merge-base was different between the branch & running it locally (I think this is because GitHub actually generates a merge commit which seems to combine the latest develop with the changes in the PR branch & then runs CI workflows against that merge commit).

However, forcing CI workflow to use the HEAD commit for the PR didn't fix the issue (per https://github.com/actions/checkout#checkout-pull-request-head-commit-instead-of-merge-commit).

Upon further investigation, I realized that there's a difference in Git versions. My local version is 2.7.4 where the script behaves correctly, and CI is using Git 2.34.1. Since GitHub updates our environment from underneath us, this is an undiscovered regression. Interestingly, the compute affected tests test suite didn't catch this despite using real Git (though the root cause is still unknown since it's not clear what the actual regression is yet). My guess is that a relatively new version of Git changed how it treats moved files reported in git diff.

@BenHenning
Copy link
Member Author

https://stackoverflow.com/a/10121060/3689782 provides some context here. git diff on the old version would output both the old & new files, whereas with -M (& with the new git without any parameter) it only outputs the old files. Because we use this list to compute affected targets, the result is wrong. I'm trying to figure out how to get git diff to provide the correct file names. We'll also need a test that specifically verifies a committed moved file.

@BenHenning BenHenning changed the title Compute affected tests in CI workflow is computing the wrong merge base with develop Compute affected tests in CI workflow is omitting targets affected by committed renamed files Dec 11, 2021
@BenHenning
Copy link
Member Author

git 2.9.0 was the version when rename detection was automatically enabled upon git diff (see https://github.com/git/git/blob/142430338477d9d1bb25be66267225fb58498d92/Documentation/RelNotes/2.9.0.txt#L33) so this issue has existed since the script was introduced in CI.

@BenHenning
Copy link
Member Author

BenHenning commented Dec 11, 2021

https://stackoverflow.com/a/55839215/3689782 is a help, and I realize that all we need to add is --no-renames to disable the renaming detection (& thus move back to the old git behavior). Gonna need to add a test to ensure that this can actually be caught it if were to ever regress since it's a rather serious failure in the script.

@BenHenning BenHenning added this to the Beta MR2 milestone Jun 11, 2022
@Broppia Broppia added Impact: Low Low perceived user impact (e.g. edge cases). user_team labels Jul 29, 2022
@Broppia Broppia added dev_team and removed user_team labels Aug 2, 2022
@BenHenning BenHenning added the Z-ibt Temporary label for Ben to keep track of issues he's triaged. label Sep 16, 2022
@BenHenning BenHenning removed this from the Beta MR2 milestone Sep 16, 2022
@seanlip seanlip added bug End user-perceivable behaviors which are not desirable. and removed issue_type_infrastructure labels Mar 28, 2023
@Rd4dev
Copy link
Collaborator

Rd4dev commented Aug 30, 2024

Following up on #3022 (comment)

You made some changes to BazelClient--do you think that change would fix ComputeAffectedTests for moved files, as well?

@BenHenning, with the case of ComputeChangedFiles I did not modify any BazelClient stuff rather I used GitClient to retrieve the renamed / moved files using the following:

private fun retrieveRenamedFiles(): List<String> {
  val renamedFilesCommand = executeGitCommand("diff -M --name-status ${computeCommitRange()}")
  return renamedFilesCommand.filter { it.startsWith("R") }
    .map { it.split("\t")[1] }
}

The command execution:

$ git diff -M --name-status HEAD..3b7ddb91bf67fcbc9abace491f680fdfcd2aa538
M       .github/workflows/unit_tests.yml
M       scripts/src/java/org/oppia/android/scripts/common/GitClient.kt
R100    scripts/src/java/org/oppia/android/scripts/coverage/CoverageReporter.kt scripts/src/java/org/oppia/android/scripts/coverage/reporter/CoverageReporter.kt
M       utility/src/main/java/org/oppia/android/util/math/MathTokenizer.kt

Would this be something that can be done with ComputAffectedTests to include targets affected by renamed files or is that different in this case?

I tried implementing the same for ComputeAffectedTests by just including the renamedFiles lists to changedFiles,

Changed Files Lists & Stack Traces

Initial Changed Files List without moving files and adding the retrieval of renamed files method -
Changed files (per Git, 2 total): stack trace

[.github/workflows/unit_tests.yml, utility/src/main/java/org/oppia/android/util/math/MathTokenizer.kt].

After moving CoverageReporter.kt from coverage/reporter -> coverage:
Without retrieval of renamed files -
Changed files (per Git, 2 total): stack trace

[.github/workflows/unit_tests.yml, utility/src/main/java/org/oppia/android/util/math/MathTokenizer.kt].

After moving CoverageReporter.kt from coverage/reporter -> coverage:
With retrieval of renamed files included for retrieveChangedFilesWithPotentialDuplicates() -
Changed files (per Git, 4 total): stack trace

[.github/workflows/unit_tests.yml, scripts/src/java/org/oppia/android/scripts/common/GitClient.kt, utility/src/main/java/org/oppia/android/util/math/MathTokenizer.kt, scripts/src/java/org/oppia/android/scripts/coverage/CoverageReporter.kt].

Seems to provide the newly moved filenames as the result, and could that also help with this - #4035 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug End user-perceivable behaviors which are not desirable. Impact: Low Low perceived user impact (e.g. edge cases). Z-ibt Temporary label for Ben to keep track of issues he's triaged.
Projects
Development

No branches or pull requests

4 participants