-
Notifications
You must be signed in to change notification settings - Fork 20
253 lines (244 loc) · 9.24 KB
/
csharp_release.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
name: Publish Release To NuGet
on:
release:
types: [ published ] # Trigger on published pre-releases and releases
workflow_dispatch:
inputs:
tag:
description: 'Tag name'
required: true
default: 'v4.1.0'
jobs:
variables:
name: Set Variables
runs-on: ubuntu-latest
env:
TAG: ${{ github.event.release.tag_name || github.event.inputs.tag }}
steps:
- name: Extract semantic version from tag
id: set_version
run: |
# Remove the "v" prefix if it exists and extract the semantic version number
SEMANTIC_VERSION=$(echo "${TAG}" | grep -Po "(?<=^|[^0-9])([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?(-[a-zA-Z]+[0-9]*)?)")
SEMANTIC_VERSION=${SEMANTIC_VERSION#"v"}
if [ -z "${SEMANTIC_VERSION}" ]; then
echo "Error: Tag '${TAG}' does not start with a valid semantic version number (e.g., #.#.#; #.#.#.#; #.#.#.#-beta)"
exit 1
fi
echo "Extracted semantic version: ${SEMANTIC_VERSION}"
echo "semantic_version=${SEMANTIC_VERSION}" >> $GITHUB_OUTPUT
outputs:
tag: ${{ env.TAG }}
semanticVersion: ${{ steps.set_version.outputs.semantic_version }}
buildFrameworkVersions:
name: Build .NET Framework versions
needs: [ variables ]
runs-on: windows-2019 # required version for Framework 4.0
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.variables.outputs.tag }}
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2
- name: Setup NuGet
uses: nuget/setup-nuget@v2
- name: Restore NuGet packages
run: nuget restore ./OptimizelySDK.NETFramework.sln
- name: Build and strongly name assemblies
run: msbuild /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=$(pwd)/keypair.snk /p:Configuration=Release ./OptimizelySDK.NETFramework.sln
- name: Upload Framework artifacts
uses: actions/upload-artifact@v4
with:
name: unsigned-dlls-framework
if-no-files-found: error
path: ./**/bin/Release/**/Optimizely*.dll
buildStandard16:
name: Build .NET 1.6 version
needs: [ variables ]
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.variables.outputs.tag }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Restore dependencies
run: dotnet restore OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj
- name: Build and strongly name assemblies
run: dotnet build OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=$(pwd)/keypair.snk -c Release
- name: Upload Standard 1.6 artifact
uses: actions/upload-artifact@v4
with:
name: unsigned-dlls-standard16
if-no-files-found: error
path: ./**/bin/Release/**/Optimizely*.dll
buildStandard20:
name: Build .NET 2.0 version
needs: [ variables ]
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.variables.outputs.tag }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Restore dependencies
run: dotnet restore OptimizelySDK.NetStandard20/OptimizelySDK.NetStandard20.csproj
- name: Build and strongly name Standard 2.0 project
run: dotnet build OptimizelySDK.NetStandard20/OptimizelySDK.NetStandard20.csproj /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=$(pwd)/keypair.snk -c Release
- name: Build and strongly name assemblies
uses: actions/upload-artifact@v4
with:
name: unsigned-dlls-standard20
if-no-files-found: error
path: ./**/bin/Release/**/Optimizely*.dll
combineArtifacts:
name: Combine artifacts
needs: [ variables, buildFrameworkVersions, buildStandard16, buildStandard20 ]
runs-on: ubuntu-latest
steps:
- name: Download Framework artifacts
uses: actions/download-artifact@v4
with:
name: unsigned-dlls-framework
- name: Download Standard 1.6 artifacts
uses: actions/download-artifact@v4
with:
name: unsigned-dlls-standard16
- name: Download Standard 2.0 artifacts
uses: actions/download-artifact@v4
with:
name: unsigned-dlls-standard20
- name: Combine artifacts
run: |
mkdir -p ./unsigned-dlls
mv ./unsigned-dlls-framework/**/Optimizely*.dll ./unsigned-dlls/
mv ./unsigned-dlls-standard16/**/Optimizely*.dll ./unsigned-dlls/
mv ./unsigned-dlls-standard20/**/Optimizely*.dll ./unsigned-dlls/
- name: Upload combined artifacts
uses: actions/upload-artifact@v4
with:
name: unsigned-dlls
if-no-files-found: error
sign:
name: Send DLLs for signing
needs: [ variables, buildFrameworkVersions, buildStandard16, buildStandard20 ]
runs-on: ubuntu-latest
env:
# TODO: Replace actual values
SIGNING_SERVER_PRIVATE_KEY: ${{ secrets.SIGNING_SERVER_PRIVATE_KEY }}
SIGNING_SERVER_HOST: ${{ secrets.SIGNING_SERVER_HOST }}
SIGNING_SERVER_UPLOAD_PATH: /path/to/UPLOAD/directory
SIGNING_SERVER_DOWNLOAD_PATH: /path/to/DOWNLOAD/directory
steps:
# TODO: Remove this when we're ready to automate
- name: Temporarily halt progress
run: exit 1
- name: Download the unsigned files
uses: actions/download-artifact@v4
with:
name: unsigned-dlls
path: ./unsigned-dlls
- name: Setup SSH
uses: shimataro/ssh-key-action@v2
with:
key: $SIGNING_SERVER_PRIVATE_KEY
- name: Send files to signing server
run: scp -r ./unsigned-dlls $SIGNING_SERVER_HOST:$SIGNING_SERVER_UPLOAD_PATH
- name: Wait for artifact to be published
run: |
for i in {1..60}; do
# Replace with actual path
if ssh $SIGNING_SERVER_HOST "ls $SIGNING_SERVER_DOWNLOAD_PATH"; then
exit 0
fi
sleep 10
done
exit 1
- name: Download signed files
run: |
mkdir ./signed-dlls
scp -r $SIGNING_SERVER_HOST:$SIGNING_SERVER_DOWNLOAD_PATH ./signed-dlls
- name: Delete signed files from server
run: ssh $SIGNING_SERVER_HOST "rm -rf $SIGNING_SERVER_DOWNLOAD_PATH/*"
- name: Upload signed files
uses: actions/upload-artifact@v4
with:
name: signed-dlls
if-no-files-found: error
path: ./signed-dlls
pack:
name: Pack NuGet package
needs: [ variables, sign ]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.variables.outputs.semanticVersion }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.variables.outputs.tag }}
- name: Install mono
run: |
sudo apt update
sudo apt install -y mono-devel
- name: Download NuGet files
uses: actions/download-artifact@v4
with:
name: signed-dlls
path: ./signed-dlls
- name: Organize files
run: |
pushd ./signed-dlls
# Move all dlls to the root directory
find . -type f -name "*.dll" -exec mv {} .
popd
# Create directories
mkdir -p nuget/lib/net35/ nuget/lib/net40/ nuget/lib/net45/ nuget/lib/netstandard1.6/ nuget/lib/netstandard2.0/
pushd ./nuget
# Move files to directories
mv ../signed-dlls/OptimizelySDK.Net35.dll lib/net35/
mv ../signed-dlls/OptimizelySDK.Net40.dll lib/net40/
mv ../signed-dlls/OptimizelySDK.dll lib/net45/
mv ../signed-dlls/OptimizelySDK.NetStandard16.dll lib/netstandard1.6/
mv ../signed-dlls/OptimizelySDK.NetStandard20.dll lib/netstandard2.0/
popd
- name: Create nuspec
# Uses env.VERSION in OptimizelySDK.nuspec.template
run: |
chmod +x ./OptimizelySDK.nuspec.template
./OptimizelySDK.nuspec.template
- name: Pack NuGet package
run: |
pushd ./nuget
nuget pack OptimizelySDK.nuspec
popd
- name: Upload nupkg artifact
uses: actions/upload-artifact@v4
with:
name: nuget-package
if-no-files-found: error
path: ./nuget/Optimizely.SDK.${{ env.VERSION }}.nupkg
publish:
name: Publish package to NuGet after reviewing the artifact
needs: [ variables, pack ]
runs-on: ubuntu-latest
# Review the `nuget-package` artifact ensuring the dlls are
# organized and signed before approving.
environment: 'i-reviewed-nuget-package-artifact'
env:
VERSION: ${{ needs.variables.outputs.semanticVersion }}
steps:
- name: Download NuGet files
uses: actions/download-artifact@v4
with:
name: nuget-package
path: ./nuget
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Publish NuGet package
run: |
dotnet nuget push ./nuget/Optimizely.SDK.${{ env.VERSION }}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}