Skip to content

Update AI SDK Dependencies #231

Update AI SDK Dependencies

Update AI SDK Dependencies #231

name: Update AI SDK Dependencies
on:
schedule:
# Run at midnight every day (UTC)
- cron: '0 0 * * *'
workflow_dispatch: # Allow manual trigger
jobs:
update-dependencies:
name: Update AI SDK Dependencies
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.17.0'
- name: Install dependencies
run: npm install
- name: Update AI SDK dependencies
run: |
# Define the AI SDK packages to update
packages=(
"ai"
"@ai-sdk/alibaba"
"@ai-sdk/amazon-bedrock"
"@ai-sdk/anthropic"
"@ai-sdk/azure"
"@ai-sdk/cerebras"
"@ai-sdk/deepseek"
"@ai-sdk/google"
"@ai-sdk/google-vertex"
"@ai-sdk/mistral"
"@ai-sdk/otel"
"@ai-sdk/groq"
"@ai-sdk/openai"
"@ai-sdk/openai-compatible"
"@ai-sdk/provider"
"@openrouter/ai-sdk-provider"
"@requesty/ai-sdk"
"ollama-ai-provider-v2"
)
# Create changelog in memory (not as file)
changelog="# AI SDK Dependencies Update\n\n| Package | From | To |\n|---------|------|----|"
has_updates=false
# Update each package to latest stable version within the same major version
for package in "${packages[@]}"; do
echo "Checking $package..."
# Get current version from package.json
current_version=$(cat package.json | jq -r ".dependencies[\"$package\"] // empty")
if [ -z "$current_version" ]; then
echo "Package $package not found in dependencies, skipping..."
continue
fi
# Normalize current version (remove caret and leading v)
current_clean=$(echo $current_version | sed 's/[\^v]//')
# Extract major version from current version
current_major=$(echo $current_clean | cut -d. -f1)
# Get all versions for the package
all_versions=$(npm view $package versions --json 2>/dev/null || echo "[]")
# Filter versions to get the latest within the same major version
# Sort versions and find the latest matching current major
latest_same_major=$(echo "$all_versions" | \
jq -r --arg major "$current_major" \
'[.[] | select(. | match("^[0-9]+\\.[0-9]+\\.[0-9]+$") != null)] |
map(. as $v | split(".") | {major: (.[0] | tonumber), minor: (.[1] | tonumber), patch: (.[2] | tonumber), original: $v}) |
map(select(.major == ($major | tonumber))) |
sort_by(.major, .minor, .patch) | reverse |
.[0].original // empty')
# If no versions found or parsing failed, fallback to current version
if [ -z "$latest_same_major" ]; then
latest_same_major=$current_clean
fi
echo "Current: $current_version, Latest (same major $current_major): $latest_same_major"
# Normalize latest version for comparison (remove caret and leading v)
latest_clean=$(echo $latest_same_major | sed 's/[\^v]//')
# Update if different
if [ "$current_clean" != "$latest_clean" ]; then
echo "Updating $package from $current_version to $latest_clean"
# Write pinned version directly to package.json (no ~ or ^ prefix)
tmp=$(mktemp)
jq --arg pkg "$package" --arg ver "$latest_clean" '.dependencies[$pkg] = $ver' package.json > "$tmp" && mv "$tmp" package.json
# Add to changelog
changelog="$changelog\n| $package | $current_version | $latest_clean |"
has_updates=true
else
echo "$package is already up to date within major version $current_major"
fi
done
# Sync lockfile with pinned versions in package.json
if [ "$has_updates" = true ]; then
npm install
fi
# Save changelog to environment variable for PR (only if there are updates)
if [ "$has_updates" = true ]; then
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
echo -e "$changelog" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
else
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
echo "No AI SDK dependencies needed updates." >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
fi
- name: Check for changes
id: verify-changed-files
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request
if: steps.verify-changed-files.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: update AI SDK dependencies to latest versions within same major version"
title: "chore: update AI SDK dependencies"
body: |
## Automated AI SDK Dependencies Update
This PR updates AI SDK packages to their latest stable versions within the same major version (to avoid breaking changes).
${{ env.CHANGELOG }}
---
🤖 This PR was created automatically by the [Update AI SDK Dependencies](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) workflow.
branch: chore/update-ai-sdk-dependencies
delete-branch: true
labels: |
dependencies
automated
assignees: ${{ github.actor }}