fix: pypi #13
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
name: "build and release" | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
# Allow this workflow to be called from other workflows | |
workflow_call: | |
inputs: | |
# Requires at least one input to be valid, but in practice we don't need any | |
dummy: | |
type: string | |
required: false | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.11", "3.12"] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup PDM | |
uses: pdm-project/setup-pdm@v4 | |
with: | |
cache: true | |
python-version: ${{ matrix.python-version }} | |
- name: Cache Huggingface assets | |
uses: actions/cache@v4 | |
with: | |
key: huggingface-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }} | |
path: ~/.cache/huggingface | |
restore-keys: | | |
huggingface-${{ runner.os }}-${{ matrix.python-version }}- | |
- name: Install dependencies | |
run: pdm install | |
- name: check formatting | |
run: pdm run ruff format --check | |
- name: check linting | |
run: pdm run ruff check | |
# TODO: re-enable when I can be bothered to fix | |
- name: check types | |
run: pdm run pyright | |
- name: test | |
run: pdm run pytest | |
- name: build | |
run: pdm build | |
release: | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
id-token: write | |
environment: | |
# Same environment name configured in PyPI trusted publisher | |
name: pypi | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'chore(release):') | |
concurrency: release | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup PDM | |
uses: pdm-project/setup-pdm@v4 | |
with: | |
cache: true | |
python-version: "3.11" | |
- name: Install dependencies | |
run: pdm install | |
- name: Semantic Release | |
id: release | |
uses: python-semantic-release/python-semantic-release@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish package distributions to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
if: steps.release.outputs.released == 'true' | |
- name: Publish package distributions to GitHub Releases | |
uses: python-semantic-release/upload-to-gh-release@main | |
if: steps.release.outputs.released == 'true' | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} |