Skip to content

Commit e395340

Browse files
committed
Fix package versioning for release
1 parent ffa2fba commit e395340

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

.github/workflows/release.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,27 @@ jobs:
104104
dotnet pack ClaudeCodeSharpSDK/ClaudeCodeSharpSDK.csproj --configuration Release --no-build -p:IncludeSymbols=false -p:SymbolPackageFormat=snupkg --output ./artifacts
105105
dotnet pack ClaudeCodeSharpSDK.Extensions.AI/ClaudeCodeSharpSDK.Extensions.AI.csproj --configuration Release --no-build -p:IncludeSymbols=false -p:SymbolPackageFormat=snupkg --output ./artifacts
106106
107+
- name: Validate packaged version
108+
shell: bash
109+
run: |
110+
set -euo pipefail
111+
VERSION="${{ steps.version.outputs.version }}"
112+
113+
mapfile -t packages < <(find ./artifacts -maxdepth 1 -type f -name '*.nupkg' | sort)
114+
if [ "${#packages[@]}" -eq 0 ]; then
115+
echo "No NuGet packages were created."
116+
exit 1
117+
fi
118+
119+
for package in "${packages[@]}"; do
120+
file_name=$(basename "$package")
121+
echo "Validating $file_name"
122+
if [[ "$file_name" != *".${VERSION}.nupkg" ]]; then
123+
echo "Package version mismatch: expected filename to end with .${VERSION}.nupkg"
124+
exit 1
125+
fi
126+
done
127+
107128
- name: Upload artifacts
108129
uses: actions/upload-artifact@v4
109130
with:
@@ -242,6 +263,25 @@ jobs:
242263
)
243264
244265
if [ "${{ steps.state.outputs.release_exists }}" = "true" ]; then
266+
mapfile -t existing_assets < <(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json assets --jq '.assets[].name')
267+
for asset in "${existing_assets[@]}"; do
268+
case "$asset" in
269+
ManagedCode.ClaudeCodeSharpSDK*.nupkg)
270+
keep_asset=false
271+
for package in "${packages[@]}"; do
272+
if [ "$asset" = "$(basename "$package")" ]; then
273+
keep_asset=true
274+
break
275+
fi
276+
done
277+
278+
if [ "$keep_asset" != "true" ]; then
279+
gh release delete-asset "$TAG" "$asset" --repo "$GITHUB_REPOSITORY" --yes
280+
fi
281+
;;
282+
esac
283+
done
284+
245285
gh release upload "$TAG" "${packages[@]}" --repo "$GITHUB_REPOSITORY" --clobber
246286
else
247287
gh release create "$TAG" "${packages[@]}" \

Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1414
<AnalysisLevel>latest-recommended</AnalysisLevel>
1515
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
16+
<Version>0.1.0</Version>
17+
<PackageVersion>$(Version)</PackageVersion>
1618

1719
</PropertyGroup>
1820

1921
<!-- NuGet package metadata and versioning -->
20-
<PropertyGroup Condition="'$(IsPackable)' == 'true'">
22+
<PropertyGroup>
2123
<Authors>ManagedCode</Authors>
2224
<Company>ManagedCode</Company>
2325
<RepositoryType>GitHub</RepositoryType>
@@ -28,11 +30,9 @@
2830
<PublishRepositoryUrl>true</PublishRepositoryUrl>
2931
<EmbedUntrackedSources>true</EmbedUntrackedSources>
3032
<EnablePackageValidation>true</EnablePackageValidation>
31-
<Version>0.1.0</Version>
32-
<PackageVersion>$(Version)</PackageVersion>
3333
</PropertyGroup>
3434

35-
<ItemGroup Condition="'$(IsPackable)' == 'true'">
35+
<ItemGroup>
3636
<None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath="/" Visible="false" />
3737
</ItemGroup>
3838

0 commit comments

Comments
 (0)