diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ff9ac93 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,106 @@ +name: Publish Python 🐍 distribution 📦 to PyPI + +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*' + +permissions: {} + +env: + # Change these for your project's URLs + PYPI_URL: https://pypi.org/p/django-salmon + +jobs: + + build: + name: Build distribution 📦 + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - name: Set up Python + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + 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 + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: python-package-distributions + path: dist/ + + publish-to-pypi: + name: >- + Publish Python 🐍 distribution 📦 to PyPI + needs: + - build + runs-on: ubuntu-latest + environment: + name: pypi + url: ${{ env.PYPI_URL }} + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + steps: + - name: Download all the dists + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0 + + github-release: + name: >- + Sign the Python 🐍 distribution 📦 with Sigstore + and upload them to GitHub Release + needs: + - publish-to-pypi + runs-on: ubuntu-latest + + permissions: + contents: write # IMPORTANT: mandatory for making GitHub Releases + id-token: write # IMPORTANT: mandatory for sigstore + + steps: + - name: Download all the dists + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: python-package-distributions + path: dist/ + - name: Sign the dists with Sigstore + uses: sigstore/gh-action-sigstore-python@04cffa1d795717b140764e8b640de88853c92acc # v3.3.0 + with: + inputs: >- + ./dist/*.tar.gz + ./dist/*.whl + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + run: >- + gh release create + "${GITHUB_REF_NAME}" + --repo '${{ github.repository }}' + --notes "" + - name: Upload artifact signatures to GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + # Upload to GitHub Release using the `gh` CLI. + # `dist/` contains the built packages, and the + # sigstore-produced signatures and certificates. + run: >- + gh release upload + "${GITHUB_REF_NAME}" dist/** + --repo '${{ github.repository }}' diff --git a/.github/workflows/test_release.yml b/.github/workflows/test_release.yml new file mode 100644 index 0000000..cdc25eb --- /dev/null +++ b/.github/workflows/test_release.yml @@ -0,0 +1,110 @@ +name: Test Python 🐍 distribution 📦 to TestPyPI + +on: + workflow_dispatch: + inputs: + iteration: + description: 'A unique iteration for the run. The tag will be suffixed with .devyyyymmdd' + type: string + required: true + default: "0" + schedule: + # Run the second day of every month. + - cron: "10 3 2 * *" + push: + tags: + - '*' + +permissions: {} + +env: + # Change these for your project's URLs + PYPI_TEST_URL: https://test.pypi.org/p/django-salmon + # The environment key that overrides the version number + DEV_VERSION_ENV_KEY: DJSALMON_VERSION_DEV + +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_ENV + - name: Determine Iteration Value + id: set-iteration + # If the action is running on a schedule, default iteration to 0 + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + echo "iteration=${GITHUB_EVENT_INPUTS_ITERATION}" >> $GITHUB_ENV + else + echo "iteration=0" >> $GITHUB_ENV + fi + env: + GITHUB_EVENT_INPUTS_ITERATION: ${{ github.event.inputs.iteration }} + - name: Output dev version + id: output-dev-version + # Don't output a dev version if the push was for a tag. + run: | + if [[ "${{ startsWith(github.ref, 'refs/tags') }}" == "true" ]]; then + echo "dev_version=" >> "$GITHUB_OUTPUT" + else + echo "dev_version=${SUFFIX}${ITERATION}" >> "$GITHUB_OUTPUT" + fi + + build: + name: Build distribution 📦 + needs: + - create-dev-version + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - name: Set up Python + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + 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 }}="${DEV_VERSION}" python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + 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@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to TestPyPI + uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0 + with: + repository-url: https://test.pypi.org/legacy/ + skip-existing: true diff --git a/src/django_salmon/__init__.py b/src/django_salmon/__init__.py index d5f6494..a81d689 100644 --- a/src/django_salmon/__init__.py +++ b/src/django_salmon/__init__.py @@ -1,5 +1,12 @@ from __future__ import annotations +import os + from .registry import registry __all__ = ["registry"] +# 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 = "0.1.0" + os.environ.get("DJSALMON_VERSION_DEV", "")