Skip to content

Commit 067f3be

Browse files
committed
ci: route publish to NuGet.org for tags and GitHub Packages for previews; change version to 1.0.0
1 parent 3c24d71 commit 067f3be

3 files changed

Lines changed: 78 additions & 8 deletions

File tree

.github/workflows/publish.yml

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ permissions:
1313
jobs:
1414
pack_and_publish:
1515
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
id-token: write
1620
steps:
1721
- uses: actions/checkout@v4
1822
with:
@@ -22,18 +26,48 @@ jobs:
2226
id: version
2327
shell: bash
2428
run: |
25-
if [[ "${{ github.ref }}" =~ ^refs/tags/v ]]; then
26-
REF="${{ github.ref }}"
29+
REF="${{ github.ref }}"
30+
EVENT="${{ github.event_name }}"
31+
CSPROJ="src/Kapusch.FacebookApisForAndroidComponents/Kapusch.FacebookApisForAndroidComponents.csproj"
32+
BASE_VERSION=$(grep -oE '<Version>[^<]+' "$CSPROJ" | head -n 1 | sed 's/<Version>//' || echo "0.1.0")
33+
34+
if [[ "$REF" =~ ^refs/tags/v ]]; then
2735
VERSION="${REF#refs/tags/v}"
36+
PUBLISH_TARGET="nuget"
37+
38+
git fetch origin +refs/heads/*:refs/remotes/origin/*
39+
TAGGED_SHA="${{ github.sha }}"
40+
CONTAINING_BRANCHES=$(git for-each-ref --format='%(refname:short)' refs/remotes/origin --contains "$TAGGED_SHA")
41+
42+
ON_MASTER="false"
43+
ON_RELEASE="false"
44+
while IFS= read -r branch; do
45+
[[ "$branch" == "origin/master" ]] && ON_MASTER="true"
46+
[[ "$branch" == origin/release/* ]] && ON_RELEASE="true"
47+
done <<< "$CONTAINING_BRANCHES"
48+
49+
if [[ "$VERSION" == *-* ]]; then
50+
if [[ "$ON_RELEASE" != "true" ]]; then
51+
echo "ERROR: Pre-release tag v$VERSION must point to a commit contained in origin/release/*"
52+
exit 1
53+
fi
54+
else
55+
if [[ "$ON_MASTER" != "true" ]]; then
56+
echo "ERROR: Stable tag v$VERSION must point to a commit contained in origin/master"
57+
exit 1
58+
fi
59+
fi
2860
else
29-
CSPROJ="src/Kapusch.FacebookApisForAndroidComponents/Kapusch.FacebookApisForAndroidComponents.csproj"
30-
BASE_VERSION=$(grep -oE '<Version>[^<]+' "$CSPROJ" | head -n 1 | sed 's/<Version>//' || echo "0.1.0")
3161
COMMIT_SHORT=$(git rev-parse --short HEAD)
3262
RUN_NUMBER="${{ github.run_number }}"
33-
VERSION="${BASE_VERSION}-prerelease.${RUN_NUMBER}.${COMMIT_SHORT}"
63+
VERSION="${BASE_VERSION}-preview.${RUN_NUMBER}.${COMMIT_SHORT}"
64+
PUBLISH_TARGET="github"
3465
fi
66+
3567
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
68+
echo "publish_target=${PUBLISH_TARGET}" >> "$GITHUB_OUTPUT"
3669
echo "Package version: ${VERSION}"
70+
echo "Publish target: ${PUBLISH_TARGET}"
3771
3872
- uses: actions/setup-dotnet@v4
3973
with:
@@ -72,7 +106,23 @@ jobs:
72106
-o artifacts/nuget \
73107
/p:PackageVersion="${{ steps.version.outputs.version }}"
74108
109+
- name: Push to NuGet.org
110+
if: steps.version.outputs.publish_target == 'nuget'
111+
uses: NuGet/login@v1
112+
id: nuget_login
113+
with:
114+
user: ${{ secrets.NUGET_USER }}
115+
116+
- name: Push to NuGet.org
117+
if: steps.version.outputs.publish_target == 'nuget'
118+
run: |
119+
dotnet nuget push artifacts/nuget/*.nupkg \
120+
--api-key "${{ steps.nuget_login.outputs.NUGET_API_KEY }}" \
121+
--source "https://api.nuget.org/v3/index.json" \
122+
--skip-duplicate
123+
75124
- name: Push to GitHub Packages
125+
if: steps.version.outputs.publish_target == 'github'
76126
env:
77127
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78128
run: |

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,30 @@ Pack the NuGet:
4141

4242
## Consumption
4343

44-
- Install the package from GitHub Packages (pre-release).
44+
- Install the package from NuGet.org for public release tags.
45+
- Install the package from GitHub Packages for internal preview builds.
4546
- Follow `Docs/Integration.md` for required AndroidManifest entries / meta-data.
4647

4748
## CI
4849

4950
- PR CI is build-only.
50-
- Publishing is handled by a workflow that pushes a pre-release to GitHub Packages.
51+
- Publishing is handled by `.github/workflows/publish.yml` with channel routing:
52+
- tag `vX.Y.Z` on `master` -> NuGet.org (stable)
53+
- tag `vX.Y.Z-rc.N` on `release/*` -> NuGet.org (pre-release)
54+
- non-tag runs (`workflow_dispatch`) -> GitHub Packages (`X.Y.Z-preview.<run>.<sha>`)
55+
- NuGet.org publishing uses NuGet Trusted Publishing (OIDC via `NuGet/login@v1`), no long-lived NuGet API key.
56+
57+
### Required GitHub secret
58+
59+
- `NUGET_USER`: your nuget.org profile username (not email), used by `NuGet/login@v1`.
60+
61+
## Release examples
62+
63+
- Pre-release candidate from a release branch:
64+
- `git checkout release/1.0.0`
65+
- `git tag v1.0.0-rc.1`
66+
- `git push origin v1.0.0-rc.1`
67+
- Stable release from master:
68+
- `git checkout master`
69+
- `git tag v1.0.0`
70+
- `git push origin v1.0.0`

src/Kapusch.FacebookApisForAndroidComponents/Kapusch.FacebookApisForAndroidComponents.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<NoWarn>$(NoWarn);NU5128</NoWarn>
1616
<AssemblyName>Kapusch.Facebook.Android</AssemblyName>
1717
<RootNamespace>Kapusch.Facebook.Android</RootNamespace>
18-
<Version>0.1.0</Version>
18+
<Version>1.0.0</Version>
1919
<PackageReadmeFile>nuget-readme.md</PackageReadmeFile>
2020
<InteropAndroidWrapperAar
2121
Condition="'$(InteropAndroidWrapperAar)' == '' and Exists('Native/Android/build/aar/kfb-facebookinterop-release.aar')"

0 commit comments

Comments
 (0)