From 7954fd409b12a6db074f8da176673d6836f673ee Mon Sep 17 00:00:00 2001 From: Thomas Finnie Date: Sat, 3 Aug 2024 14:43:18 +0100 Subject: [PATCH] Tidy the CI more and add src distributions & pypi --- .../{main.yml => distribute_package.yml} | 90 ++++++++----------- .github/workflows/test_package.yml | 67 ++++++++++++++ 2 files changed, 103 insertions(+), 54 deletions(-) rename .github/workflows/{main.yml => distribute_package.yml} (63%) create mode 100644 .github/workflows/test_package.yml diff --git a/.github/workflows/main.yml b/.github/workflows/distribute_package.yml similarity index 63% rename from .github/workflows/main.yml rename to .github/workflows/distribute_package.yml index 40cd20b..901a235 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/distribute_package.yml @@ -1,4 +1,4 @@ -name: pygom +name: create PyGOM distributions on: push: @@ -13,60 +13,7 @@ on: - master - dev -env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, windows-latest] #, macos-13, macos-14] - python-version: ["3.9", "3.10", "3.11"] - - steps: - - uses: actions/checkout@v4 - - - uses: actions/cache@v4 - if: startsWith(runner.os, 'Linux') - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - uses: actions/cache@v4 - if: startsWith(runner.os, 'macOS') - with: - path: ~/Library/Caches/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - uses: actions/cache@v4 - if: startsWith(runner.os, 'Windows') - with: - path: ~\AppData\Local\pip\Cache - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - - name: Check python version - run: python -c "import sys; print(sys.version)" - - - name: Install pip - run: | - python -m pip install --upgrade pip - - - name: install PyGOM - run: | - pip install . - - - name: Run tests - run: python -m unittest discover --verbose --start-directory tests - build_wheels: name: Build wheels on ${{ matrix.platform_id }} for Python v${{ matrix.python[1] }} runs-on: ${{ matrix.os }} @@ -134,3 +81,38 @@ jobs: with: name: cibw-wheels-${{ matrix.platform_id }}-${{ matrix.python[0] }} path: ./wheelhouse/*.whl + + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Build sdist + run: pipx run build --sdist + + - uses: actions/upload-artifact@v4 + with: + name: cibw-sdist + path: dist/*.tar.gz + + upload_pypi: + needs: [build_wheels, build_sdist] + runs-on: ubuntu-latest + environment: pypi + permissions: + id-token: write + # Upload to PyPI on every tag starting with 'v' + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + steps: + - uses: actions/download-artifact@v4 + with: + # unpacks all CIBW artifacts into dist/ + pattern: cibw-* + path: dist + merge-multiple: true + + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + # Testing only at this point + repository-url: https://test.pypi.org/legacy/ \ No newline at end of file diff --git a/.github/workflows/test_package.yml b/.github/workflows/test_package.yml new file mode 100644 index 0000000..0c2a6cb --- /dev/null +++ b/.github/workflows/test_package.yml @@ -0,0 +1,67 @@ +name: create PyGOM distributions + +on: + push: + branches: + - master + - dev + - feature/* + - bugfix/* + + pull_request: + branches: + - master + - dev + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] #, macos-13, macos-14] + python-version: ["3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v4 + + - uses: actions/cache@v4 + if: startsWith(runner.os, 'Linux') + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - uses: actions/cache@v4 + if: startsWith(runner.os, 'macOS') + with: + path: ~/Library/Caches/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - uses: actions/cache@v4 + if: startsWith(runner.os, 'Windows') + with: + path: ~\AppData\Local\pip\Cache + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Check python version + run: python -c "import sys; print(sys.version)" + + - name: Install pip + run: | + python -m pip install --upgrade pip + + - name: install PyGOM + run: | + pip install . + + - name: Run tests + run: python -m unittest discover --verbose --start-directory tests + + #TODO: Could also do something about coverage here too \ No newline at end of file