diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6eee471..babd4e5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -35,4 +35,4 @@ jobs: run: uv sync --dev - name: Run Tests - run: uv run ./run-tests.sh + run: uv run ./scripts/run-tests.sh diff --git a/.github/workflows/pre-release.yaml b/.github/workflows/pre-release.yaml new file mode 100644 index 0000000..f98481e --- /dev/null +++ b/.github/workflows/pre-release.yaml @@ -0,0 +1,61 @@ +name: Tag & Pre-Release + +on: + push: + branches: + - "prerelease-*" + +jobs: + build_and_pre_release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v6 + with: + enable-cache: true + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version-file: ".python-version" + + - name: Bump version + env: + PRE_RELEASE: "true" + run: | + git config user.name "Release Bot" + git config user.email "dev@beauhurst.com" + ./scripts/bump-version.sh + + - name: Get new version + id: version + run: echo "VERSION=$(uvx --from toml-cli toml get --toml-path pyproject.toml project.version)" >>$GITHUB_OUTPUT + + - name: Build binary wheel and a source tarball + run: | + uv build \ + --package pyap_beauhurst \ + --out-dir dist + + - name: Push version & tag to repository + env: + TAG_NAME: "v${{ steps.version.outputs.VERSION }}" + run: | + git push + git push origin tag "$TAG_NAME" + + - name: Create a GitHub Release + uses: softprops/action-gh-release@v2 + with: + prerelease: true + token: ${{ secrets.GITHUB_TOKEN }} + generate_release_notes: true + files: "./dist/pyap_beauhurst-*" + make_latest: false + tag_name: ${{ steps.version.outputs.VERSION }} + + - name: Publish to pypi + run: | + uv publish --token ${{ secrets.PYPI_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 212dcef..d119071 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,55 +1,81 @@ name: Tag & Release on: - push: + pull_request: + types: + - "closed" branches: - - 'main' + - "main" jobs: - build: + build_and_release: + if: github.event.pull_request.merged == true && !startsWith(github.head_ref, 'release') runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v4 + - name: Install uv + uses: astral-sh/setup-uv@v6 with: - python-version: '3.8' + enable-cache: true - - name: Install dev dependencies - run: python -m pip install --upgrade pip setuptools poetry + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version-file: ".python-version" - - name: Build binary wheel and a source tarball - run: poetry build + - name: Bump version + run: | + git config user.name "Release Bot" + git config user.email "dev@beauhurst.com" + ./scripts/bump-version.sh - - name: Get version - run: echo "VERSION=$(poetry version --short)" >>$GITHUB_OUTPUT + - name: Get new version id: version + run: echo "VERSION=$(uvx --from toml-cli toml get --toml-path pyproject.toml project.version)" >>$GITHUB_OUTPUT - - name: Tag with updated version - id: tag_version - uses: mathieudutour/github-tag-action@v6.1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - custom_tag: ${{ steps.version.outputs.VERSION }} + - name: Build binary wheel and a source tarball + run: | + uv build \ + --package pyap_beauhurst \ + --out-dir dist - - name: Create a GitHub release and upload artifact - uses: ncipollo/release-action@v1 - with: - tag: ${{ steps.tag_version.outputs.new_tag }} - name: Release ${{ steps.tag_version.outputs.new_tag }} - generateReleaseNotes: true - artifacts: './dist/pyap_beauhurst-${{ steps.tag_version.outputs.new_version }}.tar.gz,./dist/pyap_beauhurst-${{ steps.tag_version.outputs.new_version }}-py3-none-any.whl' - token: ${{ secrets.GITHUB_TOKEN }} + - name: Create release branch, push branch, tag and create PR + env: + TAG_NAME: "v${{ steps.version.outputs.VERSION }}" + BRANCH_NAME: "release-v${{ steps.version.outputs.VERSION }}" + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + + git checkout -b "$BRANCH_NAME" + git push origin "$BRANCH_NAME" + git push origin tag "$TAG_NAME" - - name: Latest tag - uses: EndBug/latest-tag@v1 + # create release PR + gh pr create \ + --title "Release $TAG_NAME" \ + --head "$(git branch --show-current)" \ + --fill \ + --base main - - name: Configure pypi credentials + - name: Merge it env: - PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} + TAG_NAME: "v${{ steps.version.outputs.VERSION }}" + GH_TOKEN: ${{ secrets.GA_PAT }} run: | - poetry config pypi-token.pypi "$PYPI_TOKEN" + # Merge PR + gh pr merge --admin --squash + + - name: Create a GitHub Release + uses: softprops/action-gh-release@v2 + with: + prerelease: false + token: ${{ secrets.GITHUB_TOKEN }} + generate_release_notes: true + files: "./dist/pyap_beauhurst-*" + make_latest: true + tag_name: ${{ steps.version.outputs.VERSION }} + - name: Publish to pypi run: | - poetry publish + uv publish --token ${{ secrets.PYPI_TOKEN }} \ No newline at end of file diff --git a/.python-version b/.python-version index 3b564fa..2c07333 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.11.12 +3.11 diff --git a/pyproject.toml b/pyproject.toml index aa2034b..f7a6671 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pyap-beauhurst" -version = "0.5.0" +version = "1999.1.1" description = "Pyap is an MIT Licensed text processing library, written in Python, for detecting and parsing addresses. Currently it supports USA, Canadian and British addresses. This is a fork maintained by Beauhurst." repository = "https://github.com/Beauhurst/pyap" requires-python = ">=3.11,<3.14" @@ -112,3 +112,38 @@ omit = ["tests/*"] [tool.coverage.report] show_missing = true + +[tool.bumpversion] +current_version = "1999.1.1" +parse = """(?x) # Verbose mode + (?P # The release part + (?:[1-9][0-9]{3})\\. # YYYY. + (?:1[0-2]|[1-9]) # MM. + ) + \\.(?P0|[1-9]\\d*) # num version number + (?: + -(?Pdev|stable) # pre_release label + (?P0|[1-9]\\d*) # pre_release version number + )? +""" +serialize = ["{release}.{num}-{pre_label}{pre_release}", "{release}.{num}"] +search = "{current_version}" +replace = "{new_version}" +tag = true +tag_name = "v{new_version}" +tag_message = "v{new_version}" +commit = true +message = "v{new_version}" + +[tool.bumpversion.parts.release] +calver_format = "{YYYY}.{MM}" + +[tool.bumpversion.parts.num] +independent = false + +[tool.bumpversion.parts.pre_label] +optional_value = "stable" +values = ["dev", "stable"] + +[[tool.bumpversion.files]] +filename = "pyproject.toml" diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh new file mode 100755 index 0000000..0eced51 --- /dev/null +++ b/scripts/bump-version.sh @@ -0,0 +1,43 @@ +#!/bin/sh +set -x -e + +# This defines the canonical way of bumping version +case "$PRE_RELEASE" in +true | 1) + echo "Bumping version for pre-release" + CURRENT_VERSION="$(uvx --from toml-cli toml get --toml-path pyproject.toml project.version)" + case "$CURRENT_VERSION" in + *dev*) + #2024.9.1-dev0 -> #2024.9.1-dev1 + uvx --from bump-my-version bump-my-version bump pre_release + ;; + *) + #2024.9.0 -> #2024.9.1-dev0 + uvx --from bump-my-version bump-my-version bump num + ;; + esac + ;; +*) + echo "Bumping version for release" + + # find if we can bump just the label + # this will fail when pre_label bumping cannot be done (i.e. it's already stable) + # this will succeed but include dev it if is bumping the calver section + POTENTIAL_NEW_VERSION="$(uvx --from bump-my-version bump-my-version show -i pre_label new_version 2>/dev/null || echo 'error')" + case "$POTENTIAL_NEW_VERSION" in + error | *dev*) + #2024.9.0 -> #2024.9.1 + uvx --from bump-my-version bump-my-version bump num --no-commit --no-tag + uvx --from bump-my-version bump-my-version bump pre_label --allow-dirty + ;; + *) + #2024.9.1-dev0 -> #2024.9.1 + uvx --from bump-my-version bump-my-version bump pre_label + ;; + esac + ;; +esac + +NEW_VERSION="$(uvx --from toml-cli toml get --toml-path pyproject.toml project.version)" + +echo "$NEW_VERSION" diff --git a/run-tests.sh b/scripts/run-tests.sh similarity index 100% rename from run-tests.sh rename to scripts/run-tests.sh