Skip to content

Commit

Permalink
build: convert workflow to reusable workflow for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
qthequartermasterman committed May 10, 2024
1 parent 46e3516 commit b1aa17a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 41 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/build-reusable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
name: Lint and Test

on:
workflow_call:
inputs:
python-version:
description: 'Python version'
required: true
type: string
lint:
description: 'Run linter'
required: false
default: false
type: boolean
torch-version:
description: 'PyTorch version'
required: false
default: ''
type: string

env:
HYPOTHESIS_PROFILE: "ci"
UV_SYSTEM_PYTHON: "true"

permissions:
contents: write
checks: write
pull-requests: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
id: cache-uv
with:
path: ~/.cache/uv
key: ${{ runner.os }}-python-${{ inputs.python-version }}-uv
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- name: Install uv
run: |
python -m pip install --upgrade uv
- name: Install Specific PyTorch version
if: ${{ inputs.torch-version != '' }}
run: |
uv pip install torch==${{ inputs.torch-version }}
- name: Install dependencies
run: |
uv pip install ".[dev,huggingface]"
- name: Lint with ruff
if: ${{ inputs.lint }}
run: |
ruff check --fix
- name: Format with ruff
if: ${{ inputs.lint }}
run: |
ruff format
- uses: stefanzweifel/git-auto-commit-action@v5
if: ${{ inputs.lint }}
with:
commit_message: 'style fixes by ruff'
- name: Run tests
run: |
python -m pytest \
--junitxml=pytest.xml \
--cov-report=term-missing:skip-covered \
--cov=hypothesis_torch \
tests \
| tee pytest-coverage.txt
- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml
46 changes: 5 additions & 41 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:

env:
HYPOTHESIS_PROFILE: "ci"
UV_SYSTEM_PYTHON: "true"

permissions:
contents: write
Expand All @@ -20,44 +21,7 @@ jobs:
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
id: cache-uv
with:
path: ~/.cache/uv
key: ${{ runner.os }}-python-${{ matrix.python-version }}-uv
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade uv
uv pip install --system ".[dev,huggingface]"
- name: Lint with ruff
if: ${{ matrix.python-version == '3.9' }}
run: |
ruff check
- name: Format with ruff
if: ${{ matrix.python-version == '3.9' }}
run: |
ruff format
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: 'style fixes by ruff'
- name: Run tests
run: |
python -m pytest \
--junitxml=pytest.xml \
--cov-report=term-missing:skip-covered \
--cov=hypothesis_torch \
tests \
| tee pytest-coverage.txt
- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml
uses: .github/workflows/build-reusable.yml
with:
python-version: ${{ matrix.python-version }}
lint: ${{ matrix.python-version == '3.9' }}

0 comments on commit b1aa17a

Please sign in to comment.