Skip to content

Conversation

@gberenice
Copy link
Member

@gberenice gberenice commented Jun 11, 2025

what

  • Automatically merge PR for trunk upgrade if all required checks have passed:
    • When you add a bot (e.g., Renovate or Trunk) to the bypass list in a GitHub ruleset, it only bypasses certain restrictions, specifically related to:
      • Push restrictions (who can push directly to a protected branch)
      • Force pushes, or bypassing update/deletion rules
    • However, a critical limitation of GitHub rulesets (as of now) is: rulesets do NOT allow bypassing pull request merge requirements, such as "Require approval from code owners" or "Require at least one approving review."
    • Thus, the bot can freely open PRs and directly push, but when merging a PR, GitHub explicitly still requires reviews if a ruleset is configured to enforce them, regardless of the bypass settings.
  • Successful run of this workflow: https://github.com/masterpointio/terraform-spacelift-automation/actions/runs/15493090377/job/43623096341

why

  • Less manual work.

references

  • N/A

Summary by CodeRabbit

  • Chores
    • Improved workflow reliability by ensuring pull requests are only merged after all required status checks have passed.

@gberenice gberenice requested a review from a team as a code owner June 11, 2025 13:58
@coderabbitai
Copy link

coderabbitai bot commented Jun 11, 2025

Walkthrough

This change updates the .github/workflows/trunk-upgrade.yaml workflow to replace the previous immediate merge step with a loop that waits for all required status checks on a pull request to pass before merging. The script now checks the status of required checks using gh pr checks and jq, and only proceeds with the merge when all checks succeed. If any check fails, the script exits with an error. The merge command now uses --squash, --delete-branch, and --admin flags, and the GitHub token environment variable is renamed from GITHUB_TOKEN to GH_TOKEN.

Possibly related PRs

Suggested reviewers

  • Gowiem
✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch fix/trunk-upgrade-automerge
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
.github/workflows/trunk-upgrade.yaml (2)

37-42: Set both GH_TOKEN and GITHUB_TOKEN for consistent auth.

Currently only GH_TOKEN is exported, but some tools or GitHub Actions expect GITHUB_TOKEN. Export both to avoid authentication issues:

 env:
-  GH_TOKEN: ${{ steps.generate-token.outputs.token }}
+  GH_TOKEN: ${{ steps.generate-token.outputs.token }}
+  GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
   PR_NUMBER: ${{ steps.trunk-upgrade.outputs.pull-request-number }}

43-62: Enhance script robustness with fail-fast and retry limits.

Introduce strict error handling and a maximum retry counter to avoid infinite loops or silent failures. Also verify jq is available:

 run: |
+  set -euo pipefail
+  attempt=0; max_attempts=20
   echo "Waiting for required status checks to pass on PR #$PR_NUMBER..."
   while true; do
+    ((attempt++))
+    if [ "$attempt" -gt "$max_attempts" ]; then
+      echo "Exceeded max retry attempts ($max_attempts). Exiting..."
+      exit 1
+    fi

     CHECKS_JSON=$(gh pr checks "$PR_NUMBER" --required --json state,bucket)
     echo "Current checks status: $CHECKS_JSON"
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 38dbed3 and b1794c1.

📒 Files selected for processing (1)
  • .github/workflows/trunk-upgrade.yaml (1 hunks)

gh pr merge "$PR_NUMBER" --squash --auto --delete-branch
echo "Waiting for required status checks to pass on PR #$PR_NUMBER..."
while true; do
CHECKS_JSON=$(gh pr checks "$PR_NUMBER" --required --json state,bucket)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this state,bucket

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oycyc these are fields used when checking the status of pull request checks using the GitHub CLI - gh pr checks.

  1. state - the current status of a check. Possible values:
    SUCCESS - The check passed successfully
    FAILURE - The check failed
    PENDING - The check is still running
    ERROR - The check encountered an error
  2. bucket - a higher-level categorization of the check's status (yeah, the naming is a bit confusing).Possible values:
    pass - The check has passed
    fail - The check has failed
    pending - The check is still running or waiting to start

More about how it "makes a decision": the workflow uses both fields to ensure that all checks have not only passed (state="SUCCESS") but are also properly categorized in the bucket before proceeding with the merge.
With this, we ensure that the PR is truly ready to be merged, as it verifies both the immediate state of the checks and their proper categorization in the GH system.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah got it!

@gberenice gberenice merged commit 0c399bc into main Jun 17, 2025
5 checks passed
@gberenice gberenice deleted the fix/trunk-upgrade-automerge branch June 17, 2025 13:16
gberenice pushed a commit that referenced this pull request Jun 17, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.8.0](v0.7.1...v0.8.0)
(2025-06-17)


### Features

* **INT-83:** dial in configs for tflint
([#39](#39))
([60c58f4](60c58f4))


### Bug Fixes

* **gha-trunk-upgrade:** wait for checks and merge with admin
([#42](#42))
([0c399bc](0c399bc))
* **gha:** use app–generated token to create release-please PRs
([#45](#45))
([a0c0d46](a0c0d46))
* linter configs to root folder
([#44](#44))
([7aacf9f](7aacf9f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: masterpointbot[bot] <177651640+masterpointbot[bot]@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

3 participants