@@ -2,14 +2,28 @@ name: Build NuGet Package
22on :
33 push :
44 tags : [ '[0-9]+.[0-9]+.[0-9]+' ]
5- pull_request :
6- tags : [ '[0-9]+.[0-9]+.[0-9]+' ]
75 workflow_dispatch :
6+ inputs :
7+ version :
8+ description : ' The optional semantic version number. If not supplied the branch/tag will be used.'
9+ type : string
10+ no_publish :
11+ description : ' Prevent publishing the NuGet package. Just build it and then upload it as an artifact.'
12+ type : boolean
13+ default : false
814
915jobs :
1016 package-windows-latest :
1117 runs-on : windows-latest
1218 steps :
19+ - name : Set version based on input
20+ if : ${{ inputs.version }}
21+ run : echo "RELEASE_VERSION=${{ inputs.version }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8
22+ - name : Set version based on ref
23+ if : ${{ !inputs.version }}
24+ run : echo "RELEASE_VERSION=$($env:GITHUB_REF -replace 'refs/.*/', '')" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8
25+ - name : Print Version
26+ run : echo "NuGet version will be '${{ env.RELEASE_VERSION }}'"
1327 - name : Checkout
1428 uses : actions/checkout@v3
1529 with :
@@ -82,17 +96,11 @@ jobs:
8296 install-options : --prefix ${{github.workspace}}\install --config Debug
8397 - name : " [Debug_x64] Copy install files for Debug_x64"
8498 run : xcopy /e /i /y ${{github.workspace}}\install ${{github.workspace}}\nuget\build\native\x64\Debug
85- - name : " Get latest release tag"
86- uses : oprypin/find-latest-tag@v1
87- with :
88- repository : libcpr/cpr
89- releases-only : true
90- id : find_release_tag
9199 - name : " Copy Readme.md"
92100 run : xcopy /y ${{github.workspace}}\README.md ${{github.workspace}}\nuget
93101 - name : " Create NuGet package"
94102 env :
95- VERSION : ${{ steps.find_release_tag.outputs.tag }}
103+ VERSION : ${{ env.RELEASE_VERSION }}
96104 COMMIT_HASH : ${{ github.sha }}
97105 run : nuget pack ${{github.workspace}}\nuget\libcpr.nuspec -OutputDirectory ${{github.workspace}} -Properties "VERSION=$ENV:VERSION;COMMIT_HASH=$ENV:COMMIT_HASH"
98106 - name : " Upload artifact"
@@ -101,6 +109,7 @@ jobs:
101109 name : artifact-nuget
102110 path : ${{github.workspace}}\*.nupkg
103111 - name : " Publish package to NuGet.org"
112+ if : ${{ !inputs.no_publish }}
104113 env :
105114 NUGET_API_KEY : ${{ secrets.NUGET_API_KEY }}
106115 run : nuget push ${{github.workspace}}\*.nupkg $ENV:NUGET_API_KEY -Source https://api.nuget.org/v3/index.json
0 commit comments