|
| 1 | +# This workflow will install Python dependencies, run tests and lint with a single version of Python |
| 2 | +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python |
| 3 | + |
| 4 | +name: CI/CD |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + pull_request: |
| 9 | + branches: ["main"] |
| 10 | + schedule: |
| 11 | + - cron: "0 2 * * 3" |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +jobs: |
| 17 | + format: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + - uses: psf/black@stable |
| 22 | + - uses: isort/isort-action@v1 |
| 23 | + lint: |
| 24 | + name: Lint with ruff |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - uses: actions/setup-python@v5 |
| 30 | + with: |
| 31 | + python-version: "3.12" |
| 32 | + - name: Install ruff |
| 33 | + run: | |
| 34 | + pip install ruff |
| 35 | + - name: Lint with ruff |
| 36 | + run: | |
| 37 | + # stop the build if there are Python syntax errors or undefined names |
| 38 | + ruff check . |
| 39 | + test: |
| 40 | + name: Test |
| 41 | + runs-on: macos-latest |
| 42 | + strategy: |
| 43 | + matrix: |
| 44 | + python-version: ["3.11", "3.12", "3.13"] |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@v4 |
| 47 | + - name: Set up Python ${{ matrix.python-version }} |
| 48 | + uses: actions/setup-python@v5 |
| 49 | + with: |
| 50 | + python-version: ${{ matrix.python-version }} |
| 51 | + cache: "pip" # caching pip dependencies |
| 52 | + cache-dependency-path: "**/pyproject.toml" |
| 53 | + - name: Install dependencies |
| 54 | + run: | |
| 55 | + python -m pip install --upgrade pip |
| 56 | + pip install pytest |
| 57 | + pip install -e . |
| 58 | + - name: Run tests |
| 59 | + run: python -m pytest tests |
| 60 | + |
| 61 | + build_source_dist: |
| 62 | + name: Build source distribution |
| 63 | + if: startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/tags') |
| 64 | + runs-on: ubuntu-latest |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v4 |
| 67 | + |
| 68 | + - uses: actions/setup-python@v5 |
| 69 | + with: |
| 70 | + python-version: "3.10" |
| 71 | + |
| 72 | + - name: Install build |
| 73 | + run: python -m pip install build |
| 74 | + |
| 75 | + - name: Run build |
| 76 | + run: python -m build --sdist |
| 77 | + |
| 78 | + - uses: actions/upload-artifact@v4 |
| 79 | + with: |
| 80 | + path: ./dist/*.tar.gz |
| 81 | + # Needed in case of building packages with external binaries (e.g. Cython, RUst-extensions, etc.) |
| 82 | + # build_wheels: |
| 83 | + # name: Build wheels on ${{ matrix.os }} |
| 84 | + # if: startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/tags') |
| 85 | + # runs-on: ${{ matrix.os }} |
| 86 | + # strategy: |
| 87 | + # matrix: |
| 88 | + # os: [ubuntu-20.04, windows-2019, macOS-10.15] |
| 89 | + |
| 90 | + # steps: |
| 91 | + # - uses: actions/checkout@v4 |
| 92 | + |
| 93 | + # - uses: actions/setup-python@v5 |
| 94 | + # with: |
| 95 | + # python-version: "3.10" |
| 96 | + |
| 97 | + # - name: Install cibuildwheel |
| 98 | + # run: python -m pip install cibuildwheel==2.3.1 |
| 99 | + |
| 100 | + # - name: Build wheels |
| 101 | + # run: python -m cibuildwheel --output-dir wheels |
| 102 | + |
| 103 | + # - uses: actions/upload-artifact@v4 |
| 104 | + # with: |
| 105 | + # path: ./wheels/*.whl |
| 106 | + |
| 107 | + publish: |
| 108 | + name: Publish package |
| 109 | + if: startsWith(github.ref, 'refs/tags') |
| 110 | + permissions: |
| 111 | + id-token: write |
| 112 | + needs: |
| 113 | + - format |
| 114 | + - lint |
| 115 | + - test |
| 116 | + - build_source_dist |
| 117 | + # - build_wheels |
| 118 | + runs-on: ubuntu-latest |
| 119 | + |
| 120 | + steps: |
| 121 | + - uses: actions/download-artifact@v4 |
| 122 | + with: |
| 123 | + name: artifact |
| 124 | + path: ./dist |
| 125 | + # register PyPI integration: |
| 126 | + # https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ |
| 127 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
| 128 | + with: |
| 129 | + # remove repository key to set the default to pypi (not test.pypi.org) |
| 130 | + repository-url: https://test.pypi.org/legacy/ |
0 commit comments