Skip to content

Add staging branch automation to the github generator - #231

Draft
kylesmile wants to merge 2 commits into
masterfrom
schema-merge-driver
Draft

kylesmile wants to merge 2 commits into
masterfrom
schema-merge-driver

Conversation

@kylesmile

@kylesmile kylesmile commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Why?

Two pull requests labeled Staging that each add a migration both change the define(version: …) line in db/schema.rb. When the staging branch is rebuilt, that conflict drops the second pull request even though the fix is obvious: keep the newest version.

The fix and the rebuild job live in RoleModel/actions#50: staging-auto-merge takes a merge-drivers input with a built-in railsschema driver, and the maintain-staging.yml reusable workflow uses it by default. This PR has the github generator add a short caller of that workflow, so new apps start with staging automation.

What Changed

  • maintain-staging.yml calls RoleModel/actions/.github/workflows/maintain-staging.yml at the same major version as CI. It grants the permissions the reusable job declares and passes the AUTOMATED_COMMITS_KEY deploy key, so the push to staging starts deploy-staging.yml.
  • --primary-branch option (default main) for the branch staging is rebuilt from
  • Specs for the generated caller and the --primary-branch option

Pre-merge checklist

Notes

Please don't commit version changes within your PR. Versioning, releasing, and changelog entries are managed through the Release workflow.

Screenshots

No UI changes.

🤖 Generated with Claude Code

@OutlawAndy OutlawAndy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking this up. The db/schema.rb version conflict has dropped PRs from staging more than once, and the driver's approach of taking the newest version and then running a normal git merge-file is right. I'd like to move most of it into RoleModel/actions instead of generating it into every app, so it's maintained in one place and existing apps get it too.

The merge driver goes in staging-auto-merge. The action already runs the git merge --squash that hits the conflict, so it can register the driver itself before merging: write db/schema.rb merge=railsschema to .git/info/attributes and set merge.railsschema.driver to a script that ships with the action. Neither of those is committed, and --squash still uses the driver. I tested this in a scratch repo: the same two-migration conflict fails without the driver and merges cleanly to the newest version with it. That means:

  • apps don't get bin/schema-merge, bin/setup-schema-merge or a .gitattributes entry
  • every app already using staging-auto-merge gets the fix with its next actions version bump, with no regenerating
  • your real-git specs move to the action's tests/, next to the code they test

The rebuild job becomes a reusable workflow: RoleModel/actions/.github/workflows/maintain-staging.yml, like rails-ci.yml and release.yml. The trigger filter, concurrency, checkout with the deploy key and the action call all go there. Each app keeps only a short caller, which is the part the github generator should add:

name: Maintain Staging Branch

on:
  pull_request:
    types: [labeled, unlabeled, closed, synchronize]

jobs:
  staging:
    uses: RoleModel/actions/.github/workflows/maintain-staging.yml@v3
    permissions:
      contents: write
      issues: write
      pull-requests: write
    with:
      primary-branch: main
    secrets:
      deploy-key: ${{ secrets.AUTOMATED_COMMITS_KEY }}

The caller has to grant every permission the reusable job declares. If it grants less, the run fails at startup with no logs.

I'd drop running the driver locally. The conflict comes from rebuilding staging, which only happens in CI. If someone hits it locally, they can add it then.

That leaves this PR with the caller template, the --primary-branch option, and the README notes on the Staging label, the staging branch and the AUTOMATED_COMMITS_KEY secret, which are all good as they are. Happy to pair on the actions side if that helps.

@kylesmile

Copy link
Copy Markdown
Contributor Author

@OutlawAndy Yes, I think it makes sense to move some things up to the actions repo. I want to be careful about introducing Rails-specific steps to the staging-auto-merge action, but I have an idea of how to manage that. I'll make a PR in RoleModel/actions, and update this one accordingly.

@kylesmile kylesmile changed the title Add staging branch automation and schema.rb merge driver Add staging branch automation to the github generator Dec 2, 2026
kylesmile and others added 2 commits December 2, 2026 14:47
…nerator

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The schema.rb merge driver and the staging rebuild job now live in
RoleModel/actions, so the generator no longer adds bin/schema-merge,
bin/setup-schema-merge or a .gitattributes entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kylesmile
kylesmile force-pushed the schema-merge-driver branch from d8f2982 to a065de4 Compare December 2, 2026 20:48
@kylesmile

Copy link
Copy Markdown
Contributor Author

@OutlawAndy Updated this PR, and opened RoleModel/actions#50. I still need to go through both for cleanup before they're entirely ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants