From 1b1c11b932b7b775ccb66ce8ff87fc8917e104f2 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 11 Mar 2024 15:53:14 +0100 Subject: [PATCH] split release.yml workflow out from test.yml --- .github/workflows/release.yml | 88 +++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 77 +----------------------------- 2 files changed, 89 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..f4608720 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,88 @@ +name: Tests + +on: + push: + branches: [main] + pull_request: + release: + types: [published] + workflow_dispatch: + inputs: + task: + type: choice + options: [release, test-release] + default: test-release + description: Run tests, release to PyPI, or release to TestPyPI. + +jobs: + tests: + # run test.yml first to ensure that the test suite is passing + uses: ./.github/workflows/test.yml + + build_source_dist: + name: Build source distribution + needs: tests + runs-on: ubuntu-latest + if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.task == 'release') + steps: + - name: Check out repo + uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + name: Install Python + with: + python-version: "3.10" + + - name: Build source distribution + run: | + pip install build + python -m build --sdist + + - uses: actions/upload-artifact@v3 + with: + path: dist/*.tar.gz + + build_wheels: + name: Build wheels for Python ${{ matrix.python-version }} on ${{ matrix.os }} + needs: tests + if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.task == 'release') + strategy: + matrix: + os: [ubuntu-latest, macos-14, windows-latest] + python-version: ["39", "310", "311", "312"] + runs-on: ${{ matrix.os }} + steps: + - name: Check out repo + uses: actions/checkout@v4 + + - name: Build wheels + uses: pypa/cibuildwheel@v2.16.5 + env: + CIBW_BUILD: cp${{ matrix.python-version }}-* + CIBW_ARCHS_MACOS: universal2 + + - name: Save artifact + uses: actions/upload-artifact@v3 + with: + path: wheelhouse + + release: + name: Release wheels and source distribution to PyPI + needs: [build_wheels, build_source_dist] + runs-on: ubuntu-latest + permissions: + # For pypi trusted publishing + id-token: write + steps: + - name: Download build artifacts + uses: actions/download-artifact@v3 + with: + name: artifact + path: dist + + - name: Publish to PyPi or TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + skip-existing: true + verbose: true + repository-url: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.task == 'test-release' && 'https://test.pypi.org/legacy/' || '' }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 889acc4f..479b7f9a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,15 +4,8 @@ on: push: branches: [main] pull_request: - release: - types: [published] workflow_dispatch: - inputs: - task: - type: choice - options: [tests, release, test-release] - default: tests - description: Run tests, release to PyPI, or release to TestPyPI. + workflow_call: jobs: tests: @@ -59,71 +52,3 @@ jobs: with: project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} coverage-reports: coverage.xml - - build_source_dist: - name: Build source distribution - needs: tests - runs-on: ubuntu-latest - if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.task == 'release') - steps: - - name: Check out repo - uses: actions/checkout@v4 - - - uses: actions/setup-python@v5 - name: Install Python - with: - python-version: "3.10" - - - name: Build source distribution - run: | - pip install build - python -m build --sdist - - - uses: actions/upload-artifact@v3 - with: - path: dist/*.tar.gz - - build_wheels: - name: Build wheels for Python ${{ matrix.python-version }} on ${{ matrix.os }} - needs: tests - if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.task == 'release') - strategy: - matrix: - os: [ubuntu-latest, macos-14, windows-latest] - python-version: ["39", "310", "311", "312"] - runs-on: ${{ matrix.os }} - steps: - - name: Check out repo - uses: actions/checkout@v4 - - - name: Build wheels - uses: pypa/cibuildwheel@v2.16.5 - env: - CIBW_BUILD: cp${{ matrix.python-version }}-* - CIBW_ARCHS_MACOS: universal2 - - - name: Save artifact - uses: actions/upload-artifact@v3 - with: - path: wheelhouse - - release: - name: Release wheels and source distribution to PyPI - needs: [build_wheels, build_source_dist] - runs-on: ubuntu-latest - permissions: - # For pypi trusted publishing - id-token: write - steps: - - name: Download build artifacts - uses: actions/download-artifact@v3 - with: - name: artifact - path: dist - - - name: Publish to PyPi or TestPyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - skip-existing: true - verbose: true - repository-url: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.task == 'test-release' && 'https://test.pypi.org/legacy/' || '' }}