Skip to content

Commit

Permalink
Enable dynamic versioning and publish to PyPI
Browse files Browse the repository at this point in the history
  • Loading branch information
jegork committed Jun 7, 2024
1 parent 7785d5a commit 25511ac
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 34 deletions.
64 changes: 34 additions & 30 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Python application CI

on:
push:
branches: [ "main" ]
branches: [ "*" ]
pull_request:
branches: [ "main" ]

Expand All @@ -14,9 +14,7 @@ permissions:

jobs:
check:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Install poetry
Expand All @@ -37,16 +35,14 @@ jobs:
run: |
poetry run pytest
publish:
build:
name: "Build distribution"
needs: check
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5
Expand All @@ -55,28 +51,36 @@ jobs:
python-version: '3.12'
cache: 'poetry'
- name: Install dependencies
run: poetry install
- name: Build
run: poetry build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Create release
run: |
poetry install
- name: Get version from pyproject.toml
id: get_version
run: |
VERSION=$(poetry version -s)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Check if tag exists
id: check_tag
run: |
if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then
echo "tag_exists=true" >> $GITHUB_OUTPUT
echo "Version ${{ env.VERSION }} already exists."
else
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "Version ${{ env.VERSION }} does not exists."
fi
- name: Create tag and release
if: steps.check_tag.outputs.tag_exists == 'false'
run: |
git tag "v${{ env.VERSION }}"
git push origin "v${{ env.VERSION }}"
gh release create "v${{ env.VERSION }}" --title "v${{ env.VERSION }}" --notes "Release version ${{ env.VERSION }}"
gh release create "v${{ env.VERSION }}" --title "v${{ env.VERSION }}" --generate-notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-to-pypi:
name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/ultra-cache
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[build-system]
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
build-backend = "poetry_dynamic_versioning.backend"

[tool.poetry]
name = "ultra-cache"
version = "0.1.1"
version = "0.0.0"
description = "Simple and extensible caching for FastAPI requests"
authors = ["Jegor Kitskerkin <[email protected]>"]
license = "MIT"
Expand All @@ -20,6 +24,6 @@ freezegun = "^1.5.0"
pytest-mock = "^3.14.0"
httpx = "^0.27.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"

0 comments on commit 25511ac

Please sign in to comment.