Update CI file for release to PyPi #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
push: | |
branches: [main] | |
pull_request: | |
release: | |
types: [ published ] | |
jobs: | |
test: | |
name: Unit tests / ${{ matrix.python }} / ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ ubuntu-latest ] | |
python: [ "3.10", "3.11" ] | |
fail-fast: true | |
env: | |
OS: ${{ matrix.os }} | |
PYTHON: ${{ matrix.python }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
id: setup-python | |
with: | |
python-version: ${{ matrix.python }} | |
- name: Load cached Poetry installation | |
id: cached-poetry | |
uses: actions/cache@v3 | |
with: | |
path: ~/.local # the path depends on the OS | |
key: poetry-1.7.7-1 # increment to reset cache | |
# The key configuration value here is `virtualenvs-in-project: true`: this creates the | |
# venv as a `.venv` in your testing directory, which allows the next step to easily | |
# cache it. | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
#if: steps.cached-poetry.outputs.cache-hit != 'true' | |
with: | |
version: 1.7.1 | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
- name: Load cached venv | |
id: cache-deps | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache | |
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
# Install dependencies. `--no-root` means "install all dependencies but not the project | |
# itself", which is what you want to avoid caching _your_ code. The `if` statement | |
# ensures this only runs on a cache miss. | |
- name: Install dependencies | |
run: | | |
poetry install --no-interaction --no-root | |
#if: steps.cache-deps.outputs.cache-hit != 'true' | |
# Now install _your_ project. This isn't necessary for many types of projects -- particularly | |
# things like Django apps don't need this. But it's a good idea since it fully-exercises the | |
# pyproject.toml and makes that if you add things like console-scripts at some point that | |
# they'll be installed and working. | |
- name: Install library | |
run: | | |
poetry install --no-interaction | |
# Run Tests. | |
#- run: |source $VENV | |
#poetry run pytest | |
- name: Artifact creation | |
run: | | |
poetry build | |
- name: Save artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: dist | |
path: ./dist | |
upload_pypi: | |
name: Release to PyPi | |
needs: [test] | |
permissions: | |
id-token: write | |
runs-on: ubuntu-latest | |
# upload to PyPI only on release | |
if: github.event.release && github.event.action == 'published' | |
steps: | |
- name: Retrieve release distributions | |
uses: actions/download-artifact@v4 | |
with: | |
name: release-dist | |
path: dist | |
- name: Publish release distributions to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 |