1+ name : CI/CD
2+
3+ on :
4+ push :
5+ branches : [ main, develop ]
6+ pull_request :
7+ branches : [ main ]
8+ release :
9+ types : [ published ]
10+
11+ env :
12+ DOTNET_VERSION : ' 10.0.x'
13+ PROJECT_PATH : ' TypescriptClientGenerator/TypescriptClientGenerator.csproj'
14+
15+ jobs :
16+ build-and-test :
17+ runs-on : ubuntu-latest
18+
19+ steps :
20+ - name : Checkout code
21+ uses : actions/checkout@v4
22+
23+ - name : Setup .NET
24+ uses : actions/setup-dotnet@v4
25+ with :
26+ dotnet-version : ${{ env.DOTNET_VERSION }}
27+
28+ - name : Restore dependencies
29+ run : dotnet restore ${{ env.PROJECT_PATH }}
30+
31+ - name : Build
32+ run : dotnet build ${{ env.PROJECT_PATH }} --no-restore --configuration Release
33+
34+ - name : Test tool with sample OpenAPI spec
35+ run : |
36+ dotnet run --project ${{ env.PROJECT_PATH }} -- --input tests/sample-openapi.json --output TestClient.ts
37+
38+ - name : Verify generated client
39+ run : |
40+ if [ ! -f "TestClient.ts" ]; then
41+ echo "Generated client file not found!"
42+ exit 1
43+ fi
44+ echo "Generated client file found and verified"
45+
46+ - name : Pack
47+ run : dotnet pack ${{ env.PROJECT_PATH }} --no-build --configuration Release
48+
49+ - name : Upload build artifacts
50+ uses : actions/upload-artifact@v4
51+ with :
52+ name : nuget-package
53+ path : TypescriptClientGenerator/bin/Release/*.nupkg
54+
55+ publish :
56+ needs : build-and-test
57+ runs-on : ubuntu-latest
58+ # Only publish on pushes to main branch, not on PRs or other branches
59+ if : github.ref == 'refs/heads/main' && github.event_name == 'push'
60+
61+ steps :
62+ - name : Checkout code
63+ uses : actions/checkout@v4
64+ with :
65+ fetch-depth : 0
66+
67+ - name : Install GitVersion
68+ uses : gittools/actions/gitversion/setup@v0.10.2
69+ with :
70+ versionSpec : ' 6.x'
71+
72+ - name : Determine Version
73+ id : gitversion
74+ uses : gittools/actions/gitversion/execute@v0.10.2
75+
76+ - name : Setup .NET
77+ uses : actions/setup-dotnet@v4
78+ with :
79+ dotnet-version : ${{ env.DOTNET_VERSION }}
80+
81+ - name : Restore dependencies
82+ run : dotnet restore ${{ env.PROJECT_PATH }}
83+
84+ - name : Build
85+ run : dotnet build ${{ env.PROJECT_PATH }} --no-restore --configuration Release -p:Version=${{ steps.gitversion.outputs.semVer }}
86+
87+ - name : Pack
88+ run : dotnet pack ${{ env.PROJECT_PATH }} --no-build --configuration Release -p:PackageVersion=${{ steps.gitversion.outputs.semVer }}
89+
90+ - name : Publish to NuGet
91+ run : dotnet nuget push TypescriptClientGenerator/bin/Release/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
92+
93+ - name : Upload release artifacts
94+ uses : actions/upload-artifact@v4
95+ with :
96+ name : release-package
97+ path : TypescriptClientGenerator/bin/Release/*.nupkg
98+
99+ verify-package :
100+ needs : build-and-test
101+ runs-on : ubuntu-latest
102+ if : github.event_name != 'release'
103+
104+ steps :
105+ - name : Checkout code
106+ uses : actions/checkout@v4
107+
108+ - name : Setup .NET
109+ uses : actions/setup-dotnet@v4
110+ with :
111+ dotnet-version : ${{ env.DOTNET_VERSION }}
112+
113+ - name : Download build artifacts
114+ uses : actions/download-artifact@v4
115+ with :
116+ name : nuget-package
117+ path : ./artifacts
118+
119+ - name : Install tool from local package
120+ run : |
121+ PACKAGE_PATH=$(find ./artifacts -name "*.nupkg" | head -1)
122+ dotnet tool install --global --add-source ./artifacts TypescriptClientGenerator
123+
124+ - name : Test installed tool
125+ run : |
126+ typescript-client-generator --input tests/sample-openapi.json --output VerifyClient.ts
127+
128+ - name : Verify tool output
129+ run : |
130+ if [ ! -f "VerifyClient.ts" ]; then
131+ echo "Tool verification failed - no output generated!"
132+ exit 1
133+ fi
134+ echo "Tool verification successful!"
0 commit comments