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

Diff might be inaccurate if HEAD's parent is an ancestor of BASE #11

Open
joshgubler opened this issue Mar 3, 2025 · 11 comments
Open
Assignees
Labels
enhancement New feature or request question Further information is requested released on @next

Comments

@joshgubler
Copy link

If a change is made to the BASE branch in parallel to the HEAD branch, the diff from this module indicates that the change will be reverted. Git, however, is smart enough to know that the change should not be reverted when the PR is merged.

Old Base -> BASE
         \
           -> HEAD

It's very easy to get into this state if the person creating the PR doesn't git pull before creating their feature branch.

Rather than comparing the output from kustomize on BASE with the output on HEAD, it would be better to compare the output on BASE with the output after merging HEAD to BASE. Obviously, this merge should only happen locally on the runner and not be pushed.

@swade1987
Copy link
Owner

@joshgubler would love your review on #13 if/when you have a second.

@swade1987 swade1987 self-assigned this Mar 11, 2025
@swade1987 swade1987 added the enhancement New feature or request label Mar 11, 2025
@swade1987
Copy link
Owner

🎉 This issue has been resolved in version 0.3.0-next.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@swade1987
Copy link
Owner

swade1987 commented Mar 12, 2025

@joshgubler, I've implemented the changes we discussed. Could you please test this latest version (above) and provide feedback on its functionality? If everything works as expected, I'll create a full release. Thank you for your help with testing!

@joshgubler
Copy link
Author

I got the following error:

++ mktemp -d
+ TMP_DIR=/tmp/tmp.JbDcAD
+ ROOT_DIR=apps/dsa-manager/envs/dev
+ MAX_DEPTH=2
+ DEBUG=true
+ echo Configuration:
+ echo 'ROOT_DIR: apps/dsa-manager/envs/dev'
+ echo 'MAX_DEPTH: 2'
+ echo 'DEBUG: true'
+ debug_log 'Debug mode is enabled'
+ '[' true = true ']'
+ printf '[DEBUG] %s \n' 'Debug mode is enabled'
+ main
+ validate_root_dir
+ '[' '!' -d apps/dsa-manager/envs/dev ']'
+ validate_max_depth
+ [[ 2 =~ ^[0-9]+$ ]]
+ git config --global --add safe.directory /github/workspace
Configuration:
ROOT_DIR: apps/dsa-manager/envs/dev
MAX_DEPTH: 2
DEBUG: true
[DEBUG] Debug mode is enabled 
+ local current_branch
++ git rev-parse --abbrev-ref HEAD
+ current_branch=HEAD
++ safe_filename main
++ echo main
++ sed 's/[^a-zA-Z0-9.]/_/g'
+ local safe_base_ref=main
+ local base_output_dir=/tmp/tmp.JbDcAD/base
+ build_ref main /tmp/tmp.JbDcAD/base
+ local ref=main
+ local output_dir=/tmp/tmp.JbDcAD/base
+ echo 'Checking out ref: main'
Checking out ref: main
+ git checkout main --quiet
+ mkdir -p /tmp/tmp.JbDcAD/base
++ get_targets
++ find apps/dsa-manager/envs/dev -maxdepth 2 -name kustomization.yaml -exec dirname '{}' ';'
+ for envpath in $(get_targets)
+ local relative_path=apps/dsa-manager/envs/dev
++ safe_filename apps/dsa-manager/envs/dev
++ echo apps/dsa-manager/envs/dev
++ sed 's/[^a-zA-Z0-9.]/_/g'
+ local safe_path=apps_dsa_manager_envs_dev
+ local output_file=/tmp/tmp.JbDcAD/base/apps_dsa_manager_envs_dev.yaml
+ echo 'Running kustomize for apps/dsa-manager/envs/dev'
Running kustomize for apps/dsa-manager/envs/dev
+ kustomize build apps/dsa-manager/envs/dev -o /tmp/tmp.JbDcAD/base/apps_dsa_manager_envs_dev.yaml
+ '[' true = true ']'
[DEBUG] Built kustomize for apps/dsa-manager/envs/dev to /tmp/tmp.JbDcAD/base/apps_dsa_manager_envs_dev.yaml 
+ debug_log 'Built kustomize for apps/dsa-manager/envs/dev to /tmp/tmp.JbDcAD/base/apps_dsa_manager_envs_dev.yaml'
+ '[' true = true ']'
+ printf '[DEBUG] %s \n' 'Built kustomize for apps/dsa-manager/envs/dev to /tmp/tmp.JbDcAD/base/apps_dsa_manager_envs_dev.yaml'
+ local merge_branch=temp-merge-[13](https://github.com/byu-oit/k8s-app-manifests/actions/runs/13820938668/job/38665870767?pr=280#step:4:14)175
+ git checkout -b temp-merge-13175 main --quiet
+ debug_log 'Creating temporary merge of test-kustomize-diff into main'
+ '[' true = true ']'
+ printf '[DEBUG] %s \n' 'Creating temporary merge of test-kustomize-diff into main'
+ git merge test-kustomize-diff --quiet
[DEBUG] Creating temporary merge of test-kustomize-diff into main 
merge: test-kustomize-diff - not something we can merge

Did you mean this?
	origin/test-kustomize-diff
Merge conflict detected. Cannot automatically merge test-kustomize-diff into main.
+ echo 'Merge conflict detected. Cannot automatically merge test-kustomize-diff into main.'
+ git merge --abort
fatal: There is no merge to abort (MERGE_HEAD missing).

I was able to merge the branch without a merge conflict, so that isn't the problem. Is there a bug in the git merge command that is getting the name of the local branch wrong?

@joshgubler
Copy link
Author

@swade1987
Copy link
Owner

Any chance you could try v0.3.0-next.2 please 🙏

@joshgubler
Copy link
Author

New error: https://github.com/joshgubler/kustomize-diff-test/actions/runs/13838671230/job/38720180623?pr=1#step:4:94

/kustdiff: line 126: head_ref_to_use: unbound variable

@swade1987
Copy link
Owner

@swade1987 swade1987 added the question Further information is requested label Mar 14, 2025
@joshgubler
Copy link
Author

Looks like git want's you to set the committer identity before it can create the merge commit. This can be anything since you're not going to push the commit anywhere.
https://github.com/joshgubler/kustomize-diff-test/actions/runs/13867173058/job/38808454587?pr=1#step:4:97

Sorry if this is turning into more work than it is worth.

@joshgubler
Copy link
Author

I'm happy to keep testing for you. Or feel free to fork my test repo if you don't want to wait for me.

@swade1987
Copy link
Owner

Don't worry we will get there as I think it's a valid feature. I'll take a look next week and keep you posted. Thanks in advance and the continued testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested released on @next
Projects
None yet
Development

No branches or pull requests

2 participants