name: CLI Python wheels run-name: ${{ github.event.pull_request.title || format('CLI Python wheels for {0}', github.event.workflow_run.head_branch || inputs.tag) }} on: workflow_run: workflows: [GitHub Release] types: [completed] pull_request: paths: - ci/cli_wheel/** - ci/build_cli_wheels.py - ci/package_cli.py - .github/workflows/cli-wheels.yml workflow_dispatch: inputs: tag: description: Published CLI release to package required: true default: v0.42.0-beta.30 publish: description: Request approval to publish these stable wheels to PyPI type: boolean default: false permissions: contents: read env: CLI_TAG: ${{ github.event.workflow_run.head_branch || inputs.tag || 'v0.42.1' }} jobs: select-release: if: >- github.event_name != 'workflow_run' || ( github.repository == 'lancedb/lancedb' && github.event.workflow_run.head_repository.full_name == github.repository && github.event.workflow_run.event == 'push' && startsWith(github.event.workflow_run.head_branch, 'v') && !contains(github.event.workflow_run.head_branch, '-')) runs-on: ubuntu-24.04 permissions: actions: read outputs: published: ${{ steps.release.outputs.published }} steps: - name: Check that this attempt published the CLI archives id: release if: github.event_name == 'workflow_run' shell: bash env: GH_TOKEN: ${{ github.token }} RUN_ID: ${{ github.event.workflow_run.id }} ATTEMPT: ${{ github.event.workflow_run.run_attempt }} run: | # Homebrew runs independently. A retry of just that job should not start another wheel build. published=$(gh api --paginate --slurp \ "repos/$GITHUB_REPOSITORY/actions/runs/$RUN_ID/attempts/$ATTEMPT/jobs" | jq --argjson attempt "$ATTEMPT" 'any(.[].jobs[]; .name == "gh-release" and .run_attempt == $attempt and .conclusion == "success")') echo "published=$published" >> "$GITHUB_OUTPUT" build: needs: select-release if: github.event_name != 'workflow_run' || needs.select-release.outputs.published == 'true' runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v6 with: persist-credentials: false - uses: actions/setup-python@v6 with: python-version: '3.13' - name: Test stable publishing checks run: bash ci/cli_wheel/test_publish_checks.sh - run: python -m pip install wheel==0.48.0 build - name: Build wheels from published release archives env: GH_TOKEN: ${{ github.token }} run: | gh release download --repo lancedb/lancedb --dir archives \ --pattern 'lancedb-*.tar.gz' --pattern SHA256SUMS -- "$CLI_TAG" python -m ci.build_cli_wheels "$CLI_TAG" archives wheels - name: Resolve the published CLI source env: GH_TOKEN: ${{ github.token }} RELEASE_SHA: ${{ github.event.workflow_run.head_sha }} shell: bash run: | gh api "repos/lancedb/lancedb/releases/tags/$CLI_TAG" | jq -e --arg tag "$CLI_TAG" '.tag_name == $tag and .draft == false and .published_at != null' commit=$(gh api "repos/lancedb/lancedb/commits/refs/tags/$CLI_TAG" --jq .sha) [[ "$commit" =~ ^[0-9a-f]{40}$ ]] || exit 1 if [[ -n "$RELEASE_SHA" && "$commit" != "$RELEASE_SHA" ]]; then echo "The release tag no longer points to the commit that published it." >&2 exit 1 fi echo "CLI_SOURCE_COMMIT=$commit" >> "$GITHUB_ENV" - name: Package source from the matching release tag run: | git fetch --depth=1 --no-tags https://github.com/lancedb/lancedb.git "$CLI_SOURCE_COMMIT" bash ci/cli_wheel/build_sdist.sh "$CLI_SOURCE_COMMIT" "$CLI_TAG" sdist - uses: actions/upload-artifact@v7 with: name: lancedb-tools-sdist path: sdist/*.tar.gz if-no-files-found: error - uses: actions/upload-artifact@v7 with: name: lancedb-tools-wheels path: wheels/*.whl if-no-files-found: error compression-level: 0 install: needs: build strategy: fail-fast: false matrix: os: [macos-15, ubuntu-24.04, ubuntu-24.04-arm] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v6 with: persist-credentials: false - uses: actions/setup-python@v6 with: python-version: '3.13' - uses: actions/download-artifact@v8 with: name: lancedb-tools-wheels path: wheels - run: python -m pip install uv==0.13.9 pipx==1.19.0 - name: Install and exercise the native CLI with uvx and pipx run: bash ci/cli_wheel/test_install.sh "$CLI_TAG" "$PWD/wheels" install-source: needs: build runs-on: macos-15-intel timeout-minutes: 180 steps: - uses: actions/checkout@v6 with: persist-credentials: false - uses: actions/setup-python@v6 with: python-version: '3.13' - uses: ./.github/actions/setup-protoc - uses: actions/download-artifact@v8 with: pattern: lancedb-tools-* merge-multiple: true path: dist - name: Install from the release distributions on Intel macOS shell: bash run: | test "$(uname -m)" = x86_64 cd "$RUNNER_TEMP" python -m venv cli-env cli-env/bin/python -m pip download --only-binary=:all: --dest build-tools setuptools setuptools-rust wheel version=${CLI_TAG#v} cli-env/bin/python -m pip install -v --no-cache-dir --no-index --find-links build-tools \ --find-links "$GITHUB_WORKSPACE/dist" --report install.json "lancedb-tools==${version/-beta./b}" jq -e 'any(.install[]; .metadata.name == "lancedb-tools" and (.download_info.url | endswith(".tar.gz")))' install.json test "$(lipo -archs cli-env/bin/lancedb)" = x86_64 cli-env/bin/lancedb --version | grep -Fx "lancedb $version" cli-env/bin/lancedb profile list | grep -w local check-publish: needs: build if: github.ref == 'refs/heads/main' && (github.event_name == 'workflow_run' || inputs.publish) runs-on: ubuntu-24.04 permissions: actions: read contents: read steps: - uses: actions/checkout@v6 with: persist-credentials: false - name: Verify stable release and required environment approval env: GH_TOKEN: ${{ github.token }} run: bash ci/cli_wheel/check_publish.sh "$CLI_TAG" publish: name: Publish ${{ github.event.workflow_run.head_branch || inputs.tag }} to PyPI needs: [install, install-source, check-publish] runs-on: ubuntu-24.04 environment: name: pypi-cli url: https://pypi.org/project/lancedb-tools/ concurrency: pypi-lancedb-tools-${{ github.event.workflow_run.head_branch || inputs.tag }} permissions: id-token: write steps: - uses: actions/download-artifact@v8 with: pattern: lancedb-tools-* merge-multiple: true path: dist - name: Upload tested distributions uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3 with: # A retry of this job can finish a partially uploaded release. skip-existing: true - name: Verify the published distribution checksums working-directory: dist run: | curl --fail --silent --show-error --retry 5 --retry-all-errors \ "https://pypi.org/pypi/lancedb-tools/${CLI_TAG#v}/json" -o "$RUNNER_TEMP/pypi.json" for file in *.whl *.tar.gz; do digest=$(jq -er --arg file "$file" '.urls[] | select(.filename == $file) | .digests.sha256' "$RUNNER_TEMP/pypi.json") echo "$digest $file" | sha256sum --check done