@@ -29,16 +29,63 @@ jobs:
2929 - name : Run tests
3030 run : dotnet test --configuration Release --no-build --verbosity normal --filter FullyQualifiedName\!~IntegrationTests
3131
32+ - name : Get Version
33+ run : |
34+ NUSPEC_VERSION=$(grep -oP '(?<=<version>).*?(?=</version>)' MaIN.Core/*.nuspec | head -1)
35+ echo "NUSPEC_VERSION=${NUSPEC_VERSION}" >> $GITHUB_ENV
36+ echo "nuspec_version=${NUSPEC_VERSION}" >> $GITHUB_OUTPUT
37+
38+ - name : Get latest release version
39+ uses : octokit/request-action@v2.x
40+ with :
41+ route : GET /repos/{owner}/{repo}/releases/latest
42+ owner : ${{ github.repository_owner }}
43+ repo : ${{ github.event.repository.name }}
44+ env :
45+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
46+ continue-on-error : true
47+
48+ - name : Extract latest version
49+ id : extract-latest
50+ run : |
51+ if [ "${{ steps.latest-release.outcome }}" == "success" ]; then
52+ LATEST_VERSION=$(echo '${{ steps.latest-release.outputs.data }}' | jq -r '.tag_name' | sed 's/^v//')
53+ echo "LATEST_VERSION=${LATEST_VERSION}" >> $GITHUB_ENV
54+ echo "latest_version=${LATEST_VERSION}" >> $GITHUB_OUTPUT
55+ else
56+ echo "No previous release found"
57+ echo "LATEST_VERSION=0.0.0" >> $GITHUB_ENV
58+ echo "latest_version=0.0.0" >> $GITHUB_OUTPUT
59+ fi
60+
61+ - name : Compare versions
62+ id : compare-versions
63+ run : |
64+ echo "Nuspec version: ${{ env.NUSPEC_VERSION }}"
65+ echo "Latest release version: ${{ env.LATEST_VERSION }}"
66+
67+ if [ "${{ env.NUSPEC_VERSION }}" != "${{ env.LATEST_VERSION }}" ]; then
68+ echo "Versions are different - creating a new release"
69+ echo "CREATE_RELEASE=true" >> $GITHUB_ENV
70+ echo "create_release=true" >> $GITHUB_OUTPUT
71+ else
72+ echo "Versions are the same - skipping release"
73+ echo "CREATE_RELEASE=false" >> $GITHUB_ENV
74+ echo "create_release=false" >> $GITHUB_OUTPUT
75+ fi
76+
3277 - name : Pack NuGet package
78+ if : env.CREATE_RELEASE == 'true'
3379 run : dotnet pack --configuration Release --output ./artifacts
3480
3581 - name : Push package to NuGet
82+ if : env.CREATE_RELEASE == 'true'
3683 env :
3784 NUGET_API_KEY : ${{ secrets.NUGET_API_KEY }}
3885 run : dotnet nuget push "./artifacts/*.nupkg" --source "https://api.nuget.org/v3/index.json" --api-key "$NUGET_API_KEY" --skip-duplicate
3986
4087 - name : Create GitHub Release
41- if : github.ref == 'refs/heads/main'
88+ if : github.ref == 'refs/heads/main' && env.CREATE_RELEASE == 'true'
4289 env :
4390 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4491 run : |
0 commit comments