diff --git a/.ci/scripts/collect_changes.py b/.ci/scripts/collect_changes.py index ab5d04523..d11b52874 100755 --- a/.ci/scripts/collect_changes.py +++ b/.ci/scripts/collect_changes.py @@ -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", + "\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) + ")" diff --git a/.ci/scripts/create_release_branch.sh b/.ci/scripts/create_release_branch.sh new file mode 100755 index 000000000..c76bd625f --- /dev/null +++ b/.ci/scripts/create_release_branch.sh @@ -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}" diff --git a/.ci/scripts/release.sh b/.ci/scripts/release.sh new file mode 100755 index 000000000..f81ddded6 --- /dev/null +++ b/.ci/scripts/release.sh @@ -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}" diff --git a/.github/workflows/changes.yml b/.github/workflows/changes.yml index 146ca4023..fffb44c86 100644 --- a/.github/workflows/changes.yml +++ b/.github/workflows/changes.yml @@ -27,5 +27,6 @@ jobs: with: token: ${{ secrets.RELEASE_TOKEN }} title: "Update Changelog" + body: "" branch: "update_changes" delete-branch: true diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 17b32fb92..152694ff3 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -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" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f82a15341..786fb0f65 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index ffbc67731..6aafe12d0 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -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 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 14524f743..29f534389 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -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 }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..e1554f24d --- /dev/null +++ b/.github/workflows/publish.yml @@ -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##*/}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4f0eb2d1f..6937c98db 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 pulp-infra@redhat.com + - name: Release + run: .ci/scripts/release.sh diff --git a/.github/workflows/release_branch.yml b/.github/workflows/release_branch.yml new file mode 100644 index 000000000..b090301a1 --- /dev/null +++ b/.github/workflows/release_branch.yml @@ -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 pulp-infra@redhat.com + - 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 diff --git a/releasing.md b/releasing.md index 855a3f1d6..271384770 100644 --- a/releasing.md +++ b/releasing.md @@ -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`.