Skip to content

Update deploy

Update deploy #6

Workflow file for this run

name: deploy
on:
pull_request:
branches:
- main
workflow_dispatch:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build --outdir dist/ --sdist --wheel
- name: Check there's only one sdist and one whl file created
shell: bash
# because the following two tests will be weird otherwise. see
# https://askubuntu.com/a/454568 for why this is the right way to handle
# it. using [[ BOOLEAN ]] || EXPR is a compact way of writing IF NOT
# BOOLEAN THEN EXPR in bash
run: |
[[ $(find dist/ -type f -name "*whl" -printf x | wc -c) == 1 ]] || exit 1
[[ $(find dist/ -type f -name "*tar.gz" -printf x | wc -c) == 1 ]] || exit 1
- name: Check setuptools_scm version against git tag
shell: bash
# this won't work if we use workflow dispatch, so no sense in running
# it.
if: github.event_name == 'release' && github.event.action == 'published'
run: |
# we use the error code of this comparison: =~ is bash's regex
# operator, so it checks whether the right side is contained in the
# left side. In particular, we succeed if the path of the source code
# ends in the most recent git tag, fail if it does not.
[[ "$(ls dist/*tar.gz)" =~ "-$(git describe --tags).tar.gz" ]]
- name: Check we can install from wheel
# note that this is how this works in bash (different shells might be
# slightly different). we've checked there's only one .whl file in an
# earlier step, so the bit in `$()` will expand to that single file,
# then we pass [dev] to get specify the optional dev dependencies, and
# we wrap the whole thing in quotes so bash doesn't try to interpret the
# square brackets but passes them directly to pip install
shell: bash
run: |
pip install "$(ls dist/*whl)[dev,nb]" papermill
- name: Run tests
run: |
pytest -n auto
- name: Run notebooks
run: |
for file in examples/*ipynb; do
# these first two notebooks take much longer than the rest to run (2
# and 1 hours on laptop, respectively, longer on runners). So we use
# papermill's parameters to reduce the max number of steps for
# synthesis in them (we want to test that each cell runs, but we
# don't need synthesis to go to completion).
if [[ "$file" =~ "Metamer-Portilla-Simoncelli" ]]; then
papermill $file $file_output.ipynb -p short_synth_max_iter 10 -p long_synth_max_iter 10 -p longest_synth_max_iter 10 -k python3 --cwd examples/
elif [[ "$file" =~ "Demo_Eigendistortion" ]]; then
papermill $file $file_output.ipynb -p max_iter_frontend 10 -p max_iter_vgg 10 -k python3 --cwd examples/
else
jupyter execute $file --kernel_name=python3
fi
done
- uses: actions/upload-artifact@v3
with:
path: dist/*
publish:
name: Upload release to Test PyPI
needs: [build]
environment: pypi
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- name: Publish package to test pypi
if: github.event_name != 'release'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
- name: Publish package to real pypi
if: github.event_name == 'release' && github.event.action == 'published'
uses: pypa/gh-action-pypi-publish@release/v1