Git-Flow is a branching model for Git that defines a robust workflow for managing feature development, releases, and hotfixes. It is designed to streamline collaboration and ensure a clean history for software projects. The key "protected" branches in Git-Flow are:
master: The stable branch containing production-ready code. Code changes pushed to this branch trigger a release.main(conventionally referred to asdevelopin Git-Flow): The integration branch where features are merged and tested.release: Temporary branch for preparing a new production release. Code changes pushed to this branch trigger a pre-release.
These branches may not be pushed to directly - instead, a pull request targeting one of these branches must be submitted from a patch or feature branch.
Feature development:
- Create a feature branch from
main. - Develop the feature and submit a pull request targeting
mainwhen complete. - Merge the pull request once the feature is considered ready.
Releases:
- Create a release branch from
mainusing theCut releaseworkflow (triggered manually via GitHub Actions). This workflow will automatically generate a working pull request targeting master. - Merge the generated pull request once the release is considered ready. This will trigger a new release to be packaged and distributed as both GitHub and PyPI releases.
Release patches:
- Create a release fix branch from
release. - Fix the issue and submit a pull request targeting
releasewhen complete. - Merge the pull request once the patch is considered ready. This will trigger a new pre-release to be packaged and distributed as both GitHub and PyPI releases.
Master patches:
- Create a hot fix branch from
master. - Fix the issue and submit a pull request targeting
masterwhen complete. - Merge the pull request once the patch is considered ready. This will trigger a new release to be packaged and distributed as both GitHub and PyPI releases.
This repository automates Git-Flow for Python projects using GitHub Actions and custom scripts. Below is an overview of the workflows and scripts that implement Git-Flow:
- Ensures required secrets (e.g.,
MY_TOKEN,PYPI_TOKEN) are defined. Triggered manually via GitHub Actions.
- Runs tests on pull requests targeting
master,main, orreleasebranches across multiple Python versions.
- Prevents direct merges into
masterunless the source branch isrelease.
- Automatically labels pull requests based on their source and target branches.
- Synchronizes
master,main, andreleasebranches after pull request merges.
- Creates a release branch and tags a release candidate. Triggered manually via GitHub Actions.
- Tags, builds, and publishes releases to GitHub and PyPI.
- Adds labels to pull requests based on their context.
- Identifies files modified in a pull request.
- Builds distribution artifacts for a specific version.
- Publishes a release to GitHub, including artifact signatures.
- Publishes a release to PyPI using a provided token.
- Installs required tools like Homebrew, GitHub CLI, and Keychain Secrets Manager. This is intended to be used to set up a local development environment.
- Configures GitHub Actions secrets using values from the keychain or user input. This is intended to be used to set up a local development environment.
- Splits version strings into major, minor, and patch components.
- Increments version numbers based on the specified segment (major, minor, patch).
- Creates a release branch and tags a release candidate.
- Publishes distribution artifacts to PyPI.
Unfortunately, GitHub does not support workflows defined in a Git submodule, so a bit of a workaround is required. To configure a GitHub-hosted codebase to use this library, first fork this repo. Below is the GitHub CLI command to do so:
gh repo fork https://github.com/conradbzura/cicd.gitNext, clone your fork into the .github directory in the root of your Git repo:
git clone https://github.com/<you>/cicd.git .githubAs you tweak the workflow to suit your own needs, be sure to merge them into your fork for safe-keeping. Feel free to submit a pull request to this repo with any changes you feel others might find useful.
You can verify that the required secrets are accessible to the workflow by manually triggering the Validate repository workflow via GitHub Actions. Note that this check does not verify MY_TOKEN permissions. Read on for more information regarding required permissions.
The MY_TOKEN secret should be set to a personal access token with the following permissions:
contents: write
- Used in workflows like sync-branches.yaml, publish-release.yaml, and cut-release.yaml to push changes, create tags, and manage branches.
pull-requests: write
- Required in sync-branches.yaml and cut-release.yaml to create and merge pull requests programmatically.
Recommended Scope for MY_TOKEN
When creating the personal access token, ensure it has the following scopes:
-
repo: Full control of private repositories (for pushing changes, creating branches, and managing pull requests). -
workflow: To trigger and interact with GitHub Actions workflows.
The PYPI_TOKEN should be set to the PyPI authentication token used to access your PyPI project.