|
| 1 | +name: Python package |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [ created ] |
| 6 | + |
| 7 | +jobs: |
| 8 | + lint: |
| 9 | + name: Lint Code |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - uses: actions/checkout@v4 |
| 13 | + - name: Set up Python 3.12 |
| 14 | + uses: actions/setup-python@v3 |
| 15 | + with: |
| 16 | + python-version: "3.12" |
| 17 | + - name: Install flake8 |
| 18 | + run: | |
| 19 | + python -m pip install --upgrade pip |
| 20 | + python -m pip install flake8 |
| 21 | + - name: Lint with flake8 |
| 22 | + run: | |
| 23 | + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
| 24 | + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 25 | +
|
| 26 | + build: |
| 27 | + name: Build |
| 28 | + runs-on: ${{ matrix.os }} |
| 29 | + strategy: |
| 30 | + fail-fast: false |
| 31 | + matrix: |
| 32 | + os: [ ubuntu-latest, windows-latest, macos-latest ] |
| 33 | + python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ] |
| 34 | + |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Set up Python ${{ matrix.python-version }} |
| 39 | + uses: actions/setup-python@v3 |
| 40 | + with: |
| 41 | + python-version: ${{ matrix.python-version }} |
| 42 | + |
| 43 | + - name: Cache pip |
| 44 | + uses: actions/cache@v3 |
| 45 | + with: |
| 46 | + path: ~/.cache/pip |
| 47 | + key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} |
| 48 | + restore-keys: | |
| 49 | + ${{ runner.os }}-pip- |
| 50 | +
|
| 51 | + - name: Install dependencies |
| 52 | + run: | |
| 53 | + python -m pip install --upgrade pip |
| 54 | + python -m pip install flake8 pytest pytest-cov |
| 55 | + python -m pip install -r requirements.txt |
| 56 | +
|
| 57 | + - name: Build |
| 58 | + shell: bash |
| 59 | + run: | |
| 60 | + if [[ "$RUNNER_OS" == "Windows" ]]; then |
| 61 | + ./build.cmd |
| 62 | + else |
| 63 | + chmod +x ./build.sh && ./build.sh |
| 64 | + fi |
| 65 | +
|
| 66 | + - name: Find Correct Build |
| 67 | + id: findbuild |
| 68 | + shell: bash |
| 69 | + run: | |
| 70 | + if [[ "$RUNNER_OS" == "Windows" ]]; then |
| 71 | + output=__pyfastutil.pyd |
| 72 | + else |
| 73 | + output=__pyfastutil.so |
| 74 | + fi |
| 75 | + echo "::set-output name=libname::$output" |
| 76 | +
|
| 77 | + - name: Upload Build Artifacts |
| 78 | + uses: actions/upload-artifact@v3 |
| 79 | + with: |
| 80 | + name: ${{ matrix.os }}_py${{ matrix.python-version }}-${{ steps.findbuild.outputs.libname }} |
| 81 | + path: pyfastutil/${{ steps.findbuild.outputs.libname }} |
| 82 | + |
| 83 | + - name: Test with pytest and generate coverage report |
| 84 | + run: | |
| 85 | + pytest --cov=your_package_name --cov-report=xml |
| 86 | +
|
| 87 | + - name: Upload coverage to Codecov |
| 88 | + uses: codecov/codecov-action@v3 |
| 89 | + with: |
| 90 | + file: ./coverage.xml |
| 91 | + flags: unittests |
| 92 | + name: codecov-umbrella |
| 93 | + |
| 94 | + - name: Upload to PyPI |
| 95 | + shell: bash |
| 96 | + run: | |
| 97 | + if [[ "$RUNNER_OS" == "Windows" ]]; then |
| 98 | + ./upload.cmd |
| 99 | + else |
| 100 | + chmod +x ./upload.sh && ./upload.sh |
| 101 | + fi |
0 commit comments