kingfisher/.github/workflows/pypi.yml
2026-02-16 07:34:32 -08:00

137 lines
4.2 KiB
YAML

name: pypi-wheels
on:
workflow_run:
workflows: ["Publish Docker image"]
types: [completed]
workflow_dispatch:
inputs:
tag:
description: "Release tag to package (e.g., v1.2.3). Leave blank to use Cargo.toml."
required: false
type: string
jobs:
build-wheels:
name: Build PyPI wheels
if: >
github.event_name != 'workflow_run' ||
github.event.workflow_run.conclusion == 'success' ||
github.run_attempt > 1
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }}
- name: Determine version/tag
id: version
shell: bash
env:
INPUT_TAG: ${{ github.event.inputs.tag || '' }}
run: |
set -euo pipefail
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" && -n "${INPUT_TAG}" ]]; then
TAG="${INPUT_TAG}"
else
VERSION=$(grep -m1 '^version\s*=' Cargo.toml | cut -d '"' -f2)
TAG="v${VERSION}"
fi
if [[ ! "${TAG}" =~ ^v[0-9A-Za-z._+-]+$ ]]; then
echo "Invalid tag format: ${TAG}" >&2
exit 1
fi
VERSION="${TAG#v}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Download release assets
env:
GH_TOKEN: ${{ github.token }}
run: |
mkdir -p release-assets
gh release download "${{ steps.version.outputs.tag }}" \
-p "kingfisher-*.tgz" \
-p "kingfisher-*.zip" \
-D release-assets
- name: Extract binaries
shell: bash
run: |
set -euo pipefail
mkdir -p extracted
for archive in release-assets/*; do
name=$(basename "$archive")
dir="extracted/${name%.*}"
mkdir -p "$dir"
case "$archive" in
*.tgz)
tar -xzf "$archive" -C "$dir"
;;
*.zip)
unzip -q "$archive" -d "$dir"
;;
*)
echo "Unknown archive: $archive" >&2
exit 1
;;
esac
done
mkdir -p extracted/bin
for bin in $(find extracted -type f \( -name "kingfisher" -o -name "kingfisher.exe" \)); do
chmod +x "$bin" || true
done
- name: Install build tooling
run: python -m pip install --upgrade build
- name: Build wheels
shell: bash
run: |
set -euo pipefail
version="${{ steps.version.outputs.version }}"
linux_x64=$(find extracted -type f -name "kingfisher" | grep -m1 "linux-x64")
linux_arm64=$(find extracted -type f -name "kingfisher" | grep -m1 "linux-arm64")
mac_x64=$(find extracted -type f -name "kingfisher" | grep -m1 "darwin-x64")
mac_arm64=$(find extracted -type f -name "kingfisher" | grep -m1 "darwin-arm64")
win_x64=$(find extracted -type f -name "kingfisher.exe" | grep -m1 "windows-x64")
scripts/build-pypi-wheel.sh \
--binary "$linux_x64" \
--version "$version" \
--plat-name musllinux_1_2_x86_64
scripts/build-pypi-wheel.sh \
--binary "$linux_arm64" \
--version "$version" \
--plat-name musllinux_1_2_aarch64
scripts/build-pypi-wheel.sh \
--binary "$mac_x64" \
--version "$version" \
--plat-name macosx_10_9_x86_64
scripts/build-pypi-wheel.sh \
--binary "$mac_arm64" \
--version "$version" \
--plat-name macosx_11_0_arm64
scripts/build-pypi-wheel.sh \
--binary "$win_x64" \
--version "$version" \
--plat-name win_amd64
scripts/build-pypi-wheel.sh \
--binary "$win_x64" \
--version "$version" \
--plat-name win_arm64
- name: Publish to PyPI (Trusted Publishing)
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist-pypi