1+ name : Build and Publish ShapeEngine NuGet Package
2+
3+ permissions :
4+ contents : read
5+
6+ on :
7+ workflow_dispatch :
8+
9+ jobs :
10+ build-pack-publish :
11+ runs-on : ubuntu-latest
12+
13+ steps :
14+ - name : Checkout repository
15+ uses : actions/checkout@v4
16+
17+ - name : Setup .NET
18+ uses : actions/setup-dotnet@v4
19+ with :
20+ dotnet-version : ' 8.0.x'
21+
22+ - name : Install dependencies for version check
23+ run : |
24+ sudo apt-get update
25+ sudo apt-get install -y libxml2-utils jq
26+
27+ - name : Check if ShapeEngine version is new
28+ id : check_version
29+ run : |
30+ csproj_version=$(xmllint --xpath "string(//Version)" ShapeEngine/ShapeEngine.csproj)
31+ echo "ShapeEngine.csproj version: $csproj_version"
32+ echo "csproj_version=$csproj_version" >> $GITHUB_OUTPUT
33+
34+ nuget_versions=$(curl -s https://api.nuget.org/v3-flatcontainer/shapeengine/index.json | jq -r '.versions')
35+ if [ "$nuget_versions" = "null" ]; then
36+ echo "No versions found on NuGet. Proceeding with publish."
37+ echo "should_publish=true" >> $GITHUB_OUTPUT
38+ exit 0
39+ fi
40+ latest_nuget_version=$(echo "$nuget_versions" | jq -r '.[-1]')
41+ echo "Latest NuGet version: $latest_nuget_version"
42+ echo "nuget_version=$latest_nuget_version" >> $GITHUB_OUTPUT
43+
44+ if [ "$csproj_version" = "$latest_nuget_version" ]; then
45+ echo "Version $csproj_version is already published. Skipping publish."
46+ echo "should_publish=false" >> $GITHUB_OUTPUT
47+ else
48+ echo "Version is new. Proceeding with publish."
49+ echo "should_publish=true" >> $GITHUB_OUTPUT
50+
51+ - name : Restore dependencies
52+ if : steps.check_version.outputs.should_publish == 'true'
53+ run : dotnet restore ShapeEngine/ShapeEngine.csproj
54+
55+ - name : Build ShapeEngine
56+ if : steps.check_version.outputs.should_publish == 'true'
57+ run : dotnet build ShapeEngine/ShapeEngine.csproj --configuration Release --no-restore
58+
59+ - name : Pack ShapeEngine NuGet Package
60+ if : steps.check_version.outputs.should_publish == 'true'
61+ run : dotnet pack ShapeEngine/ShapeEngine.csproj --configuration Release --no-build --output ./nupkgs
62+
63+ - name : Publish ShapeEngine NuGet Package
64+ if : steps.check_version.outputs.should_publish == 'true'
65+ env :
66+ NUGET_API_KEY : ${{ secrets.NUGET_API_KEY }}
67+ run : |
68+ dotnet nuget push ./nupkgs/ShapeEngine.*.nupkg --api-key "$NUGET_API_KEY" --source https://api.nuget.org/v3/index.json
0 commit comments