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

[chore] Add scoped GH action to test affected components on Windows #37106

Merged
merged 3 commits into from
Jan 9, 2025

Conversation

pjanotti
Copy link
Contributor

@pjanotti pjanotti commented Jan 8, 2025

Description

Many times changes that break Windows CI are merged since it is not apparent that they will break on Windows. Given the cost of running Windows CI for every PR the label Run Windows is only added in few cases. This change adds make targets that allow to run make commands only for tests and dependencies affected by files being changed.

It uses a simple detection of go files that were changed and look to the import commands to find the components that depend directly on the package being changed.

Link to tracking issue

Relates to #36788

Testing

Validated on my fork, e.g.: https://github.com/pjanotti/opentelemetry-service-contrib/actions/runs/12659871185

Documentation

N/A

@pjanotti pjanotti requested a review from a team as a code owner January 8, 2025 23:12
@pjanotti pjanotti requested a review from MovieStoreGuy January 8, 2025 23:12
@pjanotti pjanotti added Skip Changelog PRs that do not require a CHANGELOG.md entry ci-cd CI, CD, testing, build issues labels Jan 8, 2025

- name: Get changed go files
id: changed-files
uses: tj-actions/changed-files@v45
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This action is already used to check links in markdown files.

Copy link
Member

Choose a reason for hiding this comment

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

We have several actions that check for diffs and in the past have found that comparing directly against main causes a lot of pain because unrelated changes to main are detected in the diff. e.g. Your PR changes module X, but while you were working on it modules A, B, and C were updated by other PRs. Now your PR shows a diff of A, B, C, and X. This repo is one of the busiest in all of open source, so it tends to surface this type of problem more than most.

The solution we're relied on is to diff against the most recent common ancestor commit (via git merge-base). I took just a quick look at tj-actions/changed-files and I think it's not using this strategy, though it does perform a boolean "can diff" check based on it.

In any case, I think it's fine to start here but I wanted to note that we should keep an eye out for this kind of issue and may need to change how we determine the diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the info, I will keep an eye on this potential issue.

key: go-cache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}

- name: Run changed tests
if: needs.changedfiles.outputs.go_tests
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is added to cover the case of only changes affecting test files. If the step running tests on dependent components hit the same test it will used the cached results.

env:
CHANGED_GOLANG_SOURCES: ${{ needs.changedfiles.outputs.go_sources }}
run: |
make for-affected-components CMD="make test"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially I wanted to run CMD="make" to run the default target of the component, however, some targets break on Windows due to the size of the command line - to be investigated separately.

echo "No go source changes detected in shippable code."; \
else \
cd $(SRC_ROOT); \
DEPENDENT_PKGS=$$(echo $(CHANGED_GOLANG_SOURCES) | xargs sed -n 's|^package .* // import "\(.*\)"$$|\1|p' | uniq); \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This stops at the components directly dependent on the components being changed. In the future we can consider running through all levels of dependent code, eventually hitting the collector itself. However, I wanted to start small and see what I may have missed in this change.

Copy link
Member

@djaglowski djaglowski left a comment

Choose a reason for hiding this comment

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

I'm excited to see how this goes. Seems promising.


- name: Get changed go files
id: changed-files
uses: tj-actions/changed-files@v45
Copy link
Member

Choose a reason for hiding this comment

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

We have several actions that check for diffs and in the past have found that comparing directly against main causes a lot of pain because unrelated changes to main are detected in the diff. e.g. Your PR changes module X, but while you were working on it modules A, B, and C were updated by other PRs. Now your PR shows a diff of A, B, C, and X. This repo is one of the busiest in all of open source, so it tends to surface this type of problem more than most.

The solution we're relied on is to diff against the most recent common ancestor commit (via git merge-base). I took just a quick look at tj-actions/changed-files and I think it's not using this strategy, though it does perform a boolean "can diff" check based on it.

In any case, I think it's fine to start here but I wanted to note that we should keep an eye out for this kind of issue and may need to change how we determine the diff.

@dmitryax dmitryax merged commit 2c7b377 into open-telemetry:main Jan 9, 2025
163 checks passed
@github-actions github-actions bot added this to the next release milestone Jan 9, 2025
@pjanotti pjanotti deleted the scoped-make-targets branch January 9, 2025 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-cd CI, CD, testing, build issues Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants