diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8f00e17..a317fe6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,11 +1,19 @@ name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI -on: push +on: + push: + tags: + # Order matters, the last rule that applies to a tag + # is the one that takes effect: + # https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-branches-and-tags + - '*' + # There should be no dev tags created, but to be safe, + # let's not publish them. + - '!*.dev*' env: # Change these for your project's URLs PYPI_URL: https://pypi.org/p/django-commons-best-practices - PYPI_TEST_URL: https://test.pypi.org/p/django-commons-best-practices jobs: @@ -33,7 +41,6 @@ jobs: publish-to-pypi: name: >- Publish Python 🐍 distribution 📦 to PyPI - if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes needs: - build runs-on: ubuntu-latest @@ -93,29 +100,3 @@ jobs: gh release upload '${{ github.ref_name }}' dist/** --repo '${{ github.repository }}' - - publish-to-testpypi: - name: Publish Python 🐍 distribution 📦 to TestPyPI - if: startsWith(github.ref, 'refs/tags/') # only publish to TestPyPI on tag pushes - needs: - - build - runs-on: ubuntu-latest - - environment: - name: testpypi - url: ${{ env.PYPI_TEST_URL }} - - permissions: - id-token: write # IMPORTANT: mandatory for trusted publishing - - steps: - - name: Download all the dists - uses: actions/download-artifact@v4 - with: - name: python-package-distributions - path: dist/ - - name: Publish distribution 📦 to TestPyPI - uses: pypa/gh-action-pypi-publish@release/v1.10 - with: - repository-url: https://test.pypi.org/legacy/ - skip-existing: true diff --git a/.github/workflows/test_release.yml b/.github/workflows/test_release.yml new file mode 100644 index 0000000..2846f3b --- /dev/null +++ b/.github/workflows/test_release.yml @@ -0,0 +1,82 @@ +name: Test Python 🐍 distribution 📦 to TestPyPI + +on: + workflow_dispatch: + inputs: + iteration: + description: 'A unique iteration for the run. The tag will be prefixed with test.yyyymmdd.' + type: string + required: true + default: "0" + +env: + # Change these for your project's URLs + PYPI_TEST_URL: https://test.pypi.org/p/django-commons-best-practices + # The environment key that overrides the version number + DEV_VERSION_ENV_KEY: BEST_PRACTICES_VERSION + +jobs: + + create-dev-version: + # Generate the dev version suffix based on the current date. + # Tag name: + # .dev + name: Create dev version string + runs-on: ubuntu-latest + outputs: + dev_version: ${{ steps.output-dev-version.outputs.dev_version }} + steps: + - name: Set date suffix + id: set-date + run: echo "suffix=dev$(date +%Y%m%d)${{ github.event.inputs.iteration }}" >> $GITHUB_ENV + - name: Output dev version + id: output-dev-version + run: echo "dev_version=${{ env.suffix }}" >> "$GITHUB_OUTPUT" + + build: + name: Build distribution 📦 + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + - name: Install pypa/build + run: + python3 -m pip install build --user + - name: Build a binary wheel and a source tarball + env: + DEV_VERSION: ${{needs.create-dev-version.outputs.dev_version}} + run: ${{ env.DEV_VERSION_ENV_KEY }}="${{ env.DEV_VERSION }}" python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: dist/ + + publish-to-testpypi: + name: Publish Python 🐍 distribution 📦 to TestPyPI + needs: + - build + runs-on: ubuntu-latest + + environment: + name: testpypi + url: ${{ env.PYPI_TEST_URL }} + + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1.10 + with: + repository-url: https://test.pypi.org/legacy/ + skip-existing: true diff --git a/pyproject.toml b/pyproject.toml index 28f24dc..a377f7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,12 +4,11 @@ build-backend = "setuptools.build_meta" [project] name = "django-commons-best-practices" -version = "1.1.0" +dynamic = ["version", "readme"] authors = [ { name="Tim Schilling", email="schillingt@better-simple.com" }, ] description = "A place to test things out" -readme = "README.md" requires-python = ">=3.11" classifiers = [ "Programming Language :: Python :: 3", @@ -21,6 +20,10 @@ keywords = [ "django commons", ] +[tool.setuptools.dynamic] +version = {attr = "django_commons_best_practices.__version__"} +readme = {file = ["README.md"]} + [project.urls] Homepage = "https://github.com/django-commons/best-practices" Issues = "https://github.com/django-commons/best-practices/issues" \ No newline at end of file diff --git a/src/django_commons_best_practices/__init__.py b/src/django_commons_best_practices/__init__.py index e69de29..88ed0ae 100644 --- a/src/django_commons_best_practices/__init__.py +++ b/src/django_commons_best_practices/__init__.py @@ -0,0 +1,8 @@ +__all__ = ["VERSION"] +import os + +# Support suffixing the version with a dev segment. +# This allows for building dev distributions to test +# the release process. +# See .github/workflows/test_release.yml +__version__ = VERSION = "1.1.0" + os.environ.get("BEST_PRACTICES_VERSION_DEV", "")