GitHub Actions Sandbox
This is test environment for GitHub Actions.
Purpose
GitHub Actions is a great tool to manage continuous integration and deployment (CI/CD), but there are some undocumented edge cases worth knowing about.
The purpose of this actions-sandbox
repository is to provide a place to test out CI/CD workflows and setups with GitHub Actions.
Problem #1: Auto Merging Pull Requests (PRs)
If you want to automatically create and merge PRs via some CI/CD process, then you will want to figure out how to automatically create those PRs, automatically approve them, and automatically merge them in a way so that existing workflows are still triggered (e.g. a deployment when a PR is merged to the main branch).
This repository has the following workflows to demonstrate this:
- test.yml - a workflow to block PR merges until it passes
- auto-approve.yml - a workflow to automatically approve PRs with the
automated
label - deploy-main.yml - a workflow which triggers on merges to the
main
branch
With these workflows in place, you can create a PR with the GitHub CLI:
gh pr create --fill --label automated
You can then configure the PR to be automatically merged once all checks pass:
gh pr merge $(gh pr view --json number --jq .number) --auto --rebase
For automatic merges using the --auto
flag, you will also need to enable auto-merge in your repository.
The GitHub CLI is automatically installed in GitHub-hosted runners, which enables you to automatically create PRs via GitHub Actions. Make sure to authenticate via a Personal Access Token to avoid breaking existing workflows.