A GitHub Actions boilerplate for a UI-managed, "one-click" production deployment flow.
This template automates environment synchronization across main, staging, and production. It eliminates manual branch management, prevents environment drift, and generates a dynamic changelog for every production release.
- Forward-Sync: Commits to
mainautomatically merge intostaging. - Rolling Production PR: Commits to
stagingautomatically create or update a persistent Pull Request targetingproduction. - Dynamic Changelog: The Rolling PR automatically lists pending commits, authors, and emails.
- Hotfix Back-Sync: Any direct merges or hotfixes applied to
productioncascade back down tostagingandmain. - Auto-Initialization: Required branches are generated automatically on your first run.
- Click Use this template to create a new repository.
- Ensure you have GitHub Actions enabled in your repository settings.
To prevent GitHub Actions from blocking cascading workflows (infinite loop protection), you must use a Personal Access Token (PAT) instead of the default GITHUB_TOKEN.
- Go to your GitHub Developer Settings > Personal Access Tokens.
- Generate a new token with
reposcope. - Go to your repository Settings > Secrets and variables > Actions.
- Create a new repository secret named
DEPLOY_PATand paste your token.
You have two ways to generate the staging and production branches:
- Manual Bootstrap: Go to the Actions tab, select the
🛠️ Bootstrap Environmentsworkflow, and click Run workflow. - Zero-Touch: Simply push your first commit to
main. Theforward-syncaction will detect missing branches and create them automatically.
For this flow to work securely, apply these rules in Settings > Branches:
staging: Require status checks to pass before merging.production: Require a Pull Request before merging. Restrict who can push to matching branches (e.g., Tech Leads only). Allow specified actors to bypass pull request requirements for emergency hotfixes.
- Push to
main(Feature Merged)- Action:
forward-sync.yml - Result: Code is automatically merged into
staging.
- Action:
- Push to
staging(QA Ready)- Action:
rolling-pr.yml - Result: A PR to
productionis created or updated. The title includes today's date, and the body lists all pending commits.
- Action:
- Merge to
production(Release)- Action:
back-sync.yml - Result: The release commit (or any emergency hotfixes made directly to production) is merged back into
stagingandmainto prevent drift.
- Action:
Scenario: Three features are in the Rolling PR, but one fails QA and needs to be removed before deploying to production.
- Locate the merged Pull Request for the broken feature on
main. - Click the Revert button in the GitHub UI.
- The
forward-syncaction will automatically merge this revert commit intostaging. - The Rolling PR to
productionwill update automatically, stripping out the broken code while leaving the good features intact. - Merge the Rolling PR safely.
Scenario: A back-sync or forward-sync fails due to a complex merge conflict.
- The GitHub Action will fail and notify the repository owner.
- Check out the target branch locally.
- Merge the source branch, resolve the conflicts, and push.
- The automation will resume standard operation on the next trigger.
If GitHub Actions are down or you need to bypass the flow, add [skip ci] to your commit message to prevent the workflows from running, then handle the merges manually via the Git CLI.