Skip to content

fix(workflow): 统一下载依赖项的条件判断格式并清理多余配置 #5

fix(workflow): 统一下载依赖项的条件判断格式并清理多余配置

fix(workflow): 统一下载依赖项的条件判断格式并清理多余配置 #5

name: Template Build and Attach Release Packages

Check failure on line 1 in .github/workflows/template-python-build-release.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/template-python-build-release.yml

Invalid workflow file

(Line: 49, Col: 13): Unexpected symbol: '""'. Located at position 33 within expression: inputs.download-dependencies != "", (Line: 57, Col: 13): Unexpected symbol: '""'. Located at position 33 within expression: inputs.download-dependencies != ""
description: 这是一个支持 Python 包构建和发布的工作流模板,支持使用 pybind11 进行构建。
on:
workflow_call:
inputs:
python-version:
description: "Python version(s) to build with"
required: false
type: string
default: '["3.11"]' # 默认 JSON 列表
build-command:
description: "Custom build command"
required: false
type: string
default: "python -m build"
download-dependencies:
description: "Dependencies to set up before build (JSON list of URLs)"
required: false
type: string
default: ""
download-dependencies-path:
description: "Path to dependencies directory"
required: false
type: string
default: "./"
secrets:
caller_token:
description: "GitHub token for uploading release assets"
required: false
permissions:
contents: write
jobs:
# ---------------------------
# Job 1: 下载并解压依赖(仅 Linux)
# ---------------------------
setup_dependencies:
name: Download & Extract Dependencies (Linux)
runs-on: ubuntu-latest
outputs:
deps-artifact-name: "deps-artifact"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download dependencies
if: ${{ inputs.download-dependencies != "" }}
uses: HurleyKane/project_template/.github/actions/setup-dependency@master
with:
sources: ${{ inputs.download-dependencies }}
dest: ${{ inputs.download-dependencies-path }}
type: "auto"
- name: Upload dependencies artifact
if: ${{ inputs.download-dependencies != "" }}
uses: actions/upload-artifact@v4
with:
name: deps-artifact
path: ${{ inputs.download-dependencies-path }}
# ---------------------------
# Job 2: 构建 Python 包(跨平台)
# ---------------------------
build:
name: Build Python Package
needs: setup_dependencies
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ${{ fromJson(inputs.python-version) }}
timeout-minutes: 180
steps:
- name: Checkout repository
uses: actions/checkout@v4
# 下载依赖 artifact
- name: Download dependencies artifact
if: ${{ inputs.download-dependencies != '' }}
uses: actions/download-artifact@v4
with:
name: deps-artifact
path: ${{ inputs.download-dependencies-path }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install build dependencies
run: |
pip install --progress-bar off -q build setuptools wheel pybind11 cmake ninja scikit-build-core
# 构建 Python 包
- name: Build the package
run: ${{ inputs.build-command }}
# 上传构建产物
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.os }}-py${{ matrix.python-version }}
path: dist/*
# 上传到 Release
- name: Upload release assets
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}