Skip to content

Test build and publish Cobramod to PyPI #171

Test build and publish Cobramod to PyPI

Test build and publish Cobramod to PyPI #171

name: Test build and publish Cobramod to PyPI
on:
workflow_dispatch:
schedule:
- cron: "0 5 * * 1"
pull_request:
types: [ opened, synchronize, reopened, closed ]
branches:
- master
jobs:
lint-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: python -m pip install tox
- name: Linter
run: python -m tox -e lint
- name: Format
run: python -m tox -e format
types:
needs: [ lint-format ]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.10", "3.11", "3.12" ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: python -m pip install tox
- name: Run type-checking
run: python -m tox -e types
build:
needs: [ types ]
runs-on: ubuntu-latest
outputs:
file-path: ${{ steps.path.outputs.file-path }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
- name: Set up JS & build js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel build
yarn install
- name: Build JS
run: yarn run vite build
- name: Build package
run: python -m build
- name: Get file name
id: path
run: echo "file-path=$(cd dist && find . -type f -name cobramod-*.whl)" >> "$GITHUB_OUTPUT"
- name: Archive package as artifact
uses: actions/upload-artifact@v4
with:
name: cobramod-dist
path: |
dist
unittest:
needs: [build]
strategy:
max-parallel: 1
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
python-version: [ "3.10", "3.11", "3.12" ]
runs-on: ${{ matrix.os}}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Download package as artifact
uses: actions/download-artifact@v4
with:
name: cobramod-dist
- name: Install tox
run: python -m pip install tox-gh>=1.2
- name: Credentials
run: echo "${{ secrets.BIOCYC_USER }}\n${{ secrets.BIOCYC_PASS }}" >> credentials.txt
- name: Setup test suite
run: tox -vv --notest --installpkg ${{ needs.build.outputs.file-path }}
- name: Run test suite
run: tox --skip-pkg-install
- name: Upload coverage reports to Codecov
if: ${{ ( matrix.python-version == '3.12' ) && ( runner.os == 'Linux' ) }}
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
publish-to-pypi:
needs: [unittest]
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: github.event.pull_request.merged == true && github.event_name != 'schedule'
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/cobramod
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: cobramod-dist
path: |
dist
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel twine build
- name: Check the package
run: twine check dist/*
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1