Skip to content

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

@quartz-fm

Description

@quartz-fm

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions