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

workflows: Improve the change check for issue_comment triggers #16841

Merged

Conversation

pchaigno
Copy link
Member

@pchaigno pchaigno commented Jul 9, 2021

Joe reported that the CI 3.0 tests were triggered in his pull request, even though it only touched test/ code and we should skip those tests in that case. The logs revealed that happened because the workflow had an incorrect view of the pull request diff (saw more changes than existed).

To retrieve the set of changed files, we instruct the paths-filter GitHub action to compare .base.sha and .head.sha. .head.sha points to the tip of the pull request branch. .base.sha however doesn't point to the last master commit of the pull request branch (the commit on which the pull request is based). Instead it points to the latest master commit at the time you trigger the workflows.

This pull request fixes this by manually retrieving the base commit via the GitHub API.

@pchaigno pchaigno added kind/bug/CI This is a bug in the testing code. area/CI Continuous Integration testing issue or flake release-note/ci This PR makes changes to the CI. labels Jul 9, 2021
@pchaigno pchaigno marked this pull request as ready for review July 9, 2021 13:29
@pchaigno pchaigno requested review from a team as code owners July 9, 2021 13:29
@pchaigno pchaigno requested a review from nbusseneau July 9, 2021 13:29
@pchaigno pchaigno marked this pull request as draft July 9, 2021 14:13
@nbusseneau
Copy link
Member

Copying what I said on Slack regarding:

Unfortunately, there doesn't seem to be an easy way to retrieve the commit on which the pull request is based.

If you'd prefer to get the parent SHA, we already have a retrieval snippet here:

PR_COMMITS_API_JSON=$(curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
${{ github.event.pull_request.commits_url }})
PR_FIRST_SHA=$(echo "$PR_COMMITS_API_JSON" | jq -r ".[0].sha")
PR_PARENT_SHA=$(git rev-parse "${PR_FIRST_SHA}^")

No idea what approach is most useful.

@pchaigno pchaigno force-pushed the pr/pchaigno/workflows-improve-change-diff-for-issue_comment branch 4 times, most recently from e4f1ee4 to 4e85e2a Compare August 13, 2021 10:38
@pchaigno pchaigno marked this pull request as ready for review August 13, 2021 10:50
@pchaigno
Copy link
Member Author

Thanks @nbusseneau for the suggestion! I've taken the approach you suggested. I think it's best, at least for consistency/readability.

Joe reported that the CI 3.0 tests were triggered in his pull request,
even though it only touched test/ code and we should skip those tests in
that case [1]. The logs revealed that happened because the workflow had
an incorrect view of the pull request diff (saw more changes than
existed).

To retrieve the set of changed files, we instruct the paths-filter
GitHub action to compare .base.sha and .head.sha. .head.sha points to
the tip of the pull request branch. .base.sha however doesn't point to
the last master commit of the pull request branch (the commit on which
the pull request is based). Instead it points to the latest master
commit at the time you trigger the workflows.

This commit fixes this by  manually retrieving the base commit via the
GitHub API.

1 - https://github.com/cilium/cilium/blob/v1.10.2/.github/workflows/conformance-aks.yaml#L69
Reported-by: Joe Stringer <joe@cilium.io>
Suggested-by: Nicolas Busseneau <nicolas@isovalent.com>
Signed-off-by: Paul Chaignon <paul@cilium.io>
@pchaigno pchaigno force-pushed the pr/pchaigno/workflows-improve-change-diff-for-issue_comment branch from 4e85e2a to fd38ded Compare August 13, 2021 16:12
@pchaigno pchaigno added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Aug 14, 2021
@ti-mo ti-mo merged commit 98e6ea4 into master Aug 16, 2021
@ti-mo ti-mo deleted the pr/pchaigno/workflows-improve-change-diff-for-issue_comment branch August 16, 2021 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/CI Continuous Integration testing issue or flake kind/bug/CI This is a bug in the testing code. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/ci This PR makes changes to the CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants