Skip to content

Update TypeSpec Generator Version #12

Update TypeSpec Generator Version

Update TypeSpec Generator Version #12

name: Update TypeSpec Generator Version
on:
schedule:
# Run weekly on Mondays at 9 AM UTC
- cron: '0 9 * * 1'
workflow_dispatch:
# Allow manual triggering
repository_dispatch:
# Allow triggering from TypeSpec repository on new releases
types: [typespec-release]
jobs:
update-generator:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
# Automatically read .NET SDK version from global.json to stay in sync
global-json-file: global.json
- name: Check for generator updates
id: check-updates
run: |
# Get current version from the OpenAI package.json file
CURRENT_VERSION=$(node -p "require('./codegen/package.json').dependencies['@typespec/http-client-csharp']" 2>/dev/null || echo "unknown")
echo "Current OpenAI version: $CURRENT_VERSION"
# Get latest version from npm registry
LATEST_VERSION=$(npm view @typespec/http-client-csharp version 2>/dev/null || echo "unknown")
echo "Latest version from npm: $LATEST_VERSION"
# Validate we got valid versions
if [ "$CURRENT_VERSION" = "unknown" ] || [ "$LATEST_VERSION" = "unknown" ]; then
echo "Error: Failed to get version information"
echo "Current: $CURRENT_VERSION, Latest: $LATEST_VERSION"
exit 1
fi
# Compare versions (simple string comparison for alpha versions)
if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then
echo "Update needed: $CURRENT_VERSION -> $LATEST_VERSION"
echo "needs-update=true" >> $GITHUB_OUTPUT
echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "latest-version=$LATEST_VERSION" >> $GITHUB_OUTPUT
else
echo "No update needed - already at latest version: $CURRENT_VERSION"
echo "needs-update=false" >> $GITHUB_OUTPUT
fi
- name: Update generator version and create PR
if: steps.check-updates.outputs.needs-update == 'true'
run: |
LATEST_VERSION="${{ steps.check-updates.outputs.latest-version }}"
# Use the PowerShell script to handle the entire update process (following TypeSpec pattern)
pwsh ./scripts/Submit-GeneratorUpdatePr.ps1 \
-PackageVersion "$LATEST_VERSION" \
-AuthToken "${{ secrets.GITHUB_TOKEN }}" \
-RepoPath "."