Skip to content

Commit 432d86f

Browse files
committed
Add workflow to auto update generator version
1 parent 915c39d commit 432d86f

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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@v4
23+
with:
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: '22.x'
30+
31+
- name: Setup .NET
32+
uses: actions/setup-dotnet@v4
33+
with:
34+
dotnet-version: 8.x
35+
36+
- name: Check for generator updates
37+
id: check-updates
38+
run: |
39+
# Get current version from both package.json files
40+
CURRENT_VERSION_OPENAI=$(node -p "require('./dotnet/.plugin/package.json').dependencies['@typespec/http-client-csharp']" 2>/dev/null || echo "unknown")
41+
CURRENT_VERSION_AZURE=$(node -p "require('./dotnet/.plugin.azure/package.json').dependencies['@typespec/http-client-csharp']" 2>/dev/null || echo "unknown")
42+
43+
echo "Current OpenAI version: $CURRENT_VERSION_OPENAI"
44+
echo "Current Azure version: $CURRENT_VERSION_AZURE"
45+
46+
# Ensure both files have the same version
47+
if [ "$CURRENT_VERSION_OPENAI" != "$CURRENT_VERSION_AZURE" ]; then
48+
echo "Warning: Version mismatch between OpenAI and Azure package.json files"
49+
echo "Using OpenAI version as current: $CURRENT_VERSION_OPENAI"
50+
fi
51+
52+
CURRENT_VERSION="$CURRENT_VERSION_OPENAI"
53+
54+
# Get latest version from npm registry
55+
LATEST_VERSION=$(npm view @typespec/http-client-csharp version 2>/dev/null || echo "unknown")
56+
echo "Latest version from npm: $LATEST_VERSION"
57+
58+
# Validate we got valid versions
59+
if [ "$CURRENT_VERSION" = "unknown" ] || [ "$LATEST_VERSION" = "unknown" ]; then
60+
echo "Error: Failed to get version information"
61+
echo "Current: $CURRENT_VERSION, Latest: $LATEST_VERSION"
62+
exit 1
63+
fi
64+
65+
# Compare versions (simple string comparison for alpha versions)
66+
if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then
67+
echo "Update needed: $CURRENT_VERSION -> $LATEST_VERSION"
68+
echo "needs-update=true" >> $GITHUB_OUTPUT
69+
echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
70+
echo "latest-version=$LATEST_VERSION" >> $GITHUB_OUTPUT
71+
else
72+
echo "No update needed - already at latest version: $CURRENT_VERSION"
73+
echo "needs-update=false" >> $GITHUB_OUTPUT
74+
fi
75+
76+
- name: Update generator version and create PR
77+
if: steps.check-updates.outputs.needs-update == 'true'
78+
run: |
79+
LATEST_VERSION="${{ steps.check-updates.outputs.latest-version }}"
80+
81+
# Use the PowerShell script to handle the entire update process (following TypeSpec pattern)
82+
pwsh ./scripts/Submit-GeneratorUpdatePr.ps1 \
83+
-PackageVersion "$LATEST_VERSION" \
84+
-AuthToken "${{ secrets.GITHUB_TOKEN }}" \
85+
-RepoPath "."

0 commit comments

Comments
 (0)