-
Notifications
You must be signed in to change notification settings - Fork 0
263 lines (230 loc) · 10.4 KB
/
publish.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
254
255
256
257
258
259
260
261
262
263
name: publish
env:
NUGET_URL: https://api.nuget.org/v3/index.json
INDEXING_TIMEOUT: 300 # seconds
DOTNET_SDK_VERSION: 8.0.201
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
ONEOF_REDUCED_PROJECT_PATH: ./src/OneOf.Reduced/OneOf.Reduced.csproj
STATERESULTS_PROJECT_PATH: ./src/StateResults/StateResults.csproj
STATERESULTS_GENERATOR_PROJECT_PATH: ./src/StateResults.Generator/StateResults.Generator.csproj
PUBLISH_DIR: publish
on:
push:
branches: [ main ]
jobs:
build-and-set-flags:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_SDK_VERSION }}
- name: Build & Test
run: |
dotnet --info
dotnet restore
dotnet build -c Release
- name: Test
id: test
run: |
dotnet test --no-restore --no-build -c Release --verbosity normal
# Also, setting the PRERELEASE flag depending on the contents of the version file.
- name: Read Version
id: read_version
run: |
VERSION_CONTENT=$(cat ${{ github.workspace }}/src/StateResults/VERSION.g.txt)
echo "VERSION=$VERSION_CONTENT"
echo "VERSION=$VERSION_CONTENT" >> $GITHUB_OUTPUT
if [[ "$VERSION_CONTENT" == *-* ]]; then
echo "PRERELEASE=true"
echo "PRERELEASE=true" >> $GITHUB_OUTPUT
else
echo "PRERELEASE=false"
echo "PRERELEASE=false" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Check VERSION and PRERELEASE variables
run: |
echo "VERSION=${{ steps.read_version.outputs.VERSION }}"
echo "PRERELEASE=${{ steps.read_version.outputs.PRERELEASE }}"
shell: sh
outputs:
VERSION: ${{ steps.read_version.outputs.VERSION }}
PRERELEASE: ${{ steps.read_version.outputs.PRERELEASE }}
publish-OneOf-Reduced:
needs: build-and-set-flags
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_SDK_VERSION }}
- name: Pack ${{ env.PACKAGE_NAME }}
run: |
dotnet pack ${{ env.ONEOF_REDUCED_PROJECT_PATH }} -c Release --include-symbols --include-source /p:PackageVersion=${{ needs.build-and-set-flags.outputs.VERSION }} -o .
- name: Upload Artifacts of BMTLab.OneOf.Reduced
uses: actions/upload-artifact@v4
with:
name: OneOf-Reduced-NuGetArtifacts
path: ./*.nupkg
- name: Check NuGet if ${{ env.PACKAGE_NAME }} is already pushed
id: check_pushed
run: |
chmod +x ${{ github.workspace }}/scripts/check-nuget-pkg-indexed.sh
PUSHED_RESULT=$(${{ github.workspace }}/scripts/check-nuget-pkg-indexed.sh -p "${{ env.PACKAGE_NAME }}" -v ${{ needs.build-and-set-flags.outputs.VERSION }} -a 1)
echo "PUSHED=$PUSHED_RESULT" >> $GITHUB_OUTPUT
shell: bash
continue-on-error: true
- name: Push NuGet for ${{ env.PACKAGE_NAME }}
if: ${{ steps.check_pushed.outputs.PUSHED != 'true' }}
run: dotnet nuget push ./*.nupkg --source ${{ env.NUGET_URL }} --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
env:
PACKAGE_NAME: BMTLab.OneOf.Reduced
update-package-version:
runs-on: ubuntu-latest
needs: [build-and-set-flags, publish-OneOf-Reduced]
steps:
- uses: actions/checkout@v4
with:
# Necessary for correct work with history and tags
fetch-depth: 0
- name: Update Directory.Packages.props
run: |
chmod +x ${{ github.workspace }}/scripts/rewrite-pkg-version.sh
${{ github.workspace }}/scripts/rewrite-pkg-version.sh -f "${{ github.workspace }}/Directory.Packages.props" -p "BMTLab.OneOf.Reduced" -v ${{ needs.build-and-set-flags.outputs.VERSION }}
shell: bash
- name: Commit updated version
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Actions"
git add Directory.Packages.props
git commit -m "[GitHub Actions] Release ${{ needs.build-and-set-flags.outputs.VERSION }}"
git push
- name: Push Git Tag
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git tag -a ${{ needs.build-and-set-flags.outputs.VERSION }} -m "Release ${{ needs.build-and-set-flags.outputs.VERSION }}"
git push origin ${{ needs.build-and-set-flags.outputs.VERSION }}
delay-for-nuget-indexing:
needs: [build-and-set-flags, publish-OneOf-Reduced]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Waiting for NuGet Package Indexing
id: wait_indexing
run: |
sleep ${{ env.INDEXING_TIMEOUT }} # seconds
chmod +x ${{ github.workspace }}/scripts/check-nuget-pkg-indexed.sh
PUSHED_RESULT=$(${{ github.workspace }}/scripts/check-nuget-pkg-indexed.sh -p "BMTLab.OneOf.Reduced" -v ${{ needs.build-and-set-flags.outputs.VERSION }} -a 12)
echo "PUSHED=$PUSHED_RESULT" >> $GITHUB_OUTPUT
shell: bash
outputs:
INDEXED: ${{ steps.wait_indexing.outputs.PUSHED }}
publish-StateResults:
needs: [ build-and-set-flags, update-package-version, delay-for-nuget-indexing]
runs-on: ubuntu-latest
if: ${{ needs.delay-for-nuget-indexing.outputs.INDEXED == 'true' }}
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_SDK_VERSION }}
- name: Update Directory.Packages.props
run: |
chmod +x ${{ github.workspace }}/scripts/rewrite-pkg-version.sh
${{ github.workspace }}/scripts/rewrite-pkg-version.sh -f "${{ github.workspace }}/Directory.Packages.props" -p "BMTLab.OneOf.Reduced" -v ${{ needs.build-and-set-flags.outputs.VERSION }}
shell: bash
- name: Pack ${{ env.PACKAGE_NAME }}
run: |
dotnet pack ${{ env.STATERESULTS_PROJECT_PATH }} -c Release --include-symbols --include-source /p:PackageVersion=${{ needs.build-and-set-flags.outputs.VERSION }} -o .
- name: Upload Artifacts of ${{ env.PACKAGE_NAME }}
uses: actions/upload-artifact@v4
with:
name: StateResults-NuGetArtifacts
path: ./*.nupkg
- name: Check NuGet if ${{ env.PACKAGE_NAME }} is already pushed
id: check_pushed
run: |
chmod +x ${{ github.workspace }}/scripts/check-nuget-pkg-indexed.sh
PUSHED_RESULT=$(${{ github.workspace }}/scripts/check-nuget-pkg-indexed.sh -p "${{ env.PACKAGE_NAME }}" -v ${{ needs.build-and-set-flags.outputs.VERSION }} -a 1)
echo "PUSHED=$PUSHED_RESULT" >> $GITHUB_OUTPUT
shell: bash
continue-on-error: true
- name: Push NuGet for ${{ env.PACKAGE_NAME }}
if: ${{ steps.check_pushed.outputs.PUSHED != 'true' }}
run: dotnet nuget push ./*.nupkg --source ${{ env.NUGET_URL }} --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
env:
PACKAGE_NAME: BMTLab.StateResults
publish-StateResults-Generator:
needs: [ build-and-set-flags, update-package-version, delay-for-nuget-indexing]
runs-on: ubuntu-latest
if: ${{ needs.delay-for-nuget-indexing.outputs.INDEXED == 'true' }}
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_SDK_VERSION }}
- name: Update Directory.Packages.props
run: |
chmod +x ${{ github.workspace }}/scripts/rewrite-pkg-version.sh
${{ github.workspace }}/scripts/rewrite-pkg-version.sh -f "${{ github.workspace }}/Directory.Packages.props" -p "BMTLab.OneOf.Reduced" -v ${{ needs.build-and-set-flags.outputs.VERSION }}
shell: bash
- name: Pack ${{ env.PACKAGE_NAME }}
run: |
dotnet pack ${{ env.STATERESULTS_GENERATOR_PROJECT_PATH }} -c Release --include-symbols --include-source /p:PackageVersion=${{ needs.build-and-set-flags.outputs.VERSION }} -o .
- name: Upload Artifacts of ${{ env.PACKAGE_NAME }}
uses: actions/upload-artifact@v4
with:
name: StateResults-Generator-NuGetArtifacts
path: ./*.nupkg
- name: Check NuGet if ${{ env.PACKAGE_NAME }} is already pushed
id: check_pushed
run: |
chmod +x ${{ github.workspace }}/scripts/check-nuget-pkg-indexed.sh
PUSHED_RESULT=$(${{ github.workspace }}/scripts/check-nuget-pkg-indexed.sh -p "${{ env.PACKAGE_NAME }}" -v ${{ needs.build-and-set-flags.outputs.VERSION }} -a 1)
echo "PUSHED=$PUSHED_RESULT" >> $GITHUB_OUTPUT
shell: bash
continue-on-error: true
- name: Push NuGet for ${{ env.PACKAGE_NAME }}
if: ${{ steps.check_pushed.outputs.PUSHED != 'true' }}
run: dotnet nuget push ./*.nupkg --source ${{ env.NUGET_URL }} --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
env:
PACKAGE_NAME: BMTLab.StateResults.Generator
create-GitHub-Release:
needs: [ build-and-set-flags, publish-OneOf-Reduced, publish-StateResults, publish-StateResults-Generator ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: ${{ env.PUBLISH_DIR }}
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.build-and-set-flags.outputs.VERSION }}
release_name: Release ${{ needs.build-and-set-flags.outputs.VERSION }}
prerelease: ${{ needs.build-and-set-flags.outputs.PRERELEASE }}
draft: false
- name: Upload Artifacts to Release
run: |
for file in ./${{ env.PUBLISH_DIR }}/*; do
echo "Uploading artifact: ${file}..."
curl \
-X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: $(file -b --mime-type "${file}")" \
--data-binary @"${file}" \
"${{ steps.create_release.outputs.upload_url }}?name=$(basename "${file}")"
done
shell: bash
continue-on-error: true