Skip to content

[ci] with venvs?

[ci] with venvs? #498

Workflow file for this run

name: Continuous integration
on:
push:
release:
types: [ published ]
workflow_dispatch:
inputs:
deploy_trigger:
description: Force a deployment to PyPI
default: "false"
required: true
env:
main-python-version: "3.12"
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: "**/pyproject.toml"
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
uvx --python ${{ env.main-python-version }} ruff check . --select=E9,F63,F7,F82 --output-format=github
# exit-zero treats all errors as warnings.
uvx --python ${{ env.main-python-version }} ruff check . --exit-zero --output-format=github
test:
needs: lint
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: "**/pyproject.toml"
- name: Create base venv
run: uv venv --python ${{ matrix.python-version }}
- name: Get transformers and cache
id: transfo-install
run: |
source .venv/bin/activate
uv pip install --upgrade transformers
python -c "from transformers.file_utils import TRANSFORMERS_CACHE; print(f'dir={TRANSFORMERS_CACHE}')" >> $GITHUB_OUTPUT
echo "version=$(pip show transformers | grep Version)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
path: ${{ steps.transfo-install.outputs.dir }}
key: ${{ runner.os }}-transformers-${{ steps.transfo-install.outputs.version }}
restore-keys: |
${{ runner.os }}-transformers-
- name: Run tox
run: |
source .venv/bin/activate
uv pip install tox tox-gh-actions tox-uv
tox
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
needs: test
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: "**/pyproject.toml"
- name: Build wheels
run: uvx --python ${{ env.main-python-version }} build --wheel
- uses: actions/upload-artifact@v4
with:
name: dist-wheel-${{ matrix.os }}
path: ./dist/*.whl
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: "**/pyproject.toml"
- name: Build wheels
run: uvx --python ${{ env.main-python-version }} build --sdist
- uses: actions/upload-artifact@v4
with:
name: dist-sdist
path: dist/*.tar.gz
upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
if: >
(github.event_name == 'release' && github.event.action == 'published')
|| (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_trigger == 'true')
steps:
- uses: actions/download-artifact@v4
with:
pattern: dist-*
path: dist
merge-multiple: true
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_token }}
# To test: repository_url: https://test.pypi.org/legacy/