Skip to content

feat: implement function registry redesign with protobuf metadata #47

feat: implement function registry redesign with protobuf metadata

feat: implement function registry redesign with protobuf metadata #47

Workflow file for this run

name: Build and Release Python SDK
permissions:
contents: read
id-token: write
on:
push:
branches: [main, develop]
tags:
- "sdk-python-v*"
paths:
- ".github/workflows/ci-sdk-python.yml"
- "proto/**"
- "sdks/python/**"
pull_request:
branches: [main]
paths:
- ".github/workflows/ci-sdk-python.yml"
- "proto/**"
- "sdks/python/**"
workflow_dispatch:
inputs:
tag:
description: "指定 Tag 构建 (例如: sdk-python-v1.0.0)"
required: false
type: string
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
defaults:
run:
working-directory: ./sdks/python
strategy:
fail-fast: false
matrix:
python-version: ["3.12", "3.13"]
steps:
- name: Checkout repository
timeout-minutes: 3
uses: actions/checkout@v6
with:
ref: ${{ inputs.tag || github.ref }}
submodules: false
- name: Install uv
timeout-minutes: 5
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: "sdks/python/pyproject.toml"
python-version: ${{ matrix.python-version }}
- name: Install dependencies
timeout-minutes: 5
run: uv sync --dev --all-extras
- name: Create agent config
timeout-minutes: 2
run: |
cat > /tmp/agent-ci.yaml << 'EOF'
name: croupier-agent
host: 0.0.0.0
port: 19090
server:
addr: ""
insecure: true
agent:
id: "ci-test-agent"
gameId: "ci-test-game"
env: "testing"
localAddr: "0.0.0.0:19090"
httpAddr: "0.0.0.0:19090"
upstream:
heartbeatInterval: 30
retryInterval: 5
maxRetries: 0
timeout: 5000
tls:
enabled: false
outboundTLS:
enabled: false
EOF
- name: Start croupier-agent
timeout-minutes: 10
run: |
cd "${{ github.workspace }}"
docker pull ghcr.io/cuihairu/croupier-agent:latest || docker compose -f docker/docker-compose.ci.yml build
docker compose -f docker/docker-compose.ci.yml up -d
for i in {1..60}; do
if nc -z localhost 19090 2>/dev/null; then
echo "Agent is ready"
break
fi
if [ $i -eq 60 ]; then
echo "Agent failed to start"
docker compose -f docker/docker-compose.ci.yml logs
exit 1
fi
sleep 1
done
- name: Unit tests
timeout-minutes: 10
run: uv run pytest -q --cov=croupier --cov-report=xml --cov-report=term -m 'not integration'
- name: Integration tests
timeout-minutes: 10
run: uv run pytest -q tests/test_integration.py -m integration
- name: Show agent logs (if test failed)
if: failure()
run: cd "${{ github.workspace }}" && docker compose -f docker/docker-compose.ci.yml logs
- name: Stop agent
if: always()
run: cd "${{ github.workspace }}" && docker compose -f docker/docker-compose.ci.yml down -v
- name: Upload coverage to Codecov
if: success() && matrix.python-version == '3.12'
timeout-minutes: 5
uses: codecov/codecov-action@v6
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: sdks/python/coverage.xml
flags: python-sdk
fail_ci_if_error: ${{ github.event_name != 'pull_request' }}
lint:
runs-on: ubuntu-latest
timeout-minutes: 30
defaults:
run:
working-directory: ./sdks/python
steps:
- name: Checkout repository
timeout-minutes: 3
uses: actions/checkout@v6
with:
ref: ${{ inputs.tag || github.ref }}
- name: Install uv
timeout-minutes: 5
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: "sdks/python/pyproject.toml"
python-version: "3.12"
- name: Install dependencies
timeout-minutes: 5
run: uv sync --dev
- name: Run black
timeout-minutes: 5
run: uv run black --check --target-version=py312 croupier tests
- name: Run flake8
timeout-minutes: 5
run: uv run flake8 --ignore=F841,W391,F824,W504,E226 --extend-exclude=croupier/pb/,generated/ croupier tests
- name: Run mypy
timeout-minutes: 5
run: uv run mypy croupier --ignore-missing-imports --no-strict-optional
publish:
if: |
startsWith(github.ref, 'refs/tags/sdk-python-v') ||
(inputs.tag != '' && startsWith(inputs.tag, 'sdk-python-v'))
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [test, lint]
permissions:
contents: write
defaults:
run:
working-directory: ./sdks/python
steps:
- name: Checkout repository
timeout-minutes: 3
uses: actions/checkout@v6
with:
ref: ${{ inputs.tag || github.ref }}
submodules: false
- name: Determine SDK Version
id: version
shell: bash
run: |
PACKAGE_VERSION=$(python3 -c 'import pathlib, tomllib; data = tomllib.loads(pathlib.Path("pyproject.toml").read_text()); print(data["project"]["version"])')
if [[ "${GITHUB_REF_TYPE:-}" == "tag" ]]; then
TAG_VERSION="${GITHUB_REF_NAME#sdk-python-v}"
if [[ "$TAG_VERSION" != "$PACKAGE_VERSION" ]]; then
echo "Tag version ($TAG_VERSION) does not match pyproject.toml version ($PACKAGE_VERSION)"
exit 1
fi
elif [[ -n "${{ inputs.tag }}" ]]; then
TAG_VERSION="${{ inputs.tag }}"
TAG_VERSION="${TAG_VERSION#sdk-python-v}"
if [[ "$TAG_VERSION" != "$PACKAGE_VERSION" ]]; then
echo "Tag version ($TAG_VERSION) does not match pyproject.toml version ($PACKAGE_VERSION)"
exit 1
fi
fi
- name: Install uv
timeout-minutes: 5
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: "sdks/python/pyproject.toml"
python-version: "3.12"
- name: Install dependencies
timeout-minutes: 5
run: uv sync --dev --all-extras
- name: Run tests
timeout-minutes: 10
run: uv run pytest -q
- name: Build wheel and sdist
timeout-minutes: 10
run: uv build
- name: Package
timeout-minutes: 2
run: |
mkdir -p artifacts
cp dist/* artifacts/
- name: Create Release
timeout-minutes: 10
uses: softprops/action-gh-release@v4
with:
files: sdks/python/artifacts/*
fail_on_unmatched_files: true
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}