From 9cf8322c900970c783023246fe3e7fcacd08bea6 Mon Sep 17 00:00:00 2001 From: Stephen Sorriaux Date: Mon, 6 Feb 2023 15:32:43 -0500 Subject: [PATCH] chore: better handle packaging Upload to TestPyPI after some sucessful tests Only keep 2 GA workflows, with all the funny things it means --- .github/workflows/package-without-publish.yml | 42 -------------- .github/workflows/release.yml | 55 ++++++++++++++++--- .github/workflows/testing.yml | 24 +++++++- 3 files changed, 70 insertions(+), 51 deletions(-) delete mode 100644 .github/workflows/package-without-publish.yml diff --git a/.github/workflows/package-without-publish.yml b/.github/workflows/package-without-publish.yml deleted file mode 100644 index cf69f076..00000000 --- a/.github/workflows/package-without-publish.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Kazoo Awesome Packaging Test - -on: - push: - branches: - - master - - release/* - pull_request: - branches: - - master - - release/* - -jobs: - package-without-publish: - name: Testing packaging WITHOUT publishing to Pypi - runs-on: ubuntu-latest - steps: - - name: Handle the code - uses: actions/checkout@v2 - - - name: Set up Python 3.10 - uses: actions/setup-python@v2 - with: - python-version: "3.10" - - - name: Install pypa/build - run: >- - python -m - pip install - build - --user - - - name: Build a binary wheel and a source tarball - run: >- - python -m - build - -C--global-option=egg_info - -C--global-option=--tag-build="" - --sdist - --wheel - --outdir dist/ - . diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a2245812..c4fba20e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,22 +1,56 @@ name: Kazoo Awesome Release on: + workflow_call: + inputs: + TAG_BUILD: + description: 'The egg info tag build (will be appended to `kazoo.version` value)' + default: "" + required: false + type: string + USE_TEST_PYPI: + description: 'Whether to the use the TestPyPI repository or not' + default: false + required: false + type: boolean + PYTHON_VERSION: + description: 'The Python version to use to perform the steps' + default: "" + required: true + type: string + secrets: + TEST_PYPI_API_TOKEN: + required: false + PYPI_API_TOKEN: + required: false push: tags: - '*' +env: + DEFAULT_TOOLING_PYTHON_VERSION: "3.10" + jobs: build-and-release: - name: Build and release Kazoo to Pypi + name: Build and release Kazoo to PyPI runs-on: ubuntu-latest steps: + + # this is to handle the on:push:tags case, to which it is not possible to set + # default values + - name: Maybe set default vars + id: thevars + run: | + DEFINED_PYTHON_VERSION=${{ inputs.PYTHON_VERSION }} + echo "PYTHON_VERSION=${DEFINED_PYTHON_VERSION:-"${{ env.DEFAULT_TOOLING_PYTHON_VERSION }}"}" >> $GITHUB_OUTPUT + - name: Handle the code uses: actions/checkout@v3 - - name: Set up Python 3.10 + - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: ${{ steps.thevars.outputs.PYTHON_VERSION }} - name: Install pypa/build run: >- @@ -29,15 +63,22 @@ jobs: run: >- python -m build - -C--global-option=egg_info - -C--global-option=--tag-build="" + -C--build-option=egg_info + -C--build-option=--tag-build="${{ inputs.TAG_BUILD }}" --sdist --wheel --outdir dist/ . + - name: Publish Kazoo to TestPyPI + if: ${{ inputs.USE_TEST_PYPI }} + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.TEST_PYPI_API_TOKEN }} + repository_url: https://test.pypi.org/legacy/ + - name: Publish Kazoo to PyPI - if: startsWith(github.ref, 'refs/tags') - uses: pypa/gh-action-pypi-publish@master + if: ${{ github.event_name == 'push' || !inputs.USE_TEST_PYPI }} + uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index fd60e867..f20f8fdc 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -10,20 +10,27 @@ on: - master - release/* +env: + TOOLING_PYTHON_VERSION: "3.10" + jobs: validate: name: Code Validation runs-on: ubuntu-latest + outputs: + tooling-python-version: ${{ steps.setup-python.outputs.python-version }} + steps: - name: Handle the code uses: actions/checkout@v3 - - name: "Set up Python 3.10" + - name: "Set up Python" uses: actions/setup-python@v4 + id: setup-python with: - python-version: "3.10" + python-version: ${{ env.TOOLING_PYTHON_VERSION }} - name: Handle pip cache uses: actions/cache@v3 @@ -111,3 +118,16 @@ jobs: - name: Publish Codecov report uses: codecov/codecov-action@v3 + + package_and_release: + name: "Package & release" + needs: [validate, test] + uses: ./.github/workflows/release.yml + with: + # https://peps.python.org/pep-0440 + TAG_BUILD: -dev0+g${{ github.sha }}.1 + USE_TEST_PYPI: true + # cant use ${{ env.STUFF }} here... + PYTHON_VERSION: ${{ needs.validate.outputs.tooling-python-version }} + secrets: + TEST_PYPI_API_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }} \ No newline at end of file