This repository has been archived by the owner on Jun 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 197
150 lines (127 loc) · 4.76 KB
/
cicd.yaml
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
name: Continuous Integration
on:
push:
pull_request:
release:
types:
- published
env:
Configuration: Release
ContinuousIntegrationBuild: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# GitHub Packages Feed settings
GITHUB_FEED: https://nuget.pkg.github.com/serilog-contrib/
GITHUB_USER: mivano
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
package:
runs-on: ubuntu-latest
name: Run tests and create NuGet package
outputs:
coverage-reports: ${{ steps.dotnet-test.outputs.coverage-reports }}
version: ${{ steps.dotnet-pack.outputs.version }}
nupkg-filename: ${{ steps.dotnet-pack.outputs.nupkg-filename }}
release-body: ${{ steps.tag-message.outputs.release-notes }}
steps:
- name: Checkout git repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install .NET SDK
uses: actions/[email protected]
with:
dotnet-version: '7.0.x'
- name: Retrieve cached NuGet packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
- name: Restore NuGet packages
run: dotnet restore
- name: Build solution
run: dotnet build --no-restore -c Release
- name: Run tests
run: dotnet test --no-build -c Release --logger "html;LogFileName=TestResults-${{ runner.os }}.html" --logger "trx;LogFileName=TestResults-${{ runner.os }}.trx" --logger GitHubActions
id: dotnet-test
- name: Upload received files from failing tests
uses: actions/upload-artifact@v3
if: failure()
with:
name: Received-${{ runner.os }}
path: "**/*.received.*"
- name: Upload test results
uses: actions/upload-artifact@v3
if: always()
with:
name: TestResults-${{ runner.os }}
path: test/Serilog.Sinks.Elasticsearch.Tests/TestResults/TestResults-${{ runner.os }}.html
- name: Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: Test Results (${{ runner.os }})
path: '**.trx'
reporter: dotnet-trx
- name: Create NuGet packages
run: dotnet pack --no-build -c Release --version-suffix "ci-$GITHUB_RUN_ID" --include-symbols --include-source --output .
id: dotnet-pack
- name: Upload NuGet package artifact
uses: actions/upload-artifact@v3
with:
name: nuget
path: '**/*.nupkg'
prerelease:
needs: package
name: Create prerelease
if: github.ref == 'refs/heads/dev'
runs-on: ubuntu-latest
steps:
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: nuget
path: nuget
- name: Push to GitHub Feed
run: |
dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/serilog-contrib/index.json"
for f in ./nuget/*.nupkg
do
echo $f
dotnet nuget push $f --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
done
publish:
runs-on: ubuntu-latest
needs: package
if: github.event_name == 'release'
name: Publish NuGet package
steps:
- name: Checkout git repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install .NET SDK
uses: actions/[email protected]
- name: Retrieve cached NuGet packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
- name: Restore NuGet packages
run: dotnet restore
- name: Create Release NuGet package
run: |
arrTag=(${GITHUB_REF//\// })
VERSION="${arrTag[2]}"
VERSION="${VERSION//v}"
dotnet pack -v normal -c Release --include-symbols --include-source -p:Version=$VERSION -o ./nuget
- name: Push to GitHub Feed
run: |
dotnet nuget add source --username $GITHUB_USER --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/serilog-contrib/index.json"
for f in ./nuget/*.nupkg
do
dotnet nuget push $f --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
done
- name: Publish NuGet package on nuget.org
run: dotnet nuget push ./nuget/*.nupkg --api-key "${{ secrets.NUGET_API_KEY }}" --skip-duplicate