ci: package version comes from project file only

This commit is contained in:
linmeideli committed 2026-09-25 18:46:26 +08:00
1 parent bcd18b7d85
commit b675d07d2e
1 file changed
+8 -15
+8 -15
View File
@@ -24,28 +24,21 @@ jobs:
with:
dotnet-version: 8.0.x
# Version scheme mirrors build.cake/nightly: <VersionPrefix>-ci.<CI run_number + 500>.
# The floor (max already-published ci.N + 1) keeps versions monotonic.
- name: Resolve version
# Package version = <VersionPrefix> in src/Empostor.Api/Empostor.Api.csproj.
# Bump it manually to release a new version; the -dev suffix is cleared
# so the package is published as a stable version. If the version
# already exists on nuget.org, push is skipped by --skip-duplicate.
- name: Read project version
id: ver
run: |
set -euo pipefail
PROJ=src/Empostor.Api/Empostor.Api.csproj
BASE=$(sed -n 's/.*<VersionPrefix>\([^<]*\)<\/VersionPrefix>.*/\1/p' "$PROJ" | head -1)
CI_RUN=$(curl -sf -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/ci.yml/runs?per_page=1" \
| jq -r '.workflow_runs[0].run_number')
N=$(( CI_RUN + 500 ))
MAXN=$(curl -sf "https://api.nuget.org/v3-flatcontainer/empostor.api/index.json" \
| jq -r '.versions[]' | grep -oE 'ci\.[0-9]+$' | grep -oE '[0-9]+$' | sort -n | tail -1 || true)
MAXN=${MAXN:-0}
if [ "$N" -le "$MAXN" ]; then N=$((MAXN + 1)); fi
echo "suffix=ci.${N}" >> "$GITHUB_OUTPUT"
echo "version=${BASE}-ci.${N}" >> "$GITHUB_OUTPUT"
echo "Publishing version: ${BASE}-ci.${N}"
echo "version=${BASE}" >> "$GITHUB_OUTPUT"
echo "Publishing version: ${BASE}"
- name: Pack
run: dotnet pack src/Empostor.Api/Empostor.Api.csproj -c Release -p:VersionSuffix=${{ steps.ver.outputs.suffix }} -p:GeneratePackageOnBuild=false -o artifacts --nologo
run: dotnet pack src/Empostor.Api/Empostor.Api.csproj -c Release -p:VersionSuffix= -p:GeneratePackageOnBuild=false -o artifacts --nologo
# Trusted publishing: exchanges the GitHub OIDC token for a short-lived
# nuget.org API key tied to the policy (no secret needed).