Skip to content

Commit

Permalink
add deploy action
Browse files Browse the repository at this point in the history
  • Loading branch information
BalzaniEdoardo committed Nov 7, 2023
1 parent dd4466b commit 3c3b2ee
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/deploy-pure-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Build and upload to PyPI for pure python
on:
release:
types: [published]

jobs:
build:
name: Build and test package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# this is necessary for setuptools_scm to work properly with github
# actions, see https://github.com/pypa/setuptools_scm/issues/480 and
# https://stackoverflow.com/a/68959339
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Build package
run: |
pip install build
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
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]"
- name: Run some tests
# modify the following as necessary to e.g., run notebooks
run: |
pytest
- 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
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

0 comments on commit 3c3b2ee

Please sign in to comment.