Skip to content

Commit f453c9d

Browse files
committed
fix: restore manual_version input, branch gating, and NuGet.org publishing to publish.yml
1 parent bb26caf commit f453c9d

1 file changed

Lines changed: 81 additions & 7 deletions

File tree

.github/workflows/publish.yml

Lines changed: 81 additions & 7 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*"
@@ -13,6 +18,10 @@ permissions:
1318
jobs:
1419
pack_and_publish:
1520
runs-on: macos-latest
21+
permissions:
22+
contents: read
23+
packages: write
24+
id-token: write
1625
steps:
1726
- uses: actions/checkout@v4
1827
with:
@@ -22,24 +31,69 @@ jobs:
2231
id: version
2332
shell: bash
2433
run: |
25-
if [[ "${{ github.ref }}" =~ ^refs/tags/v ]]; then
26-
REF="${{ github.ref }}"
34+
REF="${{ github.ref }}"
35+
EVENT="${{ github.event_name }}"
36+
MANUAL_VERSION="${{ github.event.inputs.manual_version }}"
37+
CSPROJ="src/Kapusch.StoreKit2ApisForiOSComponents/Kapusch.StoreKit2ApisForiOSComponents.csproj"
38+
BASE_VERSION=$(grep -oE '<Version>[^<]+' "$CSPROJ" | head -n 1 | sed 's/<Version>//' || echo "1.0.0")
39+
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
2745
VERSION="${REF#refs/tags/v}"
46+
PUBLISH_TARGET="nuget"
2847
else
29-
CSPROJ="src/Kapusch.StoreKit2ApisForiOSComponents/Kapusch.StoreKit2ApisForiOSComponents.csproj"
30-
BASE_VERSION=$(grep -oE '<Version>[^<]+' "$CSPROJ" | head -n 1 | sed 's/<Version>//' || echo "0.1.0")
3148
COMMIT_SHORT=$(git rev-parse --short HEAD)
3249
RUN_NUMBER="${{ github.run_number }}"
33-
VERSION="${BASE_VERSION}-prerelease.${RUN_NUMBER}.${COMMIT_SHORT}"
50+
VERSION="${BASE_VERSION}-preview.${RUN_NUMBER}.${COMMIT_SHORT}"
51+
PUBLISH_TARGET="github"
3452
fi
53+
54+
if [[ "$PUBLISH_TARGET" == "nuget" ]]; then
55+
git fetch origin +refs/heads/*:refs/remotes/origin/*
56+
TAGGED_SHA="${{ github.sha }}"
57+
CONTAINING_BRANCHES=$(git for-each-ref --format='%(refname:short)' refs/remotes/origin --contains "$TAGGED_SHA")
58+
59+
ON_MASTER="false"
60+
ON_RELEASE="false"
61+
while IFS= read -r branch; do
62+
[[ "$branch" == "origin/master" ]] && ON_MASTER="true"
63+
[[ "$branch" == origin/release/* ]] && ON_RELEASE="true"
64+
done <<< "$CONTAINING_BRANCHES"
65+
66+
if [[ "$VERSION" == *-* ]]; then
67+
if [[ "$ON_RELEASE" != "true" ]]; then
68+
echo "ERROR: Pre-release version $VERSION must be on origin/release/*"
69+
exit 1
70+
fi
71+
else
72+
if [[ "$ON_MASTER" != "true" ]]; then
73+
echo "ERROR: Stable version $VERSION must be on origin/master"
74+
exit 1
75+
fi
76+
fi
77+
fi
78+
3579
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
80+
echo "publish_target=${PUBLISH_TARGET}" >> "$GITHUB_OUTPUT"
81+
echo "Package version: ${VERSION}"
82+
echo "Publish target: ${PUBLISH_TARGET}"
3683
3784
- uses: actions/setup-dotnet@v4
3885
with:
3986
dotnet-version: "10.0.x"
4087

4188
- name: Install iOS workload
42-
run: dotnet workload install ios
89+
run: |
90+
dotnet workload install ios
91+
92+
- name: Cache NuGet
93+
uses: actions/cache@v4
94+
with:
95+
path: ~/.nuget/packages
96+
key: ${{ runner.os }}-nuget-${{ hashFiles('global.json', '**/*.csproj') }}
4397

4498
- name: Build iOS wrapper
4599
run: |
@@ -80,10 +134,30 @@ jobs:
80134
print(f" - {p}")
81135
sys.exit(1)
82136
137+
if "Info.plist" in names:
138+
print("ERROR: wrapper appears flattened (found 'Info.plist' at package root).")
139+
sys.exit(1)
140+
83141
print("OK: nupkg layout looks correct.")
84142
PY
85143
86-
- name: Push to GitHub Packages
144+
- name: Push to NuGet.org
145+
if: steps.version.outputs.publish_target == 'nuget'
146+
uses: NuGet/login@v1
147+
id: nuget_login
148+
with:
149+
user: ${{ secrets.NUGET_USER }}
150+
151+
- name: Publish to NuGet.org
152+
if: steps.version.outputs.publish_target == 'nuget'
153+
run: |
154+
dotnet nuget push artifacts/nuget/*.nupkg \
155+
--api-key "${{ steps.nuget_login.outputs.NUGET_API_KEY }}" \
156+
--source "https://api.nuget.org/v3/index.json" \
157+
--skip-duplicate
158+
159+
- name: Publish to GitHub Packages
160+
if: steps.version.outputs.publish_target == 'github'
87161
env:
88162
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89163
run: |

0 commit comments

Comments
 (0)