Skip to content

Commit

Permalink
Add release automation
Browse files Browse the repository at this point in the history
* Create release branch from main and bump minor version
* Release from a release branch and bump patch version

[noissue]
  • Loading branch information
mdellweg committed Jul 18, 2023
1 parent cf90e74 commit 79a6b18
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 57 deletions.
17 changes: 13 additions & 4 deletions .ci/scripts/collect_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@
# Read Towncrier settings
tc_settings = toml.load("pyproject.toml")["tool"]["towncrier"]

CHANGELOG_FILE = tc_settings["filename"]
START_STRING = tc_settings["start_string"]
TITLE_FORMAT = tc_settings["title_format"]
CHANGELOG_FILE = tc_settings.get("filename", "NEWS.rst")
START_STRING = tc_settings.get(
"start_string",
"<!-- towncrier release notes start -->\n"
if CHANGELOG_FILE.endswith(".md")
else ".. towncrier release notes start\n",
)
TITLE_FORMAT = tc_settings.get("title_format", "{name} {version} ({project_date})")


NAME_REGEX = r".*"
VERSION_REGEX = r"([0-9]+\.[0-9]+\.[0-9][0-9ab]*)"
DATE_REGEX = r"[0-9]{4}-[0-9]{2}-[0-9]{2}"
TITLE_REGEX = (
"("
+ re.escape(TITLE_FORMAT.format(version="VERSION_REGEX", project_date="DATE_REGEX"))
+ re.escape(
TITLE_FORMAT.format(name="NAME_REGEX", version="VERSION_REGEX", project_date="DATE_REGEX")
)
.replace("NAME_REGEX", NAME_REGEX)
.replace("VERSION_REGEX", VERSION_REGEX)
.replace("DATE_REGEX", DATE_REGEX)
+ ")"
Expand Down
28 changes: 28 additions & 0 deletions .ci/scripts/create_release_branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -eu -o pipefail

BRANCH="$(git branch --show-current)"

if ! [[ "${BRANCH}" = "main" ]]
then
echo ERROR: This is not the main branch!
exit 1
fi

NEW_BRANCH="$(bump2version --dry-run --list release | sed -Ene 's/^new_version=([[:digit:]]+\.[[:digit:]]+)\..*$/\1/p')"

if [[ -z "${NEW_BRANCH}" ]]
then
echo ERROR: Could not parse new version.
exit 1
fi

git branch "${NEW_BRANCH}"

# Clean changelog snippets.
find CHANGES/ \( -name "*.feature" -o -name "*.bugfix" -o -name "*.doc" -o -name "*.translation" -o -name "*.devel" -o -name "*.misc" \) -exec git rm -f \{\} +

bumpversion minor --commit --message $'Bump version to {new_version}\n\n[noissue]' --allow-dirty

git push origin "${NEW_BRANCH}"
26 changes: 26 additions & 0 deletions .ci/scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -eu -o pipefail

BRANCH=$(git branch --show-current)

if ! [[ "${BRANCH}" =~ ^[0-9]+\.[0-9]+$ ]]
then
echo ERROR: This is not a release branch!
exit 1
fi

NEW_VERSION="$(bump2version --dry-run --list release | sed -ne 's/^new_version=//p')"
echo "Release ${NEW_VERSION}"

if ! [[ "${NEW_VERSION}" == "${BRANCH}"* ]]
then
echo ERROR: Version does not match release branch
exit 1
fi

towncrier --yes
bumpversion release --commit --message "Release {new_version}" --tag --tag-name "{new_version}" --tag-message "Release {new_version}" --allow-dirty
bumpversion patch --commit

git push upstream "${BRANCH}" "${NEW_VERSION}"
1 change: 1 addition & 0 deletions .github/workflows/changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ jobs:
with:
token: ${{ secrets.RELEASE_TOKEN }}
title: "Update Changelog"
body: ""
branch: "update_changes"
delete-branch: true
20 changes: 10 additions & 10 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: python
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: python

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:python"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:python"
3 changes: 1 addition & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
with:
python-version: ${{ matrix.python }}
- name: Install python dependencies
run: |
pip install -r lint_requirements.txt
run: pip install -r lint_requirements.txt
- name: Lint code
run: make lint
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
codeql:
uses: "./.github/workflows/codeql.yml"
collect_changes:
uses: "./.github/workflows/changes.yml"
uses: "./.github/workflows/collect_changes.yml"
secrets: inherit
6 changes: 2 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
git fetch --prune --unshallow
- run: git fetch --prune --unshallow
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install python dependencies
run: |
pip install toml pygithub
run: pip install toml pygithub
- name: Check commit message
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: pulp-cli Publish

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]"

jobs:
publish-pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: pulp
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
cd pulp-glue
python setup.py sdist bdist_wheel
twine upload dist/*
cd ..
python setup.py sdist bdist_wheel
twine upload dist/*
publish-docs:
name: Publish docs
needs: publish-pypi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run publish docs script
env:
PULP_DOCS_KEY: ${{ secrets.PULP_DOCS_KEY }}
run: |
.ci/scripts/publish_docs.sh "${GITHUB_REF##*/}"
54 changes: 18 additions & 36 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,25 @@
name: pulp-cli Release

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]"
workflow_dispatch

jobs:
publish-pypi:
name: Publish to PyPI
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: pulp
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
cd pulp-glue
python setup.py sdist bdist_wheel
twine upload dist/*
cd ..
python setup.py sdist bdist_wheel
twine upload dist/*
publish-docs:
name: Publish docs
needs: publish-pypi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run publish docs script
env:
PULP_DOCS_KEY: ${{ secrets.PULP_DOCS_KEY }}
run: .ci/scripts/publish_docs.sh "${GITHUB_REF##*/}"
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install bump2version towncrier
- name: Setup git
run: |
git config user.name pulpbot
git config user.email [email protected]
- name: Release
run: .ci/scripts/release.sh
30 changes: 30 additions & 0 deletions .github/workflows/release_branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Create Release Branch
on:
workflow_dispatch:

jobs:
create-release-branch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Setup git
run: |
git config user.name pulpbot
git config user.email [email protected]
- name: Install python dependencies
run: pip install bump2version
- name: Create Release Branch
run: .ci/scripts/create_release_branch.sh
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.RELEASE_TOKEN }}
title: "Bump dev-version"
body: ""
branch: "bump_version"
delete-branch: true
18 changes: 18 additions & 0 deletions releasing.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
# Releasing (for internal use)
## New method (experimental)
### Create a new Y-Release Branch

1. Trigger the "Create Release Branch" workflow on the "main" branch.
1. Watch for the "Bump Version" PR, approve and merge it.

- Verify that it deletes all the changes snippets present on the new release branch.

### Release from a Release Branch
1. Trigger the "pulp-cli Release" workflow on the corresponding release branch.
1. Lean back and see the magic happen.
1. Wait for the "pulp-cli Publish" workflow to succeed.
1. Verify that a new version appeared on PyPI.
1. Verify that the docs have been updated.
1. [only Y-releases] Announce the release at https://discourse.pulpproject.org/c/announcements/6.
1. Look for the "Update Changelog" PR, approve and merge it.

## Manual method

1. Install `bumpversion` and `towncrier` into a virtualenv or select one if it exists.
1. Run `bumpversion release`.
Expand Down

0 comments on commit 79a6b18

Please sign in to comment.