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

fix(IDX): update diff logic to work outside of PRs #1745

Closed
wants to merge 15 commits into from

Conversation

cgundy
Copy link
Member

@cgundy cgundy commented Sep 30, 2024

This PR contains two changes:

  • Update diff.sh to compare differences against the default branch if it was not created on a PR and therefore no TARGET_BRANCH is available.
  • rename CI_PULL_REQUEST_TARGET_BRANCH_NAME to TARGET_BRANCH_NAME for simplicity

@github-actions github-actions bot added the fix label Sep 30, 2024
@cgundy cgundy marked this pull request as ready for review September 30, 2024 11:35
@cgundy cgundy requested a review from a team as a code owner September 30, 2024 11:35
@github-actions github-actions bot added the @idx label Sep 30, 2024
@@ -13,7 +13,11 @@ set -euo pipefail
set -x
cd "$(git rev-parse --show-toplevel)"

MERGE_BASE="${MERGE_BASE_SHA:-HEAD}"
# since default branch is not the same in ic-private, we can't set it to master, throw error if missing
git fetch origin $DEFAULT_BRANCH
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would cause quite some downloads since we don't fetch all history when we checkout the repo.

Copy link
Member Author

Choose a reason for hiding this comment

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

But it's only pulling master... Or should I specify a couple commits like we have in the checkout step?

Copy link
Member

Choose a reason for hiding this comment

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

Using --depth 512 should be safe enough.

git fetch origin $DEFAULT_BRANCH
TARGET_BRANCH_NAME="${TARGET_BRANCH_NAME:-$DEFAULT_BRANCH}"
TARGET_BRANCH_SHA=$(git rev-parse origin/$TARGET_BRANCH_NAME)
MERGE_BASE=$(git merge-base HEAD "$TARGET_BRANCH_SHA")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't this cause the problem we discussed yesterday where HEAD on PRs points to a merge between the PR branch and the target branch meaning that this git merge-base HEAD "$TARGET_BRANCH_SHA" will return that merge commit which then results in COMMIT_RANGE being HEAD.. which then causes DIFF_FILES to become empty?

I'm doing these git calculations in my head so I could be wrong here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I realise I'm wrong. If HEAD points to a merge of the PR with the target branch git merge-base HEAD "$TARGET_BRANCH_SHA" should result in $TARGET_BRANCH_SHA.
Meaning COMMIT_RANGE=$TARGET_BRANCH_SHA... So that could actually work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I double checked this and from my understanding git merge-base will always return the common ancestor (so not the merge commit). It's the same as MERGE_BASE_SHA: ${{ github.event.pull_request.base.sha }}. The one that could return a merge commit would be the latest commit, which is CI_COMMIT_SHA: ${{ github.sha }}.

@cgundy cgundy requested a review from basvandijk October 1, 2024 08:55
@cgundy cgundy closed this Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants