name: XGBoost-Python-Wheels

on: [push, pull_request]

permissions:
  contents: read # to fetch code (actions/checkout)

defaults:
  run:
    shell: bash -l {0}

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  python-wheels:
    name: Build wheel for ${{ matrix.platform_id }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
        - os: macos-13
          platform_id: macosx_x86_64
        - os: macos-14
          platform_id: macosx_arm64
    steps:
    - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
      with:
        submodules: 'true'
    - name: Set up homebrew
      uses: Homebrew/actions/setup-homebrew@68fa6aeb1ccb0596d311f2b34ec74ec21ee68e54
    - name: Install libomp
      run: brew install libomp
    - uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca  # v3.0.4
      with:
        miniforge-variant: Mambaforge
        miniforge-version: latest
        python-version: "3.10"
        use-mamba: true
    - name: Build wheels
      run: bash tests/ci_build/build_python_wheels.sh ${{ matrix.platform_id }} ${{ github.sha }}
    - name: Extract branch name
      run: |
        echo "branch=${GITHUB_REF#refs/heads/}" >> "$GITHUB_OUTPUT"
      id: extract_branch
      if: github.ref == 'refs/heads/master' || contains(github.ref, 'refs/heads/release_')
    - name: Upload Python wheel
      if: github.ref == 'refs/heads/master' || contains(github.ref, 'refs/heads/release_')
      run: |
        python -m pip install awscli
        python -m awscli s3 cp wheelhouse/*.whl s3://xgboost-nightly-builds/${{ steps.extract_branch.outputs.branch }}/ --acl public-read --region us-west-2
      env:
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_IAM_S3_UPLOADER }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_IAM_S3_UPLOADER }}
