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

Auto-merge fails when GitHub checks required for merge #3209

Closed
tpolekhin opened this issue Mar 15, 2023 · 1 comment
Closed

Auto-merge fails when GitHub checks required for merge #3209

tpolekhin opened this issue Mar 15, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@tpolekhin
Copy link
Contributor

tpolekhin commented Mar 15, 2023

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Overview of the Issue

Atlantis auto merge after apply fails when GitHub repo is configured to require atlantis/apply check to pass before allowing merge. Seems like a race condition when Atlantis tries to merge PR before GitHub realises that atlantis/apply check has passed and unblocks merge.

Screenshot 2023-03-15 at 14 23 49

Reproduction Steps

  1. Enable auto merge in Atlantis server config ATLANTIS_AUTOMERGE=true
  2. Set apply_requirements: [approved, undiverged] in server side config
  3. Set GitHub branch protection rules to require atlantis/apply check to pass before allowing merge

Screenshot 2023-03-15 at 14 20 57

5. Run standard Atlantis workflow for pull request

Logs

Logs
{"level":"info","ts":"2023-03-15T13:04:45.139Z","caller":"events/events_controller.go:545","msg":"parsed comment as command=\"apply\" verbose=false dir=\"\" workspace=\"\" project=\"\" flags=\"\"","json":{"gh-request-id":"X-Github-Delivery=f4627360-c331-11ed-840a-b249a2a93464"}}
{"level":"info","ts":"2023-03-15T13:04:47.272Z","caller":"terraform/terraform_client.go:361","msg":"Detected module requires version: 1.4.0","json":{"repo":"<redacted>/terraform-infrastructure","pull":"6"}}
{"level":"info","ts":"2023-03-15T13:04:47.538Z","caller":"runtime/apply_step_runner.go:39","msg":"starting apply","json":{"repo":"<redacted>/terraform-infrastructure","pull":"6"}}
{"level":"info","ts":"2023-03-15T13:04:53.582Z","caller":"models/shell_command_runner.go:156","msg":"successfully ran \"/home/atlantis/.atlantis/bin/terraform1.4.0 apply -input=false \\\"/home/atlantis/.atlantis/repos/<redacted>/terraform-infrastructure/6/default/<redacted>/<redacted>-default.tfplan\\\"\" in \"/home/atlantis/.atlantis/repos/<redacted>/terraform-infrastructure/6/default/<redacted>\"","json":{"repo":"<redacted>/terraform-infrastructure","pull":"6"}}
{"level":"info","ts":"2023-03-15T13:04:53.582Z","caller":"runtime/apply_step_runner.go:58","msg":"apply successful, deleting planfile","json":{"repo":"<redacted>/terraform-infrastructure","pull":"6"}}
{"level":"info","ts":"2023-03-15T13:04:53.832Z","caller":"events/instrumented_project_command_runner.go:87","msg":"apply success. output available at: https://github.com/<redacted>/terraform-infrastructure/pull/6","json":{"repo":"<redacted>/terraform-infrastructure","pull":"6"}}
{"level":"info","ts":"2023-03-15T13:04:56.578Z","caller":"events/automerger.go:32","msg":"automerging pull request","json":{"repo":"<redacted>/terraform-infrastructure","pull":"6"}}
{"level":"error","ts":"2023-03-15T13:04:57.450Z","caller":"vcs/instrumented_client.go:231","msg":"Unable to merge pull, error: merging pull request: PUT https://api.github.com/repos/<redacted>/terraform-infrastructure/pulls/6/merge: 405 This branch must not contain merge commits. []","json":{"pull-num":6},"stacktrace":"github.com/runatlantis/atlantis/server/events/vcs.(*InstrumentedClient).MergePull\n\tgithub.com/runatlantis/atlantis/server/events/vcs/instrumented_client.go:231\ngithub.com/runatlantis/atlantis/server/events/vcs.(*ClientProxy).MergePull\n\tgithub.com/runatlantis/atlantis/server/events/vcs/proxy.go:84\ngithub.com/runatlantis/atlantis/server/events.(*AutoMerger).automerge\n\tgithub.com/runatlantis/atlantis/server/events/automerger.go:35\ngithub.com/runatlantis/atlantis/server/events.(*ApplyCommandRunner).Run\n\tgithub.com/runatlantis/atlantis/server/events/apply_command_runner.go:183\ngithub.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\tgithub.com/runatlantis/atlantis/server/events/command_runner.go:296"}

Environment details

  • Atlantis version: v0.23.2
  • Deployment method: GCE tf module
  • Atlantis flags:
  env_vars = {
    GOOGLE_IMPERSONATE_SERVICE_ACCOUNT = var.impersonate_service_account
    ATLANTIS_AUTOMERGE                 = true
    ATLANTIS_WRITE_GIT_CREDS           = true
    ATLANTIS_REPO_ALLOWLIST            = "github.com/<redacted>/terraform-infrastructure"
    ATLANTIS_ATLANTIS_URL              = "https://${var.domain}"
    ATLANTIS_REPO_CONFIG_JSON          = jsonencode(yamldecode(file("${path.module}/server-atlantis.yaml")))
  }
  • Atlantis server-side config file:
repos:
  - id: github.com/<redacted>/terraform-infrastructure
    branch: /^main$/
    plan_requirements: [undiverged]
    apply_requirements: [approved, undiverged]
    import_requirements: [approved, mergeable, undiverged]
    allow_custom_workflows: false
    delete_source_branch_on_merge: true
  • Repo atlantis.yaml file:
version: 3
parallel_plan: false
parallel_apply: false
projects:
  - name: project1
    branch: /^main$/
    dir: project1
  - name: project2
    branch: /^main$/
    dir: project2

Additional Context

@tpolekhin tpolekhin added the bug Something isn't working label Mar 15, 2023
@tpolekhin
Copy link
Contributor Author

Sorry, duplicate of #1176

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant