11name : Publish release
22
33on :
4- push :
5- branches :
6- - main
7- tags :
8- - v*
4+ workflow_dispatch :
5+ inputs :
6+ ref :
7+ description : Branch, tag, or SHA to release from
8+ default : master
9+ required : true
10+ publish_nuget :
11+ description : Push packages to NuGet
12+ type : boolean
13+ default : false
14+ publish_github :
15+ description : Create or update GitHub release
16+ type : boolean
17+ default : false
918
1019jobs :
1120 publish :
12- if : startsWith(github.ref, 'refs/tags/v')
1321 runs-on : ubuntu-latest
1422 permissions :
1523 contents : write
@@ -19,36 +27,58 @@ jobs:
1927 uses : actions/checkout@v4
2028 with :
2129 fetch-depth : 0
30+ ref : ${{ inputs.ref }}
2231
2332 - name : Set up .NET SDK
2433 uses : actions/setup-dotnet@v4
2534 with :
2635 dotnet-version : 8.0.x
2736
37+ - name : Restore .NET tools
38+ run : dotnet tool restore
39+
40+ - name : Compute semantic version
41+ id : gitversion
42+ shell : bash
43+ run : |
44+ set -euo pipefail
45+ JSON=$(dotnet tool run dotnet-gitversion /output json)
46+ echo "$JSON"
47+
48+ NUGET_VERSION=$(echo "$JSON" | jq -r '.NuGetVersion')
49+ FULL_SEMVER=$(echo "$JSON" | jq -r '.FullSemVer')
50+ SHORT_SHA=$(echo "$JSON" | jq -r '.ShortSha')
51+ MAJOR_MINOR_PATCH=$(echo "$JSON" | jq -r '.MajorMinorPatch')
52+ PR_LABEL=$(echo "$JSON" | jq -r '.PreReleaseLabel')
53+ PR_NUMBER=$(echo "$JSON" | jq -r '.PreReleaseNumber')
54+
55+ if [[ "$PR_LABEL" != "" && "$PR_LABEL" != "null" ]]; then
56+ printf -v PR_PADDED '%04d' "$PR_NUMBER"
57+ RELEASE_VERSION_PADDED="${MAJOR_MINOR_PATCH}-${PR_LABEL}.${PR_PADDED}"
58+ else
59+ RELEASE_VERSION_PADDED="$MAJOR_MINOR_PATCH"
60+ fi
61+
62+ echo "nugetVersion=$NUGET_VERSION" >> "$GITHUB_OUTPUT"
63+ echo "fullSemVer=$FULL_SEMVER" >> "$GITHUB_OUTPUT"
64+ echo "releaseVersionPadded=$RELEASE_VERSION_PADDED" >> "$GITHUB_OUTPUT"
65+ echo "informational=${NUGET_VERSION}+${SHORT_SHA}" >> "$GITHUB_OUTPUT"
66+
2867 - name : Restore
2968 run : dotnet restore LiteDB.sln
3069
3170 - name : Build
32- run : dotnet build LiteDB.sln --configuration Release --no-restore
71+ run : dotnet build LiteDB.sln --configuration Release --no-restore /p:ContinuousIntegrationBuild=true
3372
3473 - name : Test
35- timeout-minutes : 5
74+ timeout-minutes : 8
3675 run : dotnet test LiteDB.sln --configuration Release --no-build --verbosity normal --settings tests.runsettings --logger "trx;LogFileName=TestResults.trx" --logger "console;verbosity=detailed"
3776
3877 - name : Pack
39- run : |
40- dotnet pack LiteDB/LiteDB.csproj --configuration Release --no-build -o artifacts
41-
42- - name : Capture package version
43- id : version
44- run : |
45- PACKAGE_PATH=$(ls artifacts/LiteDB.*.nupkg | head -n 1)
46- PACKAGE_FILENAME=$(basename "$PACKAGE_PATH")
47- PACKAGE_VERSION=${PACKAGE_FILENAME#LiteDB.}
48- PACKAGE_VERSION=${PACKAGE_VERSION%.nupkg}
49- echo "package_version=${PACKAGE_VERSION}" >> "$GITHUB_OUTPUT"
78+ run : dotnet pack LiteDB/LiteDB.csproj --configuration Release --no-build -o artifacts /p:ContinuousIntegrationBuild=true
5079
5180 - name : Retrieve secrets from Bitwarden
81+ if : ${{ inputs.publish_nuget }}
5282 uses : bitwarden/sm-action@v2
5383 with :
5484 access_token : ${{ secrets.BW_ACCESS_TOKEN }}
@@ -57,15 +87,21 @@ jobs:
5787 265b2fb6-2cf0-4859-9bc8-b24c00ab4378 > NUGET_API_KEY
5888
5989 - name : Push package to NuGet
90+ if : ${{ inputs.publish_nuget }}
91+ env :
92+ PACKAGE_VERSION : ${{ steps.gitversion.outputs.nugetVersion }}
6093 run : |
94+ echo "Pushing LiteDB version $PACKAGE_VERSION"
6195 dotnet nuget push "artifacts/*.nupkg" --api-key "$NUGET_API_KEY" --source https://api.nuget.org/v3/index.json --skip-duplicate
6296
6397 - name : Publish GitHub release
98+ if : ${{ inputs.publish_github }}
6499 uses : softprops/action-gh-release@v2
65100 with :
66- tag_name : v${{ steps.version .outputs.package_version }}
67- name : LiteDB ${{ steps.version .outputs.package_version }}
101+ tag_name : v${{ steps.gitversion .outputs.releaseVersionPadded }}
102+ name : LiteDB ${{ steps.gitversion .outputs.releaseVersionPadded }}
68103 generate_release_notes : true
69104 files : artifacts/*.nupkg
105+ target_commitish : ${{ github.sha }}
70106 env :
71107 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments