1313 permissions :
1414 contents : read
1515 id-token : write # Required for NuGet OIDC authentication
16+ packages : write
1617
1718 steps :
1819 - name : Checkout
@@ -26,18 +27,44 @@ jobs:
2627 dotnet-version : |
2728 10.0.x
2829
29- - name : Install GitVersion
30- uses : gittools/actions/gitversion/setup@v4
31- with :
32- versionSpec : " 6.4.0"
30+ - name : Get version
31+ id : get-version
32+ run : |
33+ if [ "${{ github.ref_type }}" = "tag" ]; then
34+ # Strip 'release/v' prefix if present
35+ VERSION=${GITHUB_REF_NAME#release/v}
36+ PACKAGE_VERSION=$VERSION
37+ else
38+ # Get latest tag from history, fallback to 1.0.0 if none exist
39+ LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "release/v1.0.0")
3340
34- - name : Determine Version
35- id : gitversion
36- uses : gittools/actions/gitversion/execute@v4
37- with :
38- configFilePath : " GitVersion.yml"
41+ # Strip 'release/v' and split into Major.Minor.Patch
42+ CLEAN_TAG=${LATEST_TAG#release/v}
43+ IFS='.' read -r MAJOR MINOR RAW_PATCH <<< "$CLEAN_TAG"
44+
45+ # Strip everything after the first digit in the patch (removes -beta, -rc, etc.)
46+ # This ensures "3-rc.1" becomes just "3"
47+ PATCH=${RAW_PATCH%%[!0-9]*}
48+
49+ # Increment Patch by 1
50+ NEW_PATCH=$((PATCH + 1))
3951
40- # Cache packages for faster subsequent runs
52+ VERSION="$MAJOR.$MINOR.$NEW_PATCH"
53+
54+ if [ "${{ github.event_name }}" = "pull_request" ]; then
55+ # Append the PR number and build number
56+ PACKAGE_VERSION="$VERSION-PullRequest.${{ github.event.pull_request.number }}.${{ github.run_number }}"
57+ else
58+ # Append the branch and build number
59+ PACKAGE_VERSION="$VERSION-Branch.${{ github.ref_name }}.${{ github.run_number }}"
60+ fi
61+ fi
62+
63+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
64+ echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
65+ echo "INFORMATIONAL_VERSION=$PACKAGE_VERSION+${{ github.sha }}" >> $GITHUB_OUTPUT
66+
67+ # Cache packages for faster subsequent runs
4168 - uses : actions/cache@v5
4269 with :
4370 path : ~/.nuget/packages
@@ -49,10 +76,10 @@ jobs:
4976 run : dotnet restore
5077
5178 - name : Build
52- run : dotnet build --no-restore -c Release /p:Version=${{ steps.gitversion .outputs.semVer }}
79+ run : dotnet build --no-restore -c Release /p:Version=${{ steps.get-version .outputs.VERSION }} /p:InformationalVersion=${{ steps.get-version.outputs.INFORMATIONAL_VERSION }}
5380
5481 - name : Pack
55- run : dotnet pack --no-build -c Release /p:PackageVersion=${{ steps.gitversion .outputs.fullSemVer }}
82+ run : dotnet pack --no-build -c Release /p:PackageVersion=${{ steps.get-version .outputs.PACKAGE_VERSION }}
5683 - name : Upload Package Artifact
5784 uses : actions/upload-artifact@v6
5885 with :
6794 with :
6895 user : ${{ vars.NUGET_USER }}
6996
70- - name : Push
71- # Publish tagged releases
97+ - name : Push to NuGet.org
98+ # Publish tagged releases to NuGet.org
7299 if : ${{ startsWith(github.ref, 'refs/tags/release/') }}
73100 run : dotnet nuget push artifacts/package/release/*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
101+ - name : Push to GitHub Packages
102+ # Publish CI releases to GitHub packages
103+ if : ${{ !startsWith(github.ref, 'refs/tags/release/') }}
104+ run : |
105+ dotnet nuget add source https://nuget.pkg.github.com/couchbaselabs/index.json --name github --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text
106+ dotnet nuget push artifacts/package/release/*.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source github
0 commit comments