-
Notifications
You must be signed in to change notification settings - Fork 250
209 lines (177 loc) · 6.67 KB
/
deploy-package.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: Deploy NuGet package
on:
workflow_dispatch:
inputs:
environment:
description: Deployment environment
type: choice
options:
- pkg.github.com
- nuget.org
default: pkg.github.com
required: true
preview:
description: Append preview suffix
type: boolean
default: true
required: true
dry_run:
description: 'Dry-run only (no deploy)'
type: boolean
default: true
required: true
concurrency:
group: ${{ inputs.environment }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version_info.outputs.version }}
pkg_url: ${{ steps.package_info.outputs.pkg_url }}
pkg_name: ${{ steps.package_info.outputs.pkg_name }}
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.x"
dotnet-quality: "ga"
- name: Setup GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: "5.x"
preferLatestVersion: true
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libxml2-utils
- name: Determine version
id: gitversion
uses: gittools/actions/gitversion/[email protected]
with:
updateAssemblyInfo: true
useConfigFile: true
configFilePath: src/gitversion.yml
- name: Compose version
id: version_info
run: |
# get base version
base="${{ steps.gitversion.outputs.majorMinorPatch }}"
# determine preview suffix
preview_tag="${{ inputs.preview && '-preview.' || '' }}"
# determine preview number
preview_num="${{ inputs.preview && steps.gitversion.outputs.preReleaseNumber || '' }}"
# combine all parts
ver="${base}${preview_tag}${preview_num}"
echo "version=$ver" >> "$GITHUB_OUTPUT"
- name: Compose package info
id: package_info
run: |
PACKAGE_NAME=$(xmllint --xpath "//PropertyGroup/PackageId/text()" src/Indicators.csproj)
echo "pkg_name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT
if [[ "${{ inputs.environment }}" == "nuget.org" ]]; then
echo "pkg_url=https://www.nuget.org/packages/${PACKAGE_NAME}/${{ steps.version_info.outputs.version }}" >> $GITHUB_OUTPUT
else
echo "pkg_url=https://github.com/${{ github.repository }}/packages/nuget/${PACKAGE_NAME}/${{ steps.version_info.outputs.version }}" >> $GITHUB_OUTPUT
fi
- name: Build library
run: >
dotnet build src/Indicators.csproj
--configuration Release
--property:Version=${{ steps.version_info.outputs.version }}
--property:ContinuousIntegrationBuild=true
-warnAsError
- name: Pack for NuGet
run: >
dotnet pack src/Indicators.csproj
--configuration Release
--no-build
--include-symbols
--output NuGet
-p:PackageVersion=${{ steps.version_info.outputs.version }}
- name: Save package
uses: actions/upload-artifact@v4
with:
name: packages
path: NuGet
include-hidden-files: true
- name: Summary output
run: |
{
echo "| Version No. | Component |"
echo "| :---------- | :---------------------------------------------- |"
echo "| Major | ${{ steps.gitversion.outputs.major }} |"
echo "| Minor | ${{ steps.gitversion.outputs.minor }} |"
echo "| Patch | ${{ steps.gitversion.outputs.patch }} |"
echo "| Base | ${{ steps.gitversion.outputs.majorMinorPatch }} |"
echo "| Composed | ${{ steps.version_info.outputs.version }} |"
} >> $GITHUB_STEP_SUMMARY
deploy:
needs: build
runs-on: ubuntu-latest
if: success()
permissions:
contents: write
packages: write
environment:
name: ${{ !inputs.dry_run && inputs.environment || '' }}
url: ${{ needs.build.outputs.pkg_url }}
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.x"
dotnet-quality: "ga"
- name: Setup NuGet
uses: nuget/setup-nuget@v2
with:
nuget-api-key: ${{ secrets.NUGET_TOKEN }}
nuget-version: '6.x'
- name: Download package
uses: actions/download-artifact@v4
with:
name: packages
path: NuGet
- name: Publish package
if: ${{ !inputs.dry_run }}
env:
API_KEY: ${{ inputs.environment == 'nuget.org' && secrets.NUGET_TOKEN || secrets.GITHUB_TOKEN }}
run: >
dotnet nuget push NuGet/*.nupkg
--source "${{ vars.NUGET_PUBLISH_URL }}"
--api-key "$API_KEY"
--skip-duplicate
- name: Tag and draft release note
uses: ncipollo/release-action@v1
if: ${{ !inputs.dry_run && inputs.environment == 'nuget.org' }}
with:
body: |
## Release ${{ needs.build.outputs.version }}
📦 Package deployed to [${{ inputs.environment }}](${{ needs.build.outputs.pkg_url }})
### Package Details
- **Name**: ${{ needs.build.outputs.pkg_name }}
- **Version**: ${{ needs.build.outputs.version }}
- **Preview**: ${{ inputs.preview && 'Yes' || 'No' }}
generateReleaseNotes: true
draft: true
makeLatest: ${{ !inputs.preview }}
prerelease: ${{ inputs.preview }}
tag: v${{ needs.build.outputs.version }}
commit: ${{ github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Deployment summary
if: always()
run: |
{
echo "## Package Deployment"
echo "| Parameter | Value |"
echo "|:------------|:------|"
echo "| Mode | ${{ inputs.dry_run && '🔍 DRY RUN' || '🚀 DEPLOY' }} |"
echo "| Status | ${{ job.status == 'success' && '✅ Success' || '❌ Failed' }} |"
echo "| Environment | ${{ inputs.environment }} |"
echo "| Version | ${{ needs.build.outputs.version }} |"
echo "| Package | [${{ needs.build.outputs.pkg_name }}](${{ needs.build.outputs.pkg_url }}) |"
echo "| Preview | ${{ inputs.preview && '✓' || '✗' }} |"
} >> $GITHUB_STEP_SUMMARY