Skip to content

github_repository_file keeps sending empty commits with the same commit message despite no changes to file content #689

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

Closed
ahmadnassri opened this issue Feb 2, 2021 · 7 comments · May be fixed by #2643
Labels
r/repository_file Status: Stale Used by stalebot to clean house Type: Bug Something isn't working as documented

Comments

@ahmadnassri
Copy link

ahmadnassri commented Feb 2, 2021

(I had already opened an issue about this in the old repo, but after it moved here, seems to have been lost...)

Terraform Version

Terraform v0.14.5

Affected Resource(s)

  • github_repository_file

Terraform Configuration Files

resource "github_repository_file" "file" {
  for_each = {
    for x in flatten([
      for name, repo in var.repos : [
        for file in fileset("templates", "${repo.template}/**") : {
          repo     = name
          file     = trimprefix(file, "${repo.template}/")
          template = repo.template
        }
      ] if can(repo.template) && lookup(repo, "archived", false) == false
    ]) : "${x.repo}:${x.file}" => x
  }

  repository          = each.value.repo
  branch              = github_branch_default.default[each.value.repo].branch
  file                = each.value.file
  content             = file("templates/${each.value.template}/${each.value.file}")
  commit_message      = "chore(template): update ${each.value.file}"
  overwrite_on_create = true

  depends_on = [
    github_repository.repository
  ]
}

Expected Behavior

Should not be sending empty commits with the file content not having changed!

Actual Behavior

when running terraform plan everything looks correct, and there is no indication that any modifications to the referenced files will be triggered, but when running terraform apply a whole bunch of empty commits are sent with the same commit message template

see this repo for a recent example: https://github.com/ahmadnassri/node-glob-promise/commits/master

all the commits starting with chore(template) are an example of this

I tried adding

  lifecycle {
    ignore_changes = [
      commit_message
    ]
  }

but that simply re-uses whatever the previous commit message was for the file and commits anyways!

@ahmadnassri ahmadnassri changed the title github_repository_file keeps sending empty commits with the same commit message despite no changes to file contnet github_repository_file keeps sending empty commits with the same commit message despite no changes to file content Feb 2, 2021
@jcudit jcudit added Type: Bug Something isn't working as documented r/repository_file labels Feb 5, 2021
@simontabor
Copy link

Have you tried this?

  lifecycle {
    ignore_changes = [
      commit_author, 
      commit_email,
      commit_message
    ]
  }

It seems very buggy though, as you said with ignoring commit_message, it's re-used the previous commit message for the file. I'm going to test what happens with just ignoring the commit_email and commit_author (ie, not the message)

@ahmadnassri
Copy link
Author

I had not tried ignoring the other two fields, but .. since the files were already created by and continue to use the same author / email (they are 100% managed by Terraform), I don't believe it would have made a difference

@simontabor
Copy link

@ahmadnassri I just tested it and confirmed that ignoring the commit_author and commit_email meant it stopped detecting changes. Don't ignore the message, otherwise it'll modify the old commit message no matter what.

@github-actions
Copy link

github-actions bot commented Dec 4, 2022

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

@github-actions github-actions bot added the Status: Stale Used by stalebot to clean house label Dec 4, 2022
@github-actions github-actions bot removed the Status: Stale Used by stalebot to clean house label Dec 6, 2022
@mloskot
Copy link

mloskot commented Nov 29, 2023

@simontabor in #689 (comment)

Don't ignore the message, otherwise it'll modify the old commit message no matter what.

Using v5.42.0 I cannot confirm that ignoring commit_message still leads to that situation. I see neither any empty commits nor any non-empty commits with old messages arrive to my repo.

Copy link

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

@github-actions github-actions bot added the Status: Stale Used by stalebot to clean house label Aug 26, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 2, 2024
@atorrescogollo
Copy link

Can we remove the stale label?

This still an issue in v6.6.0. It's very annoying and it's clearly a bug. I can't figure out a reason why someone will expect that behaviour. Ignore changes makes it even more confusing since it uses previous existing commit messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
r/repository_file Status: Stale Used by stalebot to clean house Type: Bug Something isn't working as documented
Projects
None yet
7 participants