@@ -9,6 +9,9 @@ concurrency:
99 group : ${{ github.head_ref || github.ref }}
1010 cancel-in-progress : true
1111
12+ env :
13+ PACKAGE_NAME : " Rebus.Datadog.Tracing"
14+
1215jobs :
1316 build_and_publish :
1417 name : Build and publish
@@ -23,20 +26,44 @@ jobs:
2326 run : echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
2427
2528 - name : Check nuget version availability
26- uses : e-conomic/github-actions/nuget-version-check@v46
27- with :
28- name : " Rebus.Datadog.Tracing"
29- version : ${{ steps.package_version.outputs.VERSION }}
29+ shell : bash
30+ run : |
31+ PACKAGE_NAME_LOWER="${PACKAGE_NAME,,}"
32+ response=$(curl -i "https://api.nuget.org/v3/registration5-semver1/${PACKAGE_NAME_LOWER}/${{ steps.package_version.outputs.VERSION }}.json")
33+
34+ echo "::group::API Response"
35+ echo "$response"
36+ echo "::endgroup::"
37+
38+ status_code=$(echo "$response" | head -n1 | awk '{print $2}')
39+
40+ if [ "$status_code" = "404" ]; then
41+ echo "Request failed with status: $status_code"
42+ echo "Nuget package '${{ env.PACKAGE_NAME }}' does not have version '${{ steps.package_version.outputs.VERSION }}'"
43+ echo "It's safe to proceed"
44+ exit 0
45+ fi
46+
47+ if [ "$status_code" = "200" ]; then
48+ echo "Request succeeded with status: $status_code"
49+ echo "Nuget package '${{ env.PACKAGE_NAME }}' has version '${{ steps.package_version.outputs.VERSION }}'"
50+ echo "Execution will halt to prevent overwriting the package version"
51+ exit 1
52+ fi
53+
54+ echo "Request failed with status: $status_code"
55+ echo "Execution will halt due to an unexpected error code"
56+ exit 2
3057
3158 - name : Setup .NET
3259 uses : actions/setup-dotnet@v4
3360 with :
3461 dotnet-version : 6.0.x
3562
3663 - name : Generate NuGet packages
37- run : dotnet pack ./src/Rebus.Datadog.Tracing / -o ./nuget -c Release --include-source -p:PackageVersion=${{ steps.package_version.outputs.VERSION }}
64+ run : dotnet pack ./src/${{ env.PACKAGE_NAME }} / -o ./nuget -c Release --include-source -p:PackageVersion=${{ steps.package_version.outputs.VERSION }}
3865
3966 - name : Publish NuGet package
40- run : dotnet nuget push ./nuget/Rebus.Datadog.Tracing .${{ steps.package_version.outputs.VERSION }}.nupkg -k $NUGET_AUTH_TOKEN -s https://api.nuget.org/v3/index.json
67+ run : dotnet nuget push ./nuget/${{ env.PACKAGE_NAME }} .${{ steps.package_version.outputs.VERSION }}.nupkg -k $NUGET_AUTH_TOKEN -s https://api.nuget.org/v3/index.json
4168 env :
4269 NUGET_AUTH_TOKEN : ${{ secrets.NUGET_APIKEY }}
0 commit comments