Skip to content

Commit

Permalink
Reorganize workflows.
Browse files Browse the repository at this point in the history
Skip tests on emulated architectures.

Make an sdist in its own job so that isolated tests can start sooner.

Let more builds/tests run in parallel.

Merge publish jobs so that PyPI updates are done all at once.
  • Loading branch information
HexDecimal committed May 25, 2023
1 parent 814f54f commit 315dba0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 53 deletions.
93 changes: 40 additions & 53 deletions .github/workflows/python-package.yml
Expand Up @@ -13,7 +13,7 @@ defaults:
shell: bash

env:
git-depth: 0 # Depth to search for tags.
git-depth: 500 # Depth to search for tags.

jobs:
black:
Expand Down Expand Up @@ -55,17 +55,37 @@ jobs:
- uses: actions/checkout@v3
- name: Checkout submodules
run: git submodule update --init --recursive --depth 1
- name: Install Python dependencies
- name: Install typing dependencies
run: pip install mypy pytest -r requirements.txt
- name: Fake initialize package
run: |
echo '__version__ = ""' > tcod/version.py
- name: Mypy
uses: liskin/gh-problem-matcher-wrap@v2
with:
linters: mypy
run: mypy --show-column-numbers

sdist:
runs-on: ubuntu-latest
steps:
- name: APT update
run: sudo apt-get update
- name: Install APT dependencies
run: sudo apt-get install libsdl2-dev
- uses: actions/checkout@v3
with:
fetch-depth: ${{ env.git-depth }}
- name: Checkout submodules
run: git submodule update --init --recursive --depth 1
- name: Install build
run: pip install build
- name: Build source distribution
run: python -m build --sdist
- uses: actions/upload-artifact@v3
with:
name: sdist
path: dist/tcod-*.tar.gz
retention-days: 7


# This makes sure that the latest versions of the SDL headers parse correctly.
parse_sdl:
needs: [black, isort, flake8, mypy]
Expand Down Expand Up @@ -133,7 +153,7 @@ jobs:
- name: Initialize package
run: |
pip install -e . # Install the package in-place.
- name: Build package.
- name: Build package
run: |
python -m build
- name: Test with pytest
Expand All @@ -148,12 +168,6 @@ jobs:
if: runner.os != 'Windows'
run: cat /tmp/xvfb.log
- uses: codecov/codecov-action@v3
- uses: actions/upload-artifact@v3
if: runner.os == 'Linux'
with:
name: sdist
path: dist/tcod-*.tar.gz
retention-days: 7
- uses: actions/upload-artifact@v3
if: runner.os == 'Windows'
with:
Expand All @@ -162,7 +176,7 @@ jobs:
retention-days: 7

isolated: # Test installing the package from source.
needs: build
needs: [black, isort, flake8, mypy, sdist]
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -192,8 +206,7 @@ jobs:
python -c "import tcod"
linux-wheels:
needs: build # These take a while to build/test, so wait for normal tests to pass first.
if: startsWith(github.event.ref, 'refs/tags/')
needs: [black, isort, flake8, mypy]
runs-on: "ubuntu-latest"
strategy:
matrix:
Expand Down Expand Up @@ -232,6 +245,8 @@ jobs:
yum install -y SDL2-devel
CIBW_BEFORE_TEST: pip install numpy
CIBW_TEST_COMMAND: python -c "import tcod"
# Skip test on emulated architectures
CIBW_TEST_SKIP: "*_aarch64"
- name: Archive wheel
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -260,7 +275,7 @@ jobs:
run: pip3 install -r requirements.txt
- name: Prepare package
# Downloads SDL2 for the later step.
run: python3 setup.py || true
run: python3 build_sdl.py
- name: Build wheels
uses: pypa/cibuildwheel@v2.12.3
env:
Expand All @@ -278,7 +293,7 @@ jobs:
retention-days: 7

publish:
needs: [build]
needs: [sdist, build, build-macos, linux-wheels]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
environment:
Expand All @@ -295,42 +310,14 @@ jobs:
with:
name: wheels-windows
path: dist/
- uses: actions/download-artifact@v3
with:
name: wheels-macos
path: dist/
- uses: actions/download-artifact@v3
with:
name: wheels-linux
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true

publish-macos:
needs: [build-macos]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
environment:
name: release
url: https://pypi.org/p/tcod
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v3
with:
name: wheels-macos
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true

publish-linux:
needs: [linux-wheels]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
environment:
name: release
url: https://pypi.org/p/tcod
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v3
with:
name: wheels-linux
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
4 changes: 4 additions & 0 deletions pyproject.toml
Expand Up @@ -134,6 +134,10 @@ exclude = [
module = "numpy.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "tcod.version"
ignore_missing_imports = true


[tool.ruff]
# https://beta.ruff.rs/docs/rules/
Expand Down

0 comments on commit 315dba0

Please sign in to comment.