Skip to content

Commit 93b0db2

Browse files
Update nbgv_dotnet_pack.yml
1 parent 73f2188 commit 93b0db2

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

.github/workflows/nbgv_dotnet_pack.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,33 @@ jobs:
133133
run: |
134134
set -euo pipefail
135135
KEEP=${{ inputs.prune_keep }}
136-
136+
137137
echo "Will keep the newest $KEEP version(s) for each pushed package."
138-
138+
139139
for nupkg in ./artifacts/*.nupkg; do
140140
pkgfile=$(basename "$nupkg")
141-
# More robust NuGet ID extraction (handles multi-dot names)
142-
id=$(echo "$pkgfile" | sed -E 's|^(.*)-[0-9]+\.[0-9]+(\.[0-9]+)*\.nupkg$|\1|')
141+
# Robust NuGet ID extraction (handles multi-dot names and prereleases)
142+
id=$(echo "$pkgfile" | sed -E 's|(.*)-[0-9]+\.[0-9]+(\.[0-9]+)*(-[A-Za-z0-9\.\-]+)?\.nupkg|\1|')
143143
echo "🔍 Processing $id …"
144-
145-
all=$(curl -sL "https://api.nuget.org/v3-flatcontainer/${id,,}/index.json" | jq -r '.versions[]')
146-
144+
145+
# Fetch package versions from NuGet, with error handling
146+
resp=$(curl -sL "https://api.nuget.org/v3-flatcontainer/${id,,}/index.json")
147+
if ! echo "$resp" | jq . >/dev/null 2>&1; then
148+
echo " ⚠️ Could not fetch versions for $id (maybe not published yet). Skipping."
149+
continue
150+
fi
151+
152+
all=$(echo "$resp" | jq -r '.versions[]')
147153
count=$(echo "$all" | wc -l)
148154
if [[ $count -le $KEEP ]]; then
149155
echo " Nothing to prune ($count ≤ $KEEP)."
150156
continue
151157
fi
152-
158+
153159
to_delete=$(echo "$all" | sort -Vr | tail -n +"$((KEEP+1))")
154-
160+
155161
while read -r ver; do
162+
if [[ -z "$ver" ]]; then continue; fi
156163
echo " 🗑️ Deleting $id $ver"
157164
dotnet nuget delete "$id" "$ver" \
158165
--source https://api.nuget.org/v3/index.json \
@@ -161,6 +168,7 @@ jobs:
161168
done <<< "$to_delete"
162169
done
163170

171+
164172
- name: 🚀 Create GitHub Release
165173
uses: softprops/action-gh-release@v2
166174
with:

0 commit comments

Comments
 (0)