Skip to content

Commit 1b88347

Browse files
committed
ci: support manual version override for NuGet.org publish
1 parent fa4dc08 commit 1b88347

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

.github/workflows/publish.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ name: publish
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
manual_version:
7+
description: 'Force a specific version for NuGet.org publish (e.g., 1.0.0 or 1.0.0-rc.1). If empty, defaults to auto-generated preview for GitHub Packages.'
8+
required: false
9+
type: string
510
push:
611
tags:
712
- "v*"
@@ -28,13 +33,25 @@ jobs:
2833
run: |
2934
REF="${{ github.ref }}"
3035
EVENT="${{ github.event_name }}"
36+
MANUAL_VERSION="${{ github.event.inputs.manual_version }}"
3137
CSPROJ="src/Kapusch.FacebookApisForiOSComponents/Kapusch.FacebookApisForiOSComponents.csproj"
3238
BASE_VERSION=$(grep -oE '<Version>[^<]+' "$CSPROJ" | head -n 1 | sed 's/<Version>//' || echo "0.1.0")
3339
34-
if [[ "$REF" =~ ^refs/tags/v ]]; then
40+
if [[ -n "$MANUAL_VERSION" ]]; then
41+
VERSION="$MANUAL_VERSION"
42+
PUBLISH_TARGET="nuget"
43+
echo "Manual version provided ($VERSION). Triggering NuGet.org publish."
44+
elif [[ "$REF" =~ ^refs/tags/v ]]; then
3545
VERSION="${REF#refs/tags/v}"
3646
PUBLISH_TARGET="nuget"
47+
else
48+
COMMIT_SHORT=$(git rev-parse --short HEAD)
49+
RUN_NUMBER="${{ github.run_number }}"
50+
VERSION="${BASE_VERSION}-preview.${RUN_NUMBER}.${COMMIT_SHORT}"
51+
PUBLISH_TARGET="github"
52+
fi
3753
54+
if [[ "$PUBLISH_TARGET" == "nuget" ]]; then
3855
git fetch origin +refs/heads/*:refs/remotes/origin/*
3956
TAGGED_SHA="${{ github.sha }}"
4057
CONTAINING_BRANCHES=$(git for-each-ref --format='%(refname:short)' refs/remotes/origin --contains "$TAGGED_SHA")
@@ -48,20 +65,15 @@ jobs:
4865
4966
if [[ "$VERSION" == *-* ]]; then
5067
if [[ "$ON_RELEASE" != "true" ]]; then
51-
echo "ERROR: Pre-release tag v$VERSION must point to a commit contained in origin/release/*"
68+
echo "ERROR: Pre-release version $VERSION must be on origin/release/*"
5269
exit 1
5370
fi
5471
else
5572
if [[ "$ON_MASTER" != "true" ]]; then
56-
echo "ERROR: Stable tag v$VERSION must point to a commit contained in origin/master"
73+
echo "ERROR: Stable version $VERSION must be on origin/master"
5774
exit 1
5875
fi
5976
fi
60-
else
61-
COMMIT_SHORT=$(git rev-parse --short HEAD)
62-
RUN_NUMBER="${{ github.run_number }}"
63-
VERSION="${BASE_VERSION}-preview.${RUN_NUMBER}.${COMMIT_SHORT}"
64-
PUBLISH_TARGET="github"
6577
fi
6678
6779
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Pack the NuGet:
5151
- tag `vX.Y.Z` on `master` -> NuGet.org (stable)
5252
- tag `vX.Y.Z-rc.N` on `release/*` -> NuGet.org (pre-release)
5353
- non-tag runs (`workflow_dispatch`) -> GitHub Packages (`X.Y.Z-preview.<run>.<sha>`)
54+
- `workflow_dispatch` with `manual_version` -> NuGet.org (forced version)
5455
- NuGet.org publishing uses NuGet Trusted Publishing (OIDC via `NuGet/login@v1`), no long-lived NuGet API key.
5556

5657
### Required GitHub secret

0 commit comments

Comments
 (0)