7
7
description : Deployment environment
8
8
type : choice
9
9
options :
10
- - staging
10
+ - pkg.github.com
11
11
- nuget.org
12
- default : staging
12
+ default : pkg.github.com
13
13
required : true
14
14
preview :
15
15
description : Append preview suffix
16
16
type : boolean
17
17
default : true
18
18
required : true
19
+ dry_run :
20
+ description : ' Dry-run only (no deploy)'
21
+ type : boolean
22
+ default : true
23
+ required : true
19
24
20
25
concurrency :
21
26
group : ${{ inputs.environment }}
34
39
with :
35
40
fetch-depth : 0
36
41
42
+ - name : Setup .NET
43
+ uses : actions/setup-dotnet@v4
44
+ with :
45
+ dotnet-version : " 9.x"
46
+ dotnet-quality : " ga"
47
+
37
48
- name : Setup GitVersion
38
49
uses :
gittools/actions/gitversion/[email protected]
39
50
with :
@@ -51,21 +62,19 @@ jobs:
51
62
- name : Compose version
52
63
id : compose
53
64
run : |
54
- ver=${{ steps.gitversion.outputs.majorMinorPatch }}${{ inputs.preview && '-preview.' || '' }}${{ inputs.preview && steps.gitversion.outputs.preReleaseNumber || inputs.preview && github.run_number || '' }}
55
- echo "version=$ver" >> "$GITHUB_OUTPUT "
65
+ # get base version
66
+ base="${{ steps.gitversion.outputs.majorMinorPatch }} "
56
67
57
- - name : Update release notes URL
58
- uses : jacobtomlinson/gha-find-replace@v3
59
- with :
60
- find : " <PackageReleaseNotes>https://github.com/DaveSkender/Stock.Indicators/releases</PackageReleaseNotes>"
61
- replace : " <PackageReleaseNotes>https://github.com/DaveSkender/Stock.Indicators/releases/tag/${{ steps.compose.outputs.version }}</PackageReleaseNotes>"
62
- regex : false
68
+ # determine preview suffix
69
+ preview_tag="${{ inputs.preview && '-preview.' || '' }}"
63
70
64
- - name : Setup .NET
65
- uses : actions/setup-dotnet@v4
66
- with :
67
- dotnet-version : " 9.x"
68
- dotnet-quality : " ga"
71
+ # determine preview number
72
+ preview_num="${{ inputs.preview && steps.gitversion.outputs.preReleaseNumber || '' }}"
73
+
74
+ # combine all parts
75
+ ver="${base}${preview_tag}${preview_num}"
76
+
77
+ echo "version=$ver" >> "$GITHUB_OUTPUT"
69
78
70
79
- name : Build library
71
80
run : >
@@ -106,28 +115,18 @@ jobs:
106
115
deploy :
107
116
needs : build
108
117
runs-on : ubuntu-latest
118
+ if : success()
109
119
110
120
permissions :
111
121
contents : write
112
122
packages : write
113
123
114
124
environment :
115
- name : ${{ inputs.environment }}
116
- url : " ${{ vars.NUGET_DOWNLOAD_PREFIX }}${{ needs.build. outputs.version }}"
125
+ name : ${{ ! inputs.dry_run && inputs. environment || '' }}
126
+ url : ${{ steps.package_info. outputs.url }}
117
127
118
128
steps :
119
129
120
- - name : Pre-flight summary
121
- run : |
122
- {
123
- echo "| Parameter | Value |"
124
- echo "| :-------------- | :--------------------------------- |"
125
- echo "| Environment | ${{ inputs.environment }} |"
126
- echo "| Publishing URL | ${{ vars.NUGET_PUBLISH_URL }} |"
127
- echo "| Download URL | ${{ vars.NUGET_DOWNLOAD_PREFIX }} |"
128
- echo "| Version ID | ${{ needs.build.outputs.version }} |"
129
- } >> $GITHUB_STEP_SUMMARY
130
-
131
130
- name : Setup .NET
132
131
uses : actions/setup-dotnet@v4
133
132
with :
@@ -146,28 +145,59 @@ jobs:
146
145
name : packages
147
146
path : NuGet
148
147
149
- - name : Publish to GitHub Packages (staging)
150
- if : inputs.environment == 'staging'
151
- run : |
152
- dotnet nuget push NuGet/*.nupkg --source "https://nuget.pkg.github.com/DaveSkender/index.json" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
153
-
154
- - name : Publish to NuGet.org
155
- if : inputs.environment == 'nuget.org'
148
+ - name : Compose package info
149
+ id : package_info
156
150
run : |
157
- dotnet new nugetconfig --force
158
- nuget setApiKey ${{ secrets.NUGET_TOKEN }} -src nuget -ConfigFile nuget.config
159
- nuget push NuGet/*.nupkg -src nuget -NonInteractive -ConfigFile nuget.config -Verbosity Detailed
151
+ PACKAGE_NAME=$(xmllint --xpath "//PropertyGroup/PackageId/text()" Directory.Build.props || xmllint --xpath "//PropertyGroup/PackageId/text()" **/*.csproj)
152
+ echo "pkg_name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT
153
+ if [[ "${{ inputs.environment }}" == "nuget.org" ]]; then
154
+ echo "pkg_url=https://www.nuget.org/packages/${PACKAGE_NAME}/${{ needs.build.outputs.version }}" >> $GITHUB_OUTPUT
155
+ else
156
+ echo "pkg_url=https://github.com/${{ github.repository }}/packages/nuget/${PACKAGE_NAME}/${{ needs.build.outputs.version }}" >> $GITHUB_OUTPUT
157
+ fi
158
+
159
+ - name : Publish package
160
+ if : ${{ !inputs.dry_run }}
161
+ env :
162
+ API_KEY : ${{ inputs.environment == 'nuget.org' && secrets.NUGET_TOKEN || secrets.GITHUB_TOKEN }}
163
+ run : >
164
+ dotnet nuget push NuGet/*.nupkg
165
+ --source "${{ vars.NUGET_PUBLISH_URL }}"
166
+ --api-key "$API_KEY"
167
+ --skip-duplicate
160
168
161
169
- name : Tag and draft release note
162
170
uses : ncipollo/release-action@v1
163
- if : inputs.environment == 'nuget.org'
171
+ if : ${{ ! inputs.dry_run && inputs. environment == 'nuget.org' }}
164
172
with :
165
173
body : |
166
- We’ve released a new Stock Indicators for .NET NuGet package.
167
- See [Skender.Stock.Indicators @ NuGet.org](${{ vars.NUGET_DOWNLOAD_PREFIX }}${{ needs.build.outputs.version }}) for more information.
174
+ ## Release ${{ needs.build.outputs.version }}
175
+
176
+ 📦 Package deployed to [${{ inputs.environment }}](${{ steps.package_info.outputs.pkg_url }})
177
+
178
+ ### Package Details
179
+ - **Name**: ${{ steps.package_info.outputs.pkg_name }}
180
+ - **Version**: ${{ needs.build.outputs.version }}
181
+ - **Preview**: ${{ inputs.preview && 'Yes' || 'No' }}
168
182
generateReleaseNotes : true
169
183
draft : true
170
184
makeLatest : ${{ !inputs.preview }}
171
185
prerelease : ${{ inputs.preview }}
172
- tag : ${{ needs.build.outputs.version }}
173
- commit : ${{ github.ref_name }}
186
+ tag : v${{ needs.build.outputs.version }}
187
+ commit : ${{ github.sha }}
188
+ token : ${{ secrets.GITHUB_TOKEN }}
189
+
190
+ - name : Deployment summary
191
+ if : always()
192
+ run : |
193
+ {
194
+ echo "## Package Deployment"
195
+ echo "| Parameter | Value |"
196
+ echo "|:------------|:------|"
197
+ echo "| Mode | ${{ inputs.dry_run && '🔍 DRY RUN' || '🚀 DEPLOY' }} |"
198
+ echo "| Status | ${{ job.status == 'success' && '✅ Success' || '❌ Failed' }} |"
199
+ echo "| Environment | ${{ inputs.environment }} |"
200
+ echo "| Version | ${{ needs.build.outputs.version }} |"
201
+ echo "| Package | [${{ steps.package_info.outputs.pkg_name }}](${{ steps.package_info.outputs.pkg_url }}) |"
202
+ echo "| Preview | ${{ inputs.preview && '✓' || '✗' }} |"
203
+ } >> $GITHUB_STEP_SUMMARY
0 commit comments