From 186bcd845435b6a09a8467224f5cba0db111f0e2 Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Fri, 25 Aug 2023 09:29:15 +0200 Subject: [PATCH] chore: migrate to python-semantic-release8 Signed-off-by: Jan Kowalleck --- .github/workflows/release.yml | 103 ++++++++++++++++++++++++++++++++++ pyproject.toml | 7 +-- 2 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..2c75fe51 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,103 @@ +name: Release + +on: + #push: + # branches: [ 'main' ] + workflow_dispatch: + release_force: + # see https://python-semantic-release.readthedocs.io/en/latest/github-action.html#command-line-options + description: 'force release be one of: [major | minor | patch]' + type: choice + options: + - major + - minor + - patch + default: "" + required: false + prerelease_token: + description: 'The "prerelease identifier" to use as a prefix for the "prerelease" part of a semver. Like the rc in `1.2.0-rc.8`.' + type: choice + options: + - rc + - beta + - alpha + default: rc + required: false + prerelease: + description: "Is a pre-release" + type: boolean + default: false + required: false + +concurrency: + group: deploy + cancel-in-progress: false # prevent hickups with semantic-release + +env: + PYTHON_VERSION_DEFAULT: "3.11" + POETRY_VERSION: "1.4.1" + +jobs: + release: + # https://github.community/t/how-do-i-specify-job-dependency-running-in-another-workflow/16482 + # limit this to being run on regular commits, not the commits that semantic-release will create + if: github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'chore(release):') + runs-on: ubuntu-latest + concurrency: release + permissions: + # NOTE: this enables trusted publishing. + # See https://github.com/pypa/gh-action-pypi-publish/tree/release/v1#trusted-publishing + # and https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/ + id-token: write + contents: write + steps: + - name: Checkout code + # see https://github.com/actions/checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup python + # see https://github.com/actions/setup-python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION_DEFAULT }} + architecture: 'x64' + - name: Install and configure Poetry + # See https://github.com/marketplace/actions/install-poetry-action + uses: snok/install-poetry@v1 + with: + version: ${{ env.POETRY_VERSION }} + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true + - name: Install dependencies + run: poetry install --no-root + - name: View poetry version + run: poetry --version + + - name: Python Semantic Release + id: release + # see https://python-semantic-release.readthedocs.io/en/latest/automatic-releases/github-actions.html + # see https://github.com/python-semantic-release/python-semantic-release + uses: python-semantic-release/python-semantic-release@v8.0.7 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + force: ${{ github.event.inputs.release_force }} + prerelease: ${{ github.event.inputs.prerelease && "true" || "false" }} + prerelease_token: ${{ github.event.inputs.prerelease_token }} + + - name: Publish package distributions to PyPI + if: steps.release.outputs.released == 'true' + # see https://github.com/pypa/gh-action-pypi-publish + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_TOKEN }} + + - name: Publish package distributions to GitHub Releases + if: steps.release.outputs.released == 'true' + # see https://github.com/python-semantic-release/upload-to-gh-release + uses: python-semantic-release/upload-to-gh-release@main + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ steps.release.outputs.tag }} diff --git a/pyproject.toml b/pyproject.toml index 370c4b0b..aa25c1e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -71,10 +71,7 @@ requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.semantic_release] -version_variable = [ - "pyproject.toml:version" -] +version_toml = ["pyproject.toml:tool.poetry.version"] branch = "main" -upload_to_pypi = true -upload_to_release = true +upload_to_vcs_release = true build_command = "pip install poetry && poetry build"