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

Don't commit a file if its contents did not change #189

Open
quartz-fm opened this issue Feb 15, 2024 · 1 comment
Open

Don't commit a file if its contents did not change #189

quartz-fm opened this issue Feb 15, 2024 · 1 comment

Comments

@quartz-fm
Copy link

Is your feature request related to a problem? Please describe.
I noticed that a commit is pushed to the target repo when pushing a file to a repository, even when the file has no changes. This triggers unnecessary CI runs due to the commit. As each file is committed individually, it makes things even worse by triggering multiple CI runs in parallel.

Describe the solution you'd like
Nothing should happen if a file has no changes.

Describe alternatives you've considered
Use many workflows/jobs/settings with filtering logic to trigger only on change— which is better solved by using other file sync actions.

Additional context
I think the GitHub REST API makes a commit, regardless of whether the file contents changed, when you invoke it here:

result = repo.update_file(
str(file_config.dest_file.relative_to(".")),
file_config.commit_msg,
file_contents,
sha=dest_contents.sha,
branch=target_branch,
)

I think you already have both files' contents thanks to:

file_contents = (
file_config.src_file_contents
if not file_config.remote_src
else get_remote_file_contents(repo, file_config.src_file, target_branch)
)

and

dest_contents = repo.get_contents(str(file_config.dest_file), ref=target_branch)

Could a SHA or contents comparison be added? I don't know Python or the GitHub API, so I did my best to investigate, but I can't do more on my side. Thanks!

@andrewthetechie
Copy link
Owner

Hello,

I'd approve a PR for these changes if someone comes up with a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants