diff --git a/.bazelrc b/.bazelrc index acfc7bdda..90e765307 100644 --- a/.bazelrc +++ b/.bazelrc @@ -23,5 +23,6 @@ build --protocopt=--experimental_allow_proto3_optional # parameter 'user_link_flags' is deprecated and will be removed soon. # It may be temporarily re-enabled by setting --incompatible_require_linker_input_cc_api=false build --incompatible_require_linker_input_cc_api=false + build:macos --apple_platform_type=macos build:macos_arm64 --cpu=darwin_arm64 diff --git a/.github/workflows/conda-build.yml b/.github/workflows/conda-build.yml new file mode 100644 index 000000000..ea35e03d0 --- /dev/null +++ b/.github/workflows/conda-build.yml @@ -0,0 +1,97 @@ +name: Build ml-metadata with Conda + +on: + push: + branches: + - master + pull_request: + branches: + - master + workflow_dispatch: + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + python-version: ["3.9", "3.10", "3.11"] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Micromamba + uses: mamba-org/setup-micromamba@v1 + with: + environment-file: ci/environment.yml + cache-environment: true + create-args: >- + python=${{ matrix.python-version }} + + - name: Display environment info + shell: bash -l {0} + run: | + micromamba info + micromamba list + + - name: Install Bazel + shell: bash -l {0} + run: | + # Install Bazelisk (manages Bazel versions) + if [ "$RUNNER_OS" == "Linux" ]; then + curl -Lo /tmp/bazelisk https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64 + elif [ "$RUNNER_OS" == "macOS" ]; then + curl -Lo /tmp/bazelisk https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-darwin-amd64 + fi + chmod +x /tmp/bazelisk + sudo mv /tmp/bazelisk /usr/local/bin/bazel + echo "USE_BAZEL_VERSION=6.1.0" >> $GITHUB_ENV + bazel --version + + - name: Build the package + shell: bash -l {0} + run: | + python setup.py bdist_wheel + + - name: Repair wheel (Linux) + if: runner.os == 'Linux' + shell: bash -l {0} + run: | + WHEEL_PATH="$(ls dist/*.whl)" + WHEEL_DIR=$(dirname "${WHEEL_PATH}") + auditwheel repair --plat manylinux2014_x86_64 -w "${WHEEL_DIR}" "${WHEEL_PATH}" + rm "${WHEEL_PATH}" + + - name: Upload wheel artifact + uses: actions/upload-artifact@v4.4.0 + with: + name: ml-metadata-wheel-${{ matrix.os }}-py${{ matrix.python-version }} + path: dist/*.whl + + upload_to_pypi: + name: Upload to PyPI + runs-on: ubuntu-latest + if: (github.event_name == 'release' && startsWith(github.ref, 'refs/tags')) || (github.event_name == 'workflow_dispatch') + needs: [build] + environment: + name: pypi + url: https://pypi.org/p/ml-metadata/ + permissions: + id-token: write + steps: + - name: Retrieve wheels + uses: actions/download-artifact@v4.1.8 + with: + merge-multiple: true + path: wheels + + - name: List the build artifacts + run: | + ls -lAs wheels/ + + - name: Upload to PyPI + uses: pypa/gh-action-pypi-publish@release/v1.9 + with: + packages_dir: wheels/ diff --git a/.github/workflows/conda-test.yml b/.github/workflows/conda-test.yml new file mode 100644 index 000000000..77ec6d543 --- /dev/null +++ b/.github/workflows/conda-test.yml @@ -0,0 +1,69 @@ +name: Test ml-metadata with Conda + +on: + push: + branches: + - master + pull_request: + branches: + - master + workflow_dispatch: + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + python-version: ["3.9", "3.10", "3.11"] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Micromamba + uses: mamba-org/setup-micromamba@v1 + with: + environment-file: ci/environment.yml + cache-environment: true + create-args: >- + python=${{ matrix.python-version }} + + - name: Display environment info + shell: bash -l {0} + run: | + micromamba info + micromamba list + + - name: Install Bazel + shell: bash -l {0} + run: | + # Install Bazelisk (manages Bazel versions) + if [ "$RUNNER_OS" == "Linux" ]; then + curl -Lo /tmp/bazelisk https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64 + elif [ "$RUNNER_OS" == "macOS" ]; then + curl -Lo /tmp/bazelisk https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-darwin-amd64 + fi + chmod +x /tmp/bazelisk + sudo mv /tmp/bazelisk /usr/local/bin/bazel + echo "USE_BAZEL_VERSION=6.1.0" >> $GITHUB_ENV + bazel --version + + - name: Build the package + shell: bash -l {0} + run: | + python setup.py bdist_wheel + + - name: Install built wheel (Linux/macOS) + shell: bash -l {0} + run: | + pip install dist/*.whl + + - name: Run tests + shell: bash -l {0} + run: | + # cleanup (interferes with tests) + rm -rf bazel-* + # run tests + pytest -vv diff --git a/ci/environment.yml b/ci/environment.yml new file mode 100644 index 000000000..113408e3f --- /dev/null +++ b/ci/environment.yml @@ -0,0 +1,22 @@ +# Conda environment for building and testing ml-metadata on Linux +name: mlmd-dev +channels: + - conda-forge +dependencies: + # Note: Bazel is installed separately via official installer (conda package is unreliable) + - setuptools + - wheel + - pip + - numpy + - pytest + - pytest-cov + - patchelf # For wheel repair on Linux + - cmake=3.29 + + # C/C++ compilers - GCC 8.x to match manylinux2014 devtoolset-8 + - gcc_linux-64=8.5.0 + - gxx_linux-64=8.5.0 + - sysroot_linux-64=2.17 # CentOS 7/manylinux2014 compatible glibc headers + + - pip: + - auditwheel # For manylinux wheel compliance