200 lines
6.8 KiB
YAML
200 lines
6.8 KiB
YAML
name: Upgrade TensorZero Dependencies
|
||
|
||
on:
|
||
workflow_call:
|
||
workflow_dispatch:
|
||
|
||
permissions: {}
|
||
|
||
env:
|
||
FORCE_COLOR: 1
|
||
|
||
concurrency:
|
||
group: upgrade-tensorzero-deps-${{ github.event.pull_request.number || github.ref || github.run_id }}
|
||
cancel-in-progress: false
|
||
|
||
jobs:
|
||
upgrade-dependencies:
|
||
name: Upgrade TensorZero dependencies across all projects
|
||
runs-on: ubuntu-latest
|
||
timeout-minutes: 30
|
||
if: github.repository == 'tensorzero/tensorzero'
|
||
|
||
permissions:
|
||
contents: write # Required to push generated branch changes.
|
||
pull-requests: write # Required to update PR comments, labels, or branches.
|
||
|
||
steps:
|
||
- name: Checkout repository
|
||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||
with:
|
||
persist-credentials: true
|
||
token: ${{ secrets.GITHUB_TOKEN }}
|
||
|
||
- name: Install uv
|
||
uses: astral-sh/setup-uv@61cb8a9741eeb8a550a1b8544337180c0fc8476b # v7.2.0
|
||
with:
|
||
version: "0.9.27"
|
||
|
||
- name: Install jq
|
||
run: sudo apt-get update && sudo apt-get install -y jq
|
||
|
||
- name: Wait for PyPI availability (auto-trigger only)
|
||
if: github.event_name != 'workflow_dispatch'
|
||
run: |
|
||
echo "Waiting 60 seconds for PyPI to propagate the new version..."
|
||
sleep 60
|
||
|
||
- name: Get latest TensorZero version from PyPI
|
||
id: get_version
|
||
run: |
|
||
echo "Fetching latest tensorzero version from PyPI..."
|
||
response=$(curl -sSf https://pypi.org/pypi/tensorzero/json)
|
||
if [ $? -ne 0 ] || [ -z "$response" ]; then
|
||
echo "Error: Failed to fetch tensorzero info from PyPI." >&2
|
||
exit 1
|
||
fi
|
||
latest_version=$(echo "$response" | jq -r '.info.version')
|
||
if [ -z "$latest_version" ] || [ "$latest_version" = "null" ]; then
|
||
echo "Error: Failed to extract version from PyPI response." >&2
|
||
exit 1
|
||
fi
|
||
echo "Latest version: $latest_version"
|
||
echo "version=$latest_version" >> $GITHUB_OUTPUT
|
||
|
||
- name: Discover projects with TensorZero dependency
|
||
id: discover_projects
|
||
run: |
|
||
echo "Discovering projects that depend on tensorzero..."
|
||
|
||
# Find all pyproject.toml files that contain 'tensorzero' dependency
|
||
projects=$(git ls-files "**/pyproject.toml" | xargs -r grep -l "tensorzero")
|
||
|
||
echo "Found projects:"
|
||
echo "$projects"
|
||
|
||
# Store project list for later steps
|
||
echo "$projects" > tensorzero_projects.txt
|
||
|
||
project_count=$([ -n "$projects" ] && echo "$projects" | wc -l || echo 0)
|
||
echo "project_count=$project_count" >> $GITHUB_OUTPUT
|
||
|
||
- name: Upgrade TensorZero in each project
|
||
env:
|
||
VERSION: ${{ steps.get_version.outputs.version }}
|
||
run: |
|
||
echo "Upgrading tensorzero to version $VERSION in each project..."
|
||
|
||
while IFS= read -r project_file; do
|
||
if [ -n "$project_file" ]; then
|
||
project_dir=$(dirname "$project_file")
|
||
echo "Upgrading tensorzero in: $project_dir"
|
||
|
||
(cd "$project_dir" && uv lock --upgrade-package tensorzero --project="pyproject.toml") || {
|
||
echo "Warning: Failed to upgrade tensorzero in $project_dir"
|
||
}
|
||
fi
|
||
done < tensorzero_projects.txt
|
||
|
||
- name: Run uv-lock on all projects
|
||
run: |
|
||
echo "Running uv-lock on all projects (following general.yml pattern)..."
|
||
git ls-files "**/pyproject.toml" | while read f; do
|
||
dir=$(dirname "$f")
|
||
echo "Running uv lock in: $dir"
|
||
(cd "$dir" && uv lock --project="pyproject.toml") || {
|
||
echo "Warning: uv lock failed in $dir"
|
||
}
|
||
done
|
||
|
||
- name: Check for changes
|
||
id: check_changes
|
||
run: |
|
||
if git diff --quiet; then
|
||
echo "No changes detected"
|
||
echo "has_changes=false" >> $GITHUB_OUTPUT
|
||
else
|
||
echo "Changes detected"
|
||
echo "has_changes=true" >> $GITHUB_OUTPUT
|
||
|
||
# Show summary of changes
|
||
echo "Changed files:"
|
||
git diff --name-only
|
||
fi
|
||
|
||
- name: Create Pull Request
|
||
if: steps.check_changes.outputs.has_changes == 'true'
|
||
id: create_pr
|
||
run: |
|
||
version="$VERSION"
|
||
branch_name="auto/upgrade-tensorzero-${version}"
|
||
|
||
# Configure git
|
||
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||
git config --local user.name "github-actions[bot]"
|
||
|
||
# Check if branch already exists and delete it
|
||
if git ls-remote --heads origin "$branch_name" | grep -q "$branch_name"; then
|
||
echo "Branch $branch_name already exists, deleting it..."
|
||
git push origin --delete "$branch_name" || true
|
||
fi
|
||
|
||
# Create and switch to new branch
|
||
git checkout -b "$branch_name"
|
||
|
||
# Add all changes
|
||
git add .
|
||
|
||
# Create commit
|
||
git commit -m "chore: upgrade tensorzero to ${version}
|
||
|
||
Auto-upgrade of tensorzero dependency across ${PROJECT_COUNT} projects.
|
||
|
||
🤖 Generated with GitHub Actions"
|
||
|
||
# Push branch
|
||
git push origin "$branch_name"
|
||
|
||
# Create PR body
|
||
cat > pr_body.md << EOF
|
||
## Summary
|
||
Automatically upgrade \`tensorzero\` dependency to version **${version}** across all projects in the monorepo.
|
||
|
||
## Changes
|
||
- Upgraded tensorzero dependency in ${PROJECT_COUNT} projects
|
||
- Regenerated uv.lock files using \`uv lock\`
|
||
|
||
## Projects Updated
|
||
\`\`\`
|
||
$(cat tensorzero_projects.txt)
|
||
\`\`\`
|
||
|
||
🤖 This PR was automatically created by the \`upgrade-tensorzero-deps\` workflow.
|
||
EOF
|
||
|
||
# Create PR using GitHub CLI
|
||
gh pr create \
|
||
--title "chore: upgrade tensorzero to ${version}" \
|
||
--body-file pr_body.md \
|
||
--head "$branch_name" \
|
||
--base main \
|
||
--label "dependencies" \
|
||
--label "automated"
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
PROJECT_COUNT: ${{ steps.discover_projects.outputs.project_count }}
|
||
VERSION: ${{ steps.get_version.outputs.version }}
|
||
|
||
- name: Summary
|
||
env:
|
||
HAS_CHANGES: ${{ steps.check_changes.outputs.has_changes }}
|
||
PROJECT_COUNT: ${{ steps.discover_projects.outputs.project_count }}
|
||
VERSION: ${{ steps.get_version.outputs.version }}
|
||
run: |
|
||
if [ "$HAS_CHANGES" == "true" ]; then
|
||
echo "✅ Successfully created PR to upgrade tensorzero to $VERSION"
|
||
echo " Updated $PROJECT_COUNT projects"
|
||
else
|
||
echo "ℹ️ No changes needed - all projects already use the latest version"
|
||
fi
|