From 75af7ec91e296ae240cc0f696ee71230064c0637 Mon Sep 17 00:00:00 2001 From: Suvayu Ali Date: Thu, 18 Jul 2024 15:37:55 +0200 Subject: [PATCH] workflows: factor out testing to be able to use `if:` --- .github/workflows/test-n-publish.yml | 63 +++------------------- .github/workflows/test-wheel.yml | 81 ++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 56 deletions(-) create mode 100644 .github/workflows/test-wheel.yml diff --git a/.github/workflows/test-n-publish.yml b/.github/workflows/test-n-publish.yml index d09420e..d4aa22e 100644 --- a/.github/workflows/test-n-publish.yml +++ b/.github/workflows/test-n-publish.yml @@ -73,62 +73,13 @@ jobs: os: [ubuntu-latest, windows-latest] python: ["3.8", "3.9", "3.10", "3.11", "3.12"] fail-fast: false - runs-on: ${{ matrix.os }} - steps: - - name: Make dist directory - run: mkdir -p dist - - name: Download all wheels - uses: actions/download-artifact@v3 - with: - path: dist - - name: Checkout ${{ matrix.pkg }} - uses: actions/checkout@v3 - with: - repository: 'spine-tools/${{ matrix.pkg }}' - path: ${{ matrix.pkg }} - ref: ${{ inputs[matrix.pkg] }} - - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - - name: Install pytest and built wheels on *NIX - if: runner.os != 'Windows' - run: | - python -m pip install --upgrade pip - python -m pip install dist/*/*.whl - python -m pip install pytest - - name: Install pytest and built wheels on Windows - if: runner.os == 'Windows' - run: | - python -m pip install --upgrade pip - Get-ChildItem ./dist/*.whl -Recurse | ForEach-Object {python -m pip install $_} - python -m pip install pytest - - name: Install additional packages for Linux - if: runner.os == 'Linux' - run: | - sudo apt-get update -y - sudo apt-get install -y libegl1 - - name: Remove source from checkouts for *NIX - if: runner.os != 'Windows' - run: | - rm -rf Spine-Toolbox/spinetoolbox* spine-items/spine_items \ - spine-engine/spine_engine Spine-Database-API/spinedb_api - - name: Remove source from checkouts for Windows - if: runner.os == 'Windows' - run: | - Remove-Item Spine-Toolbox\spinetoolbox* -Recurse -Force -ErrorAction Ignore - Remove-Item spine-items\spine_items -Recurse -Force -ErrorAction Ignore - Remove-Item spine-engine\spine_engine -Recurse -Force -ErrorAction Ignore - Remove-Item Spine-Database-API\spinedb_api -Recurse -Force -ErrorAction Ignore - - name: Test wheels - env: - QT_QPA_PLATFORM: offscreen - run: | - python -m unittest discover -s ${{ matrix.pkg }} --verbose - - name: Execution tests - if: matrix.pkg == 'Spine-Toolbox' - run: | - python -m unittest discover -s ${{ matrix.pkg }} --pattern execution_test.py --verbose + + uses: ./.github/workflows/test-wheel.yml + with: + pkg: ${{ matrix.pkg }} + ver: ${{ inputs[matrix.pkg] }} + os: ${{ matrix.os }} + python: ${{ matrix.python }} publish: # isolate from test, to prevent partial uploads diff --git a/.github/workflows/test-wheel.yml b/.github/workflows/test-wheel.yml new file mode 100644 index 0000000..1fa0705 --- /dev/null +++ b/.github/workflows/test-wheel.yml @@ -0,0 +1,81 @@ +name: Reusable workflow to publish Spine package wheels + +on: + workflow_call: + inputs: + pkg: + description: Package name + type: string + required: true + ver: + description: Release tag + type: string + required: true + os: + description: Operating System/Platform + type: string + required: true + python: + description: Python version + type: string + required: true + +jobs: + test-whl: + if: inputs.ver != 'skip' + runs-on: ${{ inputs.os }} + steps: + - name: Make dist directory + run: mkdir -p dist + - name: Download all wheels + uses: actions/download-artifact@v4 + with: + path: dist + - name: Checkout ${{ inputs.pkg }} + uses: actions/checkout@v4 + with: + repository: 'spine-tools/${{ inputs.pkg }}' + path: ${{ inputs.pkg }} + ref: ${{ inputs[inputs.pkg] }} + - name: Set up Python ${{ inputs.python }} + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python }} + - name: Install pytest and built wheels on *NIX + if: runner.os != 'Windows' + run: | + python -m pip install --upgrade pip + python -m pip install dist/*/*.whl + python -m pip install pytest + - name: Install pytest and built wheels on Windows + if: runner.os == 'Windows' + run: | + python -m pip install --upgrade pip + Get-ChildItem ./dist/*.whl -Recurse | ForEach-Object {python -m pip install $_} + python -m pip install pytest + - name: Install additional packages for Linux + if: runner.os == 'Linux' + run: | + sudo apt-get update -y + sudo apt-get install -y libegl1 + - name: Remove source from checkouts for *NIX + if: runner.os != 'Windows' + run: | + rm -rf Spine-Toolbox/spinetoolbox* spine-items/spine_items \ + spine-engine/spine_engine Spine-Database-API/spinedb_api + - name: Remove source from checkouts for Windows + if: runner.os == 'Windows' + run: | + Remove-Item Spine-Toolbox\spinetoolbox* -Recurse -Force -ErrorAction Ignore + Remove-Item spine-items\spine_items -Recurse -Force -ErrorAction Ignore + Remove-Item spine-engine\spine_engine -Recurse -Force -ErrorAction Ignore + Remove-Item Spine-Database-API\spinedb_api -Recurse -Force -ErrorAction Ignore + - name: Test wheels + env: + QT_QPA_PLATFORM: offscreen + run: | + python -m unittest discover -s ${{ inputs.pkg }} --verbose + - name: Execution tests + if: inputs.pkg == 'Spine-Toolbox' + run: | + python -m unittest discover -s ${{ inputs.pkg }} --pattern execution_test.py --verbose