diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index b17d37a..1945e21 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -5,7 +5,7 @@ name: Python application CI on: push: - branches: [ "main" ] + branches: [ "*" ] pull_request: branches: [ "main" ] @@ -14,9 +14,7 @@ permissions: jobs: check: - runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 - name: Install poetry @@ -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 @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 5e9790a..e69ecd0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "MIT" @@ -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"