|
| 1 | +name: Build Wheels for Paddle |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [paddle] |
| 6 | + tags: ["v*"] |
| 7 | + pull_request: |
| 8 | + merge_group: |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +permissions: |
| 16 | + id-token: write |
| 17 | + contents: write |
| 18 | + |
| 19 | +defaults: |
| 20 | + run: |
| 21 | + shell: bash -l -eo pipefail {0} |
| 22 | + |
| 23 | +jobs: |
| 24 | + build-paddlecodec-wheel: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + container: |
| 27 | + image: pytorch/manylinux2_28-builder:cpu |
| 28 | + strategy: |
| 29 | + fail-fast: false |
| 30 | + matrix: |
| 31 | + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] |
| 32 | + permissions: |
| 33 | + id-token: write |
| 34 | + contents: read |
| 35 | + steps: |
| 36 | + - name: Checkout repository |
| 37 | + uses: actions/checkout@v6 |
| 38 | + |
| 39 | + - name: Setup conda environment |
| 40 | + uses: conda-incubator/setup-miniconda@v3 |
| 41 | + with: |
| 42 | + auto-update-conda: true |
| 43 | + miniforge-version: latest |
| 44 | + activate-environment: build |
| 45 | + python-version: ${{ matrix.python-version }} |
| 46 | + |
| 47 | + - name: Install build dependencies |
| 48 | + run: | |
| 49 | + python -m pip install --upgrade pip |
| 50 | + pip install build wheel setuptools |
| 51 | +
|
| 52 | + - name: Install PaddlePaddle nightly |
| 53 | + run: | |
| 54 | + pip install --pre paddlepaddle -i https://www.paddlepaddle.org.cn/packages/nightly/cpu/ |
| 55 | +
|
| 56 | + - name: Run pre-build script |
| 57 | + run: | |
| 58 | + bash packaging/pre_build_script.sh |
| 59 | +
|
| 60 | + - name: Build wheel |
| 61 | + run: | |
| 62 | + # Use pre-built FFmpeg from PyTorch S3 |
| 63 | + export BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1 |
| 64 | + export TORCHCODEC_CMAKE_BUILD_DIR=$(pwd)/build_cmake |
| 65 | + python -m build --wheel -vvv --no-isolation |
| 66 | +
|
| 67 | + - name: Repair wheel |
| 68 | + run: | |
| 69 | + pip install auditwheel |
| 70 | +
|
| 71 | + # 1. Extract internal libraries from the wheel to a temporary directory |
| 72 | + # This allows auditwheel to find them when checking dependencies |
| 73 | + mkdir -p temp_libs |
| 74 | + unzip -j dist/*.whl "torchcodec/*.so" -d temp_libs || true |
| 75 | +
|
| 76 | + # 2. Prepare LD_LIBRARY_PATH |
| 77 | + # FFmpeg libraries |
| 78 | + FFMPEG_LIB_PATHS=$(find $(pwd)/build_cmake/_deps -type d -name "lib" | tr '\n' ':') |
| 79 | + # PaddlePaddle libraries |
| 80 | + PADDLE_PATH=$(python -c "import paddle; print(paddle.__path__[0])") |
| 81 | + PADDLE_LIB_PATHS="$PADDLE_PATH/base:$PADDLE_PATH/libs" |
| 82 | + # Wheel internal libraries |
| 83 | + INTERNAL_LIB_PATH=$(pwd)/temp_libs |
| 84 | +
|
| 85 | + export LD_LIBRARY_PATH=${FFMPEG_LIB_PATHS}${PADDLE_LIB_PATHS}:${INTERNAL_LIB_PATH}:${LD_LIBRARY_PATH} |
| 86 | +
|
| 87 | + # 3. Repair wheel with auditwheel |
| 88 | + # We exclude all external libraries because we want to rely on system libraries (like FFmpeg) |
| 89 | + # or libraries provided by other packages (like PaddlePaddle). |
| 90 | + # auditwheel 6.1.0+ supports wildcards in --exclude. |
| 91 | + auditwheel repair dist/*.whl --plat manylinux_2_28_x86_64 -w wheelhouse/ --exclude "*" |
| 92 | +
|
| 93 | + # Cleanup |
| 94 | + rm -rf temp_libs |
| 95 | + rm dist/*.whl |
| 96 | + mv wheelhouse/*.whl dist/ |
| 97 | + rmdir wheelhouse |
| 98 | +
|
| 99 | + - name: Upload wheel artifact |
| 100 | + uses: actions/upload-artifact@v5 |
| 101 | + with: |
| 102 | + name: paddlecodec-wheel-linux-py${{ matrix.python-version }} |
| 103 | + path: dist/*.whl |
| 104 | + |
| 105 | + - name: Run post-build script |
| 106 | + run: | |
| 107 | + bash packaging/post_build_script.sh |
| 108 | +
|
| 109 | + - name: List wheel contents |
| 110 | + run: | |
| 111 | + wheel_path=$(find dist -type f -name "*.whl") |
| 112 | + echo "Wheel path: $wheel_path" |
| 113 | + unzip -l $wheel_path |
| 114 | +
|
| 115 | + test-paddlecodec-wheel: |
| 116 | + needs: build-paddlecodec-wheel |
| 117 | + runs-on: ubuntu-latest |
| 118 | + strategy: |
| 119 | + fail-fast: false |
| 120 | + matrix: |
| 121 | + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] |
| 122 | + # FFmpeg 8.0 depends on libopenvino.so.2520, PaddlePaddle CPU depends on libopenvino.so.2500 |
| 123 | + # There has some conflict causing test failures, but it works with PaddlePaddle GPU. |
| 124 | + # We skip FFmpeg 8.0 tests for PaddlePaddle CPU builds for now. |
| 125 | + ffmpeg-version: ["4.4.2", "5.1.2", "6.1.1", "7.0.1"] |
| 126 | + steps: |
| 127 | + - name: Checkout repository |
| 128 | + uses: actions/checkout@v6 |
| 129 | + |
| 130 | + - name: Set up Python ${{ matrix.python-version }} |
| 131 | + uses: actions/setup-python@v5 |
| 132 | + with: |
| 133 | + python-version: ${{ matrix.python-version }} |
| 134 | + |
| 135 | + - name: Download wheel artifact |
| 136 | + uses: actions/download-artifact@v4 |
| 137 | + with: |
| 138 | + name: paddlecodec-wheel-linux-py${{ matrix.python-version }} |
| 139 | + path: dist/ |
| 140 | + |
| 141 | + - name: Install FFmpeg via conda |
| 142 | + uses: conda-incubator/setup-miniconda@v3 |
| 143 | + with: |
| 144 | + auto-update-conda: true |
| 145 | + miniforge-version: latest |
| 146 | + activate-environment: test |
| 147 | + python-version: ${{ matrix.python-version }} |
| 148 | + |
| 149 | + - name: Install FFmpeg from conda-forge |
| 150 | + run: | |
| 151 | + conda install "ffmpeg=${{ matrix.ffmpeg-version }}" -c conda-forge -y |
| 152 | + ffmpeg -version |
| 153 | +
|
| 154 | + - name: Install PaddlePaddle nightly in conda env |
| 155 | + run: | |
| 156 | + pip install --pre paddlepaddle -i https://www.paddlepaddle.org.cn/packages/nightly/cpu/ |
| 157 | +
|
| 158 | + - name: Install paddlecodec from wheel |
| 159 | + run: | |
| 160 | + wheel_path=$(find dist -type f -name "*.whl") |
| 161 | + echo "Installing $wheel_path" |
| 162 | + pip install $wheel_path -vvv |
| 163 | +
|
| 164 | + - name: Install test dependencies |
| 165 | + run: | |
| 166 | + pip install numpy pytest pillow |
| 167 | +
|
| 168 | + - name: Delete src folder |
| 169 | + run: | |
| 170 | + # Delete src/ to ensure we're testing the installed wheel, not source code |
| 171 | + rm -rf src/ |
| 172 | + ls -la |
| 173 | +
|
| 174 | + - name: Run tests |
| 175 | + run: | |
| 176 | + pytest --override-ini="addopts=-v" -s test_paddle |
| 177 | +
|
| 178 | + publish-pypi: |
| 179 | + runs-on: ubuntu-latest |
| 180 | + name: Publish to PyPI |
| 181 | + if: "startsWith(github.ref, 'refs/tags/')" |
| 182 | + needs: |
| 183 | + - test-paddlecodec-wheel |
| 184 | + permissions: |
| 185 | + id-token: write |
| 186 | + |
| 187 | + steps: |
| 188 | + - name: Retrieve release distributions |
| 189 | + uses: actions/download-artifact@v6 |
| 190 | + with: |
| 191 | + pattern: paddlecodec-wheel-linux-* |
| 192 | + path: dist/ |
| 193 | + merge-multiple: true |
| 194 | + |
| 195 | + - name: Publish release distributions to PyPI |
| 196 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 197 | + |
| 198 | + publish-release: |
| 199 | + runs-on: ubuntu-latest |
| 200 | + name: Publish to GitHub |
| 201 | + if: "startsWith(github.ref, 'refs/tags/')" |
| 202 | + needs: |
| 203 | + - test-paddlecodec-wheel |
| 204 | + permissions: |
| 205 | + contents: write |
| 206 | + steps: |
| 207 | + - uses: actions/download-artifact@v6 |
| 208 | + with: |
| 209 | + pattern: paddlecodec-wheel-linux-* |
| 210 | + path: dist/ |
| 211 | + merge-multiple: true |
| 212 | + - name: Get tag name |
| 213 | + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV |
| 214 | + - name: Publish to GitHub |
| 215 | + uses: softprops/action-gh-release@v2 |
| 216 | + with: |
| 217 | + draft: true |
| 218 | + files: dist/* |
| 219 | + tag_name: ${{ env.RELEASE_VERSION }} |
0 commit comments