openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
.github/workflows/update-generator.yml
77lines · modecode
| 1 | name: Update TypeSpec Generator Version |
| 2 | |
| 3 | on: |
| 4 | schedule: |
| 5 | # Run weekly on Mondays at 9 AM UTC |
| 6 | - cron: '0 9 * * 1' |
| 7 | workflow_dispatch: |
| 8 | # Allow manual triggering |
| 9 | repository_dispatch: |
| 10 | # Allow triggering from TypeSpec repository on new releases |
| 11 | types: [typespec-release] |
| 12 | |
| 13 | jobs: |
| 14 | update-generator: |
| 15 | runs-on: ubuntu-latest |
| 16 | permissions: |
| 17 | contents: write |
| 18 | pull-requests: write |
| 19 | |
| 20 | steps: |
| 21 | - name: Checkout code |
| 22 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 23 | with: |
| 24 | token: ${{ secrets.GITHUB_TOKEN }} |
| 25 | |
| 26 | - name: Setup Node.js |
| 27 | uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 |
| 28 | with: |
| 29 | node-version: '22.x' |
| 30 | |
| 31 | - name: Setup .NET |
| 32 | uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 # v5.2.0 |
| 33 | with: |
| 34 | # Automatically read .NET SDK version from global.json to stay in sync |
| 35 | global-json-file: global.json |
| 36 | |
| 37 | - name: Check for generator updates |
| 38 | id: check-updates |
| 39 | run: | |
| 40 | # Get current version from the OpenAI package.json file |
| 41 | CURRENT_VERSION=$(node -p "require('./codegen/package.json').dependencies['@typespec/http-client-csharp']" 2>/dev/null || echo "unknown") |
| 42 | |
| 43 | echo "Current OpenAI version: $CURRENT_VERSION" |
| 44 | |
| 45 | # Get latest version from npm registry |
| 46 | LATEST_VERSION=$(npm view @typespec/http-client-csharp version 2>/dev/null || echo "unknown") |
| 47 | echo "Latest version from npm: $LATEST_VERSION" |
| 48 | |
| 49 | # Validate we got valid versions |
| 50 | if [ "$CURRENT_VERSION" = "unknown" ] || [ "$LATEST_VERSION" = "unknown" ]; then |
| 51 | echo "Error: Failed to get version information" |
| 52 | echo "Current: $CURRENT_VERSION, Latest: $LATEST_VERSION" |
| 53 | exit 1 |
| 54 | fi |
| 55 | |
| 56 | # Compare versions (simple string comparison for alpha versions) |
| 57 | if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then |
| 58 | echo "Update needed: $CURRENT_VERSION -> $LATEST_VERSION" |
| 59 | echo "needs-update=true" >> $GITHUB_OUTPUT |
| 60 | echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 61 | echo "latest-version=$LATEST_VERSION" >> $GITHUB_OUTPUT |
| 62 | else |
| 63 | echo "No update needed - already at latest version: $CURRENT_VERSION" |
| 64 | echo "needs-update=false" >> $GITHUB_OUTPUT |
| 65 | fi |
| 66 | |
| 67 | - name: Update generator version and create PR |
| 68 | if: steps.check-updates.outputs.needs-update == 'true' |
| 69 | run: | |
| 70 | LATEST_VERSION="${{ steps.check-updates.outputs.latest-version }}" |
| 71 | |
| 72 | # Use the PowerShell script to handle the entire update process (following TypeSpec pattern) |
| 73 | pwsh ./scripts/Submit-GeneratorUpdatePr.ps1 \ |
| 74 | -PackageVersion "$LATEST_VERSION" \ |
| 75 | -AuthToken "${{ secrets.GITHUB_TOKEN }}" \ |
| 76 | -RepoPath "." \ |
| 77 | -ActionRunUrl "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 78 | |