|
| 1 | +name: build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + python-version: ["3.10", "3.11", "3.12"] |
| 17 | + |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + - name: Set up Python ${{ matrix.python-version }} |
| 21 | + uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: ${{ matrix.python-version }} |
| 24 | + - name: Cache Huggingface assets |
| 25 | + uses: actions/cache@v4 |
| 26 | + with: |
| 27 | + key: huggingface-0-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }} |
| 28 | + path: ~/.cache/huggingface |
| 29 | + restore-keys: | |
| 30 | + huggingface-0-${{ runner.os }}-${{ matrix.python-version }}- |
| 31 | + - name: Load cached Poetry installation |
| 32 | + id: cached-poetry |
| 33 | + uses: actions/cache@v4 |
| 34 | + with: |
| 35 | + path: ~/.local # the path depends on the OS |
| 36 | + key: poetry-${{ runner.os }}-${{ matrix.python-version }}-1 # increment to reset cache |
| 37 | + - name: Install Poetry |
| 38 | + if: steps.cached-poetry.outputs.cache-hit != 'true' |
| 39 | + uses: snok/install-poetry@v1 |
| 40 | + with: |
| 41 | + virtualenvs-create: true |
| 42 | + virtualenvs-in-project: true |
| 43 | + installer-parallel: true |
| 44 | + - name: Load cached venv |
| 45 | + id: cached-poetry-dependencies |
| 46 | + uses: actions/cache@v4 |
| 47 | + with: |
| 48 | + path: .venv |
| 49 | + key: venv-0-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }} |
| 50 | + restore-keys: | |
| 51 | + venv-0-${{ runner.os }}-${{ matrix.python-version }}- |
| 52 | + - name: Install dependencies |
| 53 | + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' |
| 54 | + run: poetry install --no-interaction |
| 55 | + - name: Run Unit Tests |
| 56 | + run: poetry run pytest tests/unit |
| 57 | + - name: Build package |
| 58 | + run: poetry build |
| 59 | + |
| 60 | + release: |
| 61 | + needs: build |
| 62 | + permissions: |
| 63 | + contents: write |
| 64 | + id-token: write |
| 65 | + # https://github.community/t/how-do-i-specify-job-dependency-running-in-another-workflow/16482 |
| 66 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'chore(release):') |
| 67 | + runs-on: ubuntu-latest |
| 68 | + concurrency: release |
| 69 | + environment: |
| 70 | + name: pypi |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v4 |
| 73 | + with: |
| 74 | + fetch-depth: 0 |
| 75 | + - uses: actions/setup-python@v5 |
| 76 | + with: |
| 77 | + python-version: "3.11" |
| 78 | + - name: Semantic Release |
| 79 | + id: release |
| 80 | + uses: python-semantic-release/[email protected] |
| 81 | + with: |
| 82 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + - name: Publish package distributions to PyPI |
| 84 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 85 | + if: steps.release.outputs.released == 'true' |
| 86 | + - name: Publish package distributions to GitHub Releases |
| 87 | + uses: python-semantic-release/upload-to-gh-release@main |
| 88 | + if: steps.release.outputs.released == 'true' |
| 89 | + with: |
| 90 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments