@@ -62,12 +62,40 @@ jobs:
6262 if : steps.check_changes.outputs.has_changes == 'true'
6363 run : |
6464 LAST_CLIENT_TAG="${{ steps.check_changes.outputs.last_client_tag }}"
65+ PACKAGE_ID="xero.netstandard.oauth2client"
66+ NUGET_INDEX_URL="https://api.nuget.org/v3-flatcontainer/${PACKAGE_ID}/index.json"
67+
68+ version_exists_on_nuget() {
69+ local candidate_version="$1"
70+ # NuGet package IDs are case-insensitive and returned versions are lowercase.
71+ echo "$NUGET_VERSIONS" | grep -qi "\"${candidate_version,,}\""
72+ }
73+
74+ bump_patch() {
75+ local version="$1"
76+ IFS='.' read -r v1 v2 v3 <<< "$version"
77+ echo "${v1}.${v2}.$((v3 + 1))"
78+ }
79+
80+ NUGET_VERSIONS=$(curl -fsSL "$NUGET_INDEX_URL" || true)
81+ if [ -z "$NUGET_VERSIONS" ]; then
82+ echo "Warning: Could not fetch published versions from NuGet. Proceeding with tag-based versioning only."
83+ fi
6584
6685 if [ -z "$LAST_CLIENT_TAG" ]; then
6786 # No previous client tag, start with version from csproj
6887 CURRENT_VERSION=$(grep '<Version>' ./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj | sed 's/.*<Version>\(.*\)<\/Version>.*/\1/')
69- echo "No previous client tag found, using csproj version: $CURRENT_VERSION"
70- echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
88+ NEW_VERSION="$CURRENT_VERSION"
89+
90+ if [ ! -z "$NUGET_VERSIONS" ]; then
91+ while version_exists_on_nuget "$NEW_VERSION"; do
92+ echo "Version $NEW_VERSION already exists on NuGet. Incrementing patch version."
93+ NEW_VERSION=$(bump_patch "$NEW_VERSION")
94+ done
95+ fi
96+
97+ echo "No previous client tag found, selected version: $NEW_VERSION"
98+ echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
7199 exit 0
72100 fi
73101
@@ -104,6 +132,13 @@ jobs:
104132 else
105133 NEW_VERSION="${c1}.${c2}.$((c3 + 1))"
106134 fi
135+
136+ if [ ! -z "$NUGET_VERSIONS" ]; then
137+ while version_exists_on_nuget "$NEW_VERSION"; do
138+ echo "Version $NEW_VERSION already exists on NuGet. Incrementing patch version."
139+ NEW_VERSION=$(bump_patch "$NEW_VERSION")
140+ done
141+ fi
107142
108143 echo "Incrementing version ($BUMP_TYPE): $LAST_VERSION -> $NEW_VERSION"
109144 echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
@@ -112,7 +147,7 @@ jobs:
112147 GH_TOKEN : ${{secrets.GITHUB_TOKEN}}
113148
114149 - name : Update csproj version
115- if : steps.calc_version .outputs.should_publish == 'true'
150+ if : steps.check_changes .outputs.has_changes == 'true'
116151 run : |
117152 NEW_VERSION="${{steps.calc_version.outputs.version}}"
118153 sed -i "s/<Version>.*<\/Version>/<Version>$NEW_VERSION<\/Version>/" \
@@ -121,33 +156,33 @@ jobs:
121156 working-directory : Xero-NetStandard
122157
123158 - name : Setup .NET
124- if : steps.calc_version .outputs.should_publish == 'true'
159+ if : steps.check_changes .outputs.has_changes == 'true'
125160 uses : actions/setup-dotnet@v4
126161 with :
127162 dotnet-version : 8.0.x
128163
129164 - name : Restore dependencies
130- if : steps.calc_version .outputs.should_publish == 'true'
165+ if : steps.check_changes .outputs.has_changes == 'true'
131166 run : dotnet restore
132167 working-directory : Xero-NetStandard
133168
134169 - name : Build
135- if : steps.calc_version .outputs.should_publish == 'true'
170+ if : steps.check_changes .outputs.has_changes == 'true'
136171 run : dotnet build --no-restore
137172 working-directory : Xero-NetStandard
138173
139174 - name : Create OAuth2Client Package for Nuget.org
140- if : steps.calc_version .outputs.should_publish == 'true'
175+ if : steps.check_changes .outputs.has_changes == 'true'
141176 run : dotnet pack ./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj
142177 working-directory : Xero-NetStandard
143178
144179 - name : Publish OAuth2Client Package to Nuget.org
145- if : steps.calc_version .outputs.should_publish == 'true'
146- run : dotnet nuget push ./Xero.NetStandard.OAuth2Client/bin/Release/Xero.NetStandard.OAuth2Client.${{steps.calc_version.outputs.version}}.nupkg --api-key ${{ secrets.NUGET_APIKEY }} --source https://api.nuget.org/v3/index.json
180+ if : steps.check_changes .outputs.has_changes == 'true'
181+ run : dotnet nuget push ./Xero.NetStandard.OAuth2Client/bin/Release/Xero.NetStandard.OAuth2Client.${{steps.calc_version.outputs.version}}.nupkg --api-key ${{ secrets.NUGET_APIKEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
147182 working-directory : Xero-NetStandard
148183
149184 - name : Commit, Push and Tag
150- if : steps.calc_version .outputs.should_publish == 'true'
185+ if : steps.check_changes .outputs.has_changes == 'true'
151186 run : |
152187 git config user.name "github-actions[bot]"
153188 git config user.email "github-actions[bot]@users.noreply.github.com"
0 commit comments