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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: token: ${{ secrets.GITHUB_TOKEN }} - name: Setup Node.js uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 with: node-version: '22.x' - name: Setup .NET uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 # v5.2.0 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 "." \ -ActionRunUrl "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"