|
| 1 | +name: CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["master"] |
| 6 | + pull_request: |
| 7 | + branches: ["master"] |
| 8 | + release: |
| 9 | + types: [created] |
| 10 | + branches: |
| 11 | + - 'master' |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +env: |
| 15 | + FORCE_COLOR: "1" # Make tools pretty. |
| 16 | + PIP_DISABLE_PIP_VERSION_CHECK: "1" |
| 17 | + PIP_NO_PYTHON_VERSION_WARNING: "1" |
| 18 | + PYTHON_LATEST: "3.12" |
| 19 | + KAFKA_LATEST: "2.6.0" |
| 20 | + |
| 21 | + # For re-actors/checkout-python-sdist |
| 22 | + sdist-artifact: python-package-distributions |
| 23 | + |
| 24 | +jobs: |
| 25 | + |
| 26 | + build-sdist: |
| 27 | + name: 📦 Build the source distribution |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Checkout project |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + - name: Set up Python |
| 35 | + uses: actions/setup-python@v5 |
| 36 | + with: |
| 37 | + python-version: ${{ env.PYTHON_LATEST }} |
| 38 | + cache: pip |
| 39 | + - run: python -m pip install build |
| 40 | + name: Install core libraries for build and install |
| 41 | + - name: Build artifacts |
| 42 | + run: python -m build |
| 43 | + - name: Upload built artifacts for testing |
| 44 | + uses: actions/upload-artifact@v4 |
| 45 | + with: |
| 46 | + name: ${{ env.sdist-artifact }} |
| 47 | + # NOTE: Exact expected file names are specified here |
| 48 | + # NOTE: as a safety measure — if anything weird ends |
| 49 | + # NOTE: up being in this dir or not all dists will be |
| 50 | + # NOTE: produced, this will fail the workflow. |
| 51 | + path: dist/${{ env.sdist-name }} |
| 52 | + retention-days: 15 |
| 53 | + |
| 54 | + test-python: |
| 55 | + name: Tests on ${{ matrix.python-version }} |
| 56 | + needs: |
| 57 | + - build-sdist |
| 58 | + runs-on: ubuntu-latest |
| 59 | + continue-on-error: ${{ matrix.experimental }} |
| 60 | + strategy: |
| 61 | + fail-fast: false |
| 62 | + matrix: |
| 63 | + python-version: |
| 64 | + - "3.8" |
| 65 | + - "3.9" |
| 66 | + - "3.10" |
| 67 | + - "3.11" |
| 68 | + - "3.12" |
| 69 | + - "pypy3.9" |
| 70 | + experimental: [ false ] |
| 71 | + include: |
| 72 | + - python-version: "~3.13.0-0" |
| 73 | + experimental: true |
| 74 | + steps: |
| 75 | + - name: Checkout the source code |
| 76 | + uses: actions/checkout@v4 |
| 77 | + with: |
| 78 | + fetch-depth: 0 |
| 79 | + - name: Setup java |
| 80 | + uses: actions/setup-java@v4 |
| 81 | + with: |
| 82 | + distribution: temurin |
| 83 | + java-version: 11 |
| 84 | + - name: Set up Python |
| 85 | + uses: actions/setup-python@v5 |
| 86 | + with: |
| 87 | + python-version: ${{ matrix.python-version }} |
| 88 | + cache: pip |
| 89 | + cache-dependency-path: | |
| 90 | + requirements-dev.txt |
| 91 | + - name: Check Java installation |
| 92 | + run: source travis_java_install.sh |
| 93 | + - name: Pull Kafka releases |
| 94 | + run: ./build_integration.sh |
| 95 | + env: |
| 96 | + PLATFORM: ${{ matrix.platform }} |
| 97 | + KAFKA_VERSION: ${{ env.KAFKA_LATEST }} |
| 98 | + # TODO: Cache releases to expedite testing |
| 99 | + - name: Install dependencies |
| 100 | + run: | |
| 101 | + sudo apt install -y libsnappy-dev libzstd-dev |
| 102 | + python -m pip install --upgrade pip |
| 103 | + python -m pip install tox tox-gh-actions |
| 104 | + pip install . |
| 105 | + pip install -r requirements-dev.txt |
| 106 | + - name: Test with tox |
| 107 | + run: tox |
| 108 | + env: |
| 109 | + PLATFORM: ${{ matrix.platform }} |
| 110 | + KAFKA_VERSION: ${{ env.KAFKA_LATEST }} |
| 111 | + |
| 112 | + test-kafka: |
| 113 | + name: Tests for Kafka ${{ matrix.kafka-version }} |
| 114 | + needs: |
| 115 | + - build-sdist |
| 116 | + runs-on: ubuntu-latest |
| 117 | + timeout-minutes: 10 |
| 118 | + strategy: |
| 119 | + fail-fast: false |
| 120 | + matrix: |
| 121 | + kafka-version: |
| 122 | + - "0.9.0.1" |
| 123 | + - "0.10.2.2" |
| 124 | + - "0.11.0.2" |
| 125 | + - "0.11.0.3" |
| 126 | + - "1.1.1" |
| 127 | + - "2.4.0" |
| 128 | + - "2.5.0" |
| 129 | + - "2.6.0" |
| 130 | + experimental: [false] |
| 131 | + include: |
| 132 | + - kafka-version: '0.8.2.2' |
| 133 | + experimental: true |
| 134 | + continue-on-error: ${{ matrix.experimental }} |
| 135 | + steps: |
| 136 | + - name: Checkout the source code |
| 137 | + uses: actions/checkout@v4 |
| 138 | + with: |
| 139 | + fetch-depth: 0 |
| 140 | + - name: Setup java |
| 141 | + uses: actions/setup-java@v4 |
| 142 | + with: |
| 143 | + distribution: temurin |
| 144 | + java-version: 8 |
| 145 | + - name: Set up Python |
| 146 | + uses: actions/setup-python@v5 |
| 147 | + with: |
| 148 | + python-version: ${{ env.PYTHON_LATEST }} |
| 149 | + cache: pip |
| 150 | + cache-dependency-path: | |
| 151 | + requirements-dev.txt |
| 152 | + - name: Pull Kafka releases |
| 153 | + run: ./build_integration.sh |
| 154 | + env: |
| 155 | + # This is fast enough as long as you pull only one release at a time, |
| 156 | + # no need to worry about caching |
| 157 | + PLATFORM: ${{ matrix.platform }} |
| 158 | + KAFKA_VERSION: ${{ matrix.kafka-version }} |
| 159 | + - name: Install dependencies |
| 160 | + run: | |
| 161 | + sudo apt install -y libsnappy-dev libzstd-dev |
| 162 | + python -m pip install --upgrade pip |
| 163 | + python -m pip install tox tox-gh-actions |
| 164 | + pip install . |
| 165 | + pip install -r requirements-dev.txt |
| 166 | + - name: Test with tox |
| 167 | + run: tox |
| 168 | + env: |
| 169 | + PLATFORM: ${{ matrix.platform }} |
| 170 | + KAFKA_VERSION: ${{ matrix.kafka-version }} |
| 171 | + |
| 172 | + check: # This job does nothing and is only used for the branch protection |
| 173 | + name: ✅ Ensure the required checks passing |
| 174 | + if: always() |
| 175 | + needs: |
| 176 | + - build-sdist |
| 177 | + - test-python |
| 178 | + - test-kafka |
| 179 | + runs-on: ubuntu-latest |
| 180 | + steps: |
| 181 | + - name: Decide whether the needed jobs succeeded or failed |
| 182 | + uses: re-actors/alls-green@release/v1 |
| 183 | + with: |
| 184 | + jobs: ${{ toJSON(needs) }} |
| 185 | + publish: |
| 186 | + name: 📦 Publish to PyPI |
| 187 | + runs-on: ubuntu-latest |
| 188 | + needs: [build-sdist] |
| 189 | + permissions: |
| 190 | + id-token: write |
| 191 | + environment: pypi |
| 192 | + if: github.event_name == 'release' && github.event.action == 'created' |
| 193 | + steps: |
| 194 | + - name: Download the artifacts |
| 195 | + uses: actions/download-artifact@v4 |
| 196 | + with: |
| 197 | + name: ${{ env.sdist-artifact }} |
| 198 | + path: dist/${{ env.sdist-name }} |
| 199 | + - name: Publish package to PyPI |
| 200 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 201 | + with: |
| 202 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments