Skip to content

Commit 886e3f2

Browse files
committed
ci(dotnet): sync NuGet version tags with tags and prevent duplicate publishes
1 parent 31ea30c commit 886e3f2

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

.github/workflows/release-binaries.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ jobs:
145145
echo "Version already matches tag, skipping"
146146
fi
147147
148-
- name: Check if version exists
148+
- name: Check if npm version exists
149149
working-directory: node_version
150150
run: |
151151
PACKAGE_NAME=$(node -p "require('./package.json').name")
@@ -179,10 +179,36 @@ jobs:
179179
with:
180180
dotnet-version: 8.0.x
181181

182+
- name: Sync .NET version with tag
183+
working-directory: dotnet_version
184+
shell: bash
185+
run: |
186+
VERSION=${GITHUB_REF#refs/tags/v}
187+
188+
CURRENT=$(grep -oPm1 "(?<=<Version>)[^<]+" ExplainThisRepo.csproj)
189+
190+
if [ "$VERSION" != "$CURRENT" ]; then
191+
sed -i "s|<Version>.*</Version>|<Version>$VERSION</Version>|" ExplainThisRepo.csproj
192+
else
193+
echo "Version already matches tag, skipping"
194+
fi
195+
182196
- name: Build and Pack .NET Global Tool
183197
working-directory: dotnet_version
184198
run: dotnet pack -c Release
185199

200+
- name: Check if NuGet version exists
201+
working-directory: dotnet_version
202+
shell: bash
203+
run: |
204+
PACKAGE_ID=$(grep -oPm1 "(?<=<ToolCommandName>)[^<]+" ExplainThisRepo.csproj)
205+
VERSION=$(grep -oPm1 "(?<=<Version>)[^<]+" ExplainThisRepo.csproj)
206+
207+
if curl -fsSL "https://api.nuget.org/v3-flatcontainer/${PACKAGE_ID,,}/index.json" | grep "\"$VERSION\"" >/dev/null; then
208+
echo "Version already exists on NuGet"
209+
exit 1
210+
fi
211+
186212
- name: Publish to NuGet
187213
working-directory: dotnet_version
188214
env:

0 commit comments

Comments
 (0)