diff --git a/.github/workflows/wheel.yaml b/.github/workflows/wheel.yaml index f91659730..69dc66a83 100644 --- a/.github/workflows/wheel.yaml +++ b/.github/workflows/wheel.yaml @@ -1,102 +1,73 @@ -name: Build wheel +name: Build and test Linux wheels on: - push: - branches: [ main ] pull_request: + push: + branches: + - nightly + - main + - release/* + tags: + - v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+ + workflow_dispatch: concurrency: - group: unit-test${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_number || github.ref }} + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }} cancel-in-progress: true +permissions: + id-token: write + contents: write + defaults: run: shell: bash -l -eo pipefail {0} jobs: + generate-matrix: + uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main + with: + package-type: wheel + os: linux + test-infra-repository: pytorch/test-infra + test-infra-ref: main + with-xpu: disable + with-rocm: disable + with-cuda: disable build: - runs-on: ubuntu-20.04 + needs: generate-matrix strategy: fail-fast: false - matrix: - python-version: ['3.8', '3.12'] - steps: - - name: Check out repo - uses: actions/checkout@v3 - - name: Setup conda env - uses: conda-incubator/setup-miniconda@v2 - with: - auto-update-conda: true - miniconda-version: "latest" - activate-environment: test - python-version: ${{ matrix.python-version }} - - name: Update pip - run: python -m pip install --upgrade pip - - name: Install Pytorch - run: | - python -m pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu - - name: Check GCC version - run: | - # We want to build wheels on gcc 9 to be consistent with the torch - # binaries, which is why we're using ubuntu-20.04 and not - # ubuntu-latest. More details below about the GLIBCXX checks. - if ! gcc --version | grep -q -E "9\.[0-9]+\.[0-9]+" - then - echo "Wrong GCC version, exiting!" - gcc --version - exit 1 - fi - - name: Build the torchcodec wheel - run: | - # Just for sanity, make sure FFmpeg isn't installed or needed for buidling. - .github/scripts/assert_ffmpeg_not_installed.sh - - python -m pip install build - BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1 python -m build . -vvv --no-isolation - - name: Validate wheel content - run: | - source .github/scripts/helpers.sh - wheel_path=$(pwd)/$(find dist -type f -name "*.whl") - echo "Wheel content:" - unzip -l $wheel_path - - for ffmpeg_major_version in 4 5 6 7; do - assert_in_wheel $wheel_path torchcodec/libtorchcodec${ffmpeg_major_version}.so - done - assert_not_in_wheel $wheel_path libtorchcodec.so - - for ffmpeg_so in libavcodec.so libavfilter.so libavformat.so libavutil.so libavdevice.so ; do - assert_not_in_wheel $wheel_path $ffmpeg_so - done - - assert_not_in_wheel $wheel_path "^test" - assert_not_in_wheel $wheel_path "^doc" - assert_not_in_wheel $wheel_path "^benchmarks" - - # See invoked python script below for details about this check. - extracted_wheel_dir=$(mktemp -d) - unzip -q $wheel_path -d $extracted_wheel_dir - symbols_matches=$(find $extracted_wheel_dir | grep ".so$" | xargs objdump --syms | grep GLIBCXX_3.4.) - python .github/scripts/check_glibcxx.py "$symbols_matches" - - uses: actions/upload-artifact@v4 - with: - name: sdist-and-wheel-linux_x86_${{ matrix.python-version }} - path: dist/* + name: Build and Upload wheel + uses: pytorch/test-infra/.github/workflows/build_wheels_linux.yml@main + with: + repository: pytorch/torchcodec + ref: "" + test-infra-repository: pytorch/test-infra + test-infra-ref: main + build-matrix: ${{ needs.generate-matrix.outputs.matrix }} + post-script: packaging/post_build_script.sh + env-var-script: packaging/env_var_script.sh + smoke-test-script: packaging/fake_smoke_test.py + package-name: torchcodec + trigger-event: ${{ github.event_name }} + build-platform: "python-build-package" + wheel-build-extra-args: "-vvv --no-isolation" install-and-test: runs-on: ubuntu-latest strategy: fail-fast: false matrix: - python-version: ['3.8', '3.12'] + python-version: ['3.9'] ffmpeg-version-for-tests: ['4.4.2', '5.1.2', '6.1.1', '7.0.1'] if: ${{ always() }} needs: build steps: - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v3 with: - name: sdist-and-wheel-linux_x86_${{ matrix.python-version }} - path: dist/ + name: pytorch_torchcodec__${{ matrix.python-version }}_cpu_x86_64 + path: pytorch/torchcodec/dist/ - name: Setup conda env uses: conda-incubator/setup-miniconda@v2 with: @@ -111,7 +82,7 @@ jobs: python -m pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu - name: Install torchcodec from the wheel run: | - wheel_path=`find dist -type f -name "*.whl"` + wheel_path=`find pytorch/torchcodec/dist -type f -name "*.whl"` echo Installing $wheel_path python -m pip install $wheel_path -vvv diff --git a/packaging/env_var_script.sh b/packaging/env_var_script.sh new file mode 100644 index 000000000..f94c490a8 --- /dev/null +++ b/packaging/env_var_script.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +export BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1 diff --git a/packaging/fake_smoke_test.py b/packaging/fake_smoke_test.py new file mode 100644 index 000000000..ac1be55ef --- /dev/null +++ b/packaging/fake_smoke_test.py @@ -0,0 +1,7 @@ +# This is a fake smoke test that runs on the test-infra instances after we build +# a wheel. We cannot run a real smoke test over there, because the machines are +# too old to even install a proper ffmpeg version - and without ffmpeg, +# importing torchcodec just fails. It's OK, we run our *entire* test suite on +# those wheels anyway (on other machines). + +print("Success") diff --git a/packaging/post_build_script.sh b/packaging/post_build_script.sh new file mode 100755 index 000000000..688d88771 --- /dev/null +++ b/packaging/post_build_script.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +source .github/scripts/helpers.sh + +wheel_path=$(pwd)/$(find dist -type f -name "*.whl") +echo "Wheel content:" +unzip -l $wheel_path + +for ffmpeg_major_version in 4 5 6 7; do + assert_in_wheel $wheel_path torchcodec/libtorchcodec${ffmpeg_major_version}.so +done +assert_not_in_wheel $wheel_path libtorchcodec.so + +for ffmpeg_so in libavcodec.so libavfilter.so libavformat.so libavutil.so libavdevice.so ; do + assert_not_in_wheel $wheel_path $ffmpeg_so +done + +assert_not_in_wheel $wheel_path "^test" +assert_not_in_wheel $wheel_path "^doc" +assert_not_in_wheel $wheel_path "^benchmarks" +assert_not_in_wheel $wheel_path "^packaging" + +# See invoked python script below for details about this check. +extracted_wheel_dir=$(mktemp -d) +unzip -q $wheel_path -d $extracted_wheel_dir +symbols_matches=$(find $extracted_wheel_dir | grep ".so$" | xargs objdump --syms | grep GLIBCXX_3.4.) +python .github/scripts/check_glibcxx.py "$symbols_matches" + +echo "ls dist" +ls dist + +old="linux_x86_64" +new="manylinux_2_17_x86_64.manylinux2014_x86_64" +echo "Replacing ${old} with ${new} in wheel name" +mv dist/*${old}*.whl $(echo dist/*${old}*.whl | sed "s/${old}/${new}/") + +echo "ls dist" +ls dist