Skip to content

Commit a4da94f

Browse files
authored
feat: change the release and staging branching model (#900)
This pull request refactors the current branching model to improve development and address several challenges associated with using staging as the default base branch for pull requests. With this update, main will serve as the base branch for pull requests, containing active development changes, while releases will be triggered upon merging pull requests into the newly created release branch.
1 parent a79993e commit a4da94f

6 files changed

Lines changed: 24 additions & 22 deletions

File tree

.github/dependabot.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ updates:
1313
prefix-development: chore
1414
include: scope
1515
open-pull-requests-limit: 13
16-
target-branch: staging
16+
target-branch: main
1717
# Add additional reviewers for PRs opened by Dependabot. For more information, see:
1818
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#reviewers
1919
# reviewers:
@@ -28,7 +28,7 @@ updates:
2828
prefix-development: chore
2929
include: scope
3030
open-pull-requests-limit: 13
31-
target-branch: staging
31+
target-branch: main
3232
# Add additional reviewers for PRs opened by Dependabot. For more information, see:
3333
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#reviewers
3434
# reviewers:

.github/workflows/_generate-rebase.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Automatically rebase one branch on top of another; usually staging on top
2-
# of main after a new package version was published.
1+
# Automatically rebase one branch on top of another; usually main on top
2+
# of release after a new package version was published.
33

44
name: Rebase branch
55
on:

.github/workflows/codeql-analysis.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ name: CodeQL
55
on:
66
push:
77
branches:
8+
- release
89
- main
9-
- staging
1010
pull_request:
1111
branches:
12+
- release
1213
- main
13-
- staging
1414
# Avoid unnecessary scans of pull requests.
1515
paths:
1616
- '**/*.py'

.github/workflows/release.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# We run checks on pushing to the specified branches.
2-
# Pushing to main also triggers a release.
2+
# Pushing to release also triggers a release.
33

44
name: Check and Release
55
on:
66
push:
77
branches:
8+
- release
89
- main
9-
- staging
1010
permissions:
1111
contents: read
1212

@@ -19,11 +19,11 @@ jobs:
1919
with:
2020
disable-pip-audit: ${{ vars.DISABLE_PIP_AUDIT == 'true' }}
2121

22-
# On pushes to the 'main' branch create a new release by bumping the version
22+
# On pushes to the 'release' branch create a new release by bumping the version
2323
# and generating a change log. That's the new bump commit and associated tag.
2424
bump:
2525
needs: check
26-
if: github.ref == 'refs/heads/main'
26+
if: github.ref == 'refs/heads/release'
2727
runs-on: ubuntu-latest
2828
permissions:
2929
contents: write
@@ -77,7 +77,7 @@ jobs:
7777
7878
# When triggered by the version bump commit, build the package and publish the release artifacts.
7979
build:
80-
if: github.ref == 'refs/heads/main' && startsWith(github.event.commits[0].message, 'bump:')
80+
if: github.ref == 'refs/heads/release' && startsWith(github.event.commits[0].message, 'bump:')
8181
uses: ./.github/workflows/_build.yaml
8282
permissions:
8383
contents: read
@@ -256,19 +256,19 @@ jobs:
256256
secrets:
257257
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
258258

259-
# After the bump commit was pushed to the main branch, rebase the staging branch
260-
# (to_head argument) on top of the new main branch (from_base argument), to keep
259+
# After the bump commit was pushed to the release branch, rebase the main branch
260+
# (to_head argument) on top of the new release branch (from_base argument), to keep
261261
# the histories of both branches in sync.
262-
rebase_staging:
262+
rebase_main:
263263
# if: ${{ false }}
264264
needs: [release]
265-
name: Rebase staging branch on main
265+
name: Rebase main branch on release
266266
uses: ./.github/workflows/_generate-rebase.yaml
267267
permissions:
268268
contents: read
269269
with:
270-
to-head: staging
271-
from-base: origin/main
270+
to-head: main
271+
from-base: origin/release
272272
git-user-name: jenstroeger
273273
git-user-email: jenstroeger@users.noreply.github.com
274274
secrets:

.github/workflows/sync-with-upstream.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
with:
3636
token: ${{ secrets.REPO_ACCESS_TOKEN }}
3737
fetch-depth: 0
38-
ref: staging
38+
ref: main
3939
path: repo
4040

4141
- name: Sync with template
@@ -84,7 +84,7 @@ jobs:
8484
git push --set-upstream origin "$BRANCH_NAME"
8585
8686
# Create the pull request.
87-
gh pr create --base staging --head "$BRANCH_NAME" --title "chore: sync with template $LATEST_VERSION" --body "This PR was generated automatically."
87+
gh pr create --base main --head "$BRANCH_NAME" --title "chore: sync with template $LATEST_VERSION" --body "This PR was generated automatically."
8888
8989
fi
9090
fi

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ If you’d like to start your own Python project from scratch, you can either co
8282

8383
- Rename the `src/package/` folder to whatever your own package’s name will be, adjust the Github Actions in `.github/workflows/`, and review the `Makefile`, `pyproject.toml`, `.pre-commit-config.yaml` files as well as the unit tests accordingly. **Note**: by default all Actions run on three different host types (Linux, MacOS, and Windows) whose [rates vary widely](https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#minute-multipliers), so make sure that you disable or budget accordingly if you’re in a private repository!
8484

85+
- A new protected `release` branch, should be created if it doesn't already exist. This branch should be configured with appropriate security policies and essential checks to ensure the integrity and stability of the release process.
86+
8587
- Adjust the content of the `pyproject.toml` file according to your needs, and make sure to fill in the project URL, maintainer and author information too. Don’t forget to reset the package’s version number in `src/package/__init__.py`.
8688

8789
- If you import packages that do not provide type hints into your new repository, then `mypy` needs to be configured accordingly: add these packages to the `pyproject.toml` file using the [`ignore_missing_imports`](https://mypy.readthedocs.io/en/stable/config_file.html#confval-ignore_missing_imports) option.
@@ -141,7 +143,7 @@ make upgrade
141143
Using the pre-commit tool and its `.pre-commit-config.yaml` configuration, the following git hooks are active in this repository:
142144

143145
- When committing code, a number of [pre-commit hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_committing_workflow_hooks) ensure that your code is formatted according to [PEP 8](https://www.python.org/dev/peps/pep-0008/) using the [`black`](https://github.com/psf/black) tool, and they’ll invoke [`flake8`](https://github.com/PyCQA/flake8) (and various plugins), [`pylint`](https://github.com/PyCQA/pylint) and [`mypy`](https://github.com/python/mypy) to check for lint and correct types. There are more checks, but those two are the important ones. You can adjust the settings for these tools in the `pyproject.toml` or `.flake8` configuration files.
144-
- The [commit message hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_committing_workflow_hooks) enforces [conventional commit messages](https://www.conventionalcommits.org/) and that, in turn, enables a _semantic release_ of this package on the Github side: upon merging changes into the `main` branch, the [release action](https://github.com/jenstroeger/python-package-template/blob/main/.github/workflows/release.yaml) uses the [Commitizen tool](https://commitizen-tools.github.io/commitizen/) to produce a [changelog](https://en.wikipedia.org/wiki/Changelog) and it computes the next version of this package and publishes a release — all based on the commit messages of a release.
146+
- The [commit message hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_committing_workflow_hooks) enforces [conventional commit messages](https://www.conventionalcommits.org/) and that, in turn, enables a _semantic release_ of this package on the Github side: upon merging changes into the `release` branch, the [release action](https://github.com/jenstroeger/python-package-template/blob/main/.github/workflows/release.yaml) uses the [Commitizen tool](https://commitizen-tools.github.io/commitizen/) to produce a [changelog](https://en.wikipedia.org/wiki/Changelog) and it computes the next version of this package and publishes a release — all based on the commit messages of a release.
145147
- Using a [pre-push hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_other_client_hooks) this package is also set up to run [`pytest`](https://github.com/pytest-dev/pytest); in addition, the [`coverage`](https://github.com/nedbat/coveragepy) plugin makes sure that _all_ of your package’s code is covered by tests and [Hypothesis](https://hypothesis.works/) is already installed to help with generating test payloads.
146148
- The [`actionlint`](https://github.com/Mateusz-Grzelinski/actionlint-py) hook is set up to lint GitHub Actions workflows. If [`shellcheck`](https://github.com/koalaman/shellcheck) is installed on the system, `actionlint` runs `shellcheck` to lint the `run` steps in GitHub Actions. Note that `shellcheck` is available on [Ubuntu GitHub Actions runners](https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md) by default.
147149

@@ -244,9 +246,9 @@ The [sync-with-upstream.yaml](https://github.com/jenstroeger/python-package-temp
244246

245247
## Versioning, publishing and changelog
246248

247-
To enable automation for [semantic versioning](https://semver.org/), package publishing, and changelog generation it is important to use meaningful [conventional commit messages](https://www.conventionalcommits.org/)! This package template already has a built-in semantic release support enabled which is set up to take care of all three of these aspects — every time changes are pushed to the `main` branch.
249+
To enable automation for [semantic versioning](https://semver.org/), package publishing, and changelog generation it is important to use meaningful [conventional commit messages](https://www.conventionalcommits.org/)! This package template already has a built-in semantic release support enabled which is set up to take care of all three of these aspects — every time changes are pushed to the `release` branch.
248250

249-
With every package release, a new `bump:` commit is pushed to the `main` branch and tagged with the package’s new version. In addition, the `staging` branch (which this repository uses to stage merged pull requests into for the next release) is rebased on top of the updated `main` branch automatically, so that subsequent pull requests can be merged while keeping a [linear history](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches#require-linear-history).
251+
With every package release, a new `bump:` commit is pushed to the `release` branch and tagged with the package’s new version. In addition, the `main` branch (which this repository uses to stage merged pull requests into for the next release) is rebased on top of the updated `release` branch automatically, so that subsequent pull requests can be merged while keeping a [linear history](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches#require-linear-history).
250252

251253
If you’d like to receive Slack notifications whenever a new release is published, follow the comments in the [Release Notification](https://github.com/jenstroeger/python-package-template/tree/main/.github/workflows/_release-notifications.yaml) Action and set up a Slack bot by following [the instructions here](https://github.com/slackapi/slack-github-action#setup-2).
252254

0 commit comments

Comments
 (0)