From 2a8ec136c3ee2d8261169216e7bc66ead3141e49 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 17 Sep 2025 13:46:29 +0100 Subject: [PATCH] Split test release workflow from actual --- .github/workflows/release.yml | 41 +++--------- .github/workflows/test_release.yml | 103 +++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/test_release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f13b3a7d8..733912ad9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,10 +1,18 @@ -name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI +name: Publish Python 🐍 distribution 📦 to PyPI -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: PYPI_URL: https://pypi.org/p/djangorestframework - PYPI_TEST_URL: https://test.pypi.org/p/djangorestframework jobs: @@ -32,7 +40,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 @@ -92,29 +99,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 Test PyPI 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@v5 - with: - name: python-package-distributions - path: dist/ - - name: Publish distribution 📦 to TestPyPI - uses: pypa/gh-action-pypi-publish@release/v1.13 - 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 000000000..3e53d4f62 --- /dev/null +++ b/.github/workflows/test_release.yml @@ -0,0 +1,103 @@ +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: "12 3 2 * *" + push: + tags: + - '*' + +env: + PYPI_TEST_URL: https://test.pypi.org/p/djangorestframework + # The environment key that overrides the version number + DEV_VERSION_ENV_KEY: BEST_PRACTICES_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 + - 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=${{ env.suffix }}${{ env.iteration }}" >> "$GITHUB_OUTPUT" + fi + + build: + name: Build distribution 📦 + needs: + - create-dev-version + 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.12 + with: + repository-url: https://test.pypi.org/legacy/ + skip-existing: true