forked from G-Research/consuldotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (188 loc) · 8.3 KB
/
ci.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
name: CI
on:
push:
pull_request:
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
# Enforces the consistency of code formatting using `.editorconfig` and the `dotnet format`.
check-format:
if: github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET SDK v7.0.x
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
# For the time being (https://github.com/dotnet/format/issues/1500, https://github.com/dotnet/format/issues/1560) we need to use `dotnet-format` instead of `dotnet format`
- name: Restore tool
run: dotnet tool restore
- name: Check format
run: dotnet tool run dotnet-format -- --check
Consul_AspNetCore:
if: github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] # macos-13 for x86_x64 arch
framework: [net6.0, net7.0, net8.0]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET SDK v6.0.x
if: matrix.framework == 'net6.0'
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
- name: Setup .NET SDK v7.0.x
if: matrix.framework == 'net7.0'
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
- name: Setup .NET SDK v8.0.x
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Build
run: dotnet build Consul.AspNetCore.Test --configuration=Release --framework=${{ matrix.framework }}
- name: Run tests
shell: bash
run: dotnet test Consul.AspNetCore.Test --configuration=Release --logger "GitHubActions;report-warnings=false" --no-build -v=Normal --framework=${{ matrix.framework }}
Consul:
if: github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
strategy:
matrix:
consul: [1.6.10, 1.7.14, 1.8.19, 1.9.17, 1.10.12, 1.11.11, 1.12.9, 1.13.9, 1.14.11, 1.15.11, 1.16.7, 1.17.3, 1.18.1]
framework: [net461, net6.0, net7.0, net8.0]
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] # macos-13 for x86_x64 arch
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET SDK v6.0.x
if: matrix.framework == 'net6.0'
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
- name: Setup .NET SDK v7.0.x
if: matrix.framework == 'net7.0'
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
- name: Setup .NET SDK v8.0.x
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Setup Consul Enterprise URL
# Consul enterprise until version 1.10.0 can be run even without a valid license,
# so we take advantage of that and run enterprise tests for versions lower than 1.10.0.
# This is still necessary although a valid license has been configured in the repository settings
# because the license secret is unavailable when the pull request is created from a fork.
if: ${{ env.CONSUL_LICENSE != '' || !startsWith(matrix.consul, '1.1') }}
run: |
echo "RUN_CONSUL_ENTERPRISE_TESTS=1" >> $GITHUB_ENV
# We've decided to pause using the CONSUL_LICENSE for tests because the license would need to be renewed periodically.
# Otherwise, new builds of consul are going to fail with "license expiration date is before version build date" errors.
# Mind that, we are still running enterprise 1.10.0.
# env:
# CONSUL_LICENSE: ${{ secrets.CONSUL_LICENSE }}
- name: Download Consul
shell: bash
run: |
cd Consul.Test
SYSTEM=$(uname | sed 's/MINGW.*/windows/' | tr A-Z a-z)
if [[ $RUN_CONSUL_ENTERPRISE_TESTS == 1 ]]
then
curl -sSL https://releases.hashicorp.com/consul/${{ matrix.consul }}+ent/consul_${{ matrix.consul }}+ent_${SYSTEM}_amd64.zip -o consul.zip
else
curl -sSL https://releases.hashicorp.com/consul/${{ matrix.consul }}/consul_${{ matrix.consul }}_${SYSTEM}_amd64.zip -o consul.zip
fi
unzip consul.zip
rm consul.zip
- name: Build
run: dotnet build Consul.Test --configuration=Release --framework=${{ matrix.framework }}
- name: Run tests
shell: bash
run: |
./Consul.Test/consul agent -dev -config-file Consul.Test/test_config.json -log-file consul.log >consul-stdout.log 2>consul-stderr.log &
dotnet test Consul.Test --configuration=Release --logger "GitHubActions;report-warnings=false" --no-build -v=Normal --framework=${{ matrix.framework }}
env:
RUN_CONSUL_ENTERPRISE_TESTS: ${{env.RUN_CONSUL_ENTERPRISE_TESTS }}
CONSUL_LICENSE: ${{ secrets.CONSUL_LICENSE }}
CONSUL_AGENT_CONFIG_PATH: ${{ github.workspace }}/Consul.Test/test_config.json
- name: Upload Consul logs
if: failure()
uses: actions/upload-artifact@v4
with:
name: consul-logs-${{ matrix.consul }}-${{ matrix.framework }}-${{ matrix.os }}
path: consul*.log
package:
runs-on: windows-latest
needs: [Consul_AspNetCore, Consul]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET SDK v8.0.x
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Create NuGet packages
run: |
if (-not ("${{ github.ref }}" -like "refs/tags/v*")) {
$suffix = "preview-$(Get-Date -Format yyyyMMddHHmmss -AsUTC)-$(git rev-parse --short HEAD)"
$params = "--version-suffix", $suffix
}
dotnet pack --configuration=Release --output dist @params
if ("${{ github.ref }}" -like "refs/tags/v*") {
$tag = "${{ github.ref }}".SubString(11)
$expectedConsulFile = "dist/Consul.$tag.nupkg"
$expectedConsulAspNetCoreFile = "dist/Consul.AspNetCore.$tag.nupkg"
# Check whether the tag and the package version match together
if (-not (Test-Path -Path $expectedConsulFile)) {
echo "::error ::Expected file $expectedConsulFile doesn't exist"
exit 1
}
if (-not (Test-Path -Path $expectedConsulAspNetCoreFile)) {
echo "::error ::Expected file $expectedConsulAspNetCoreFile doesn't exist"
exit 1
}
}
- name: Upload NuGet package artifacts
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: dist/*.nupkg
# Publish NuGet packages to the preview feed when there is a push to master.
# Tests need to succeed for all components and on all platforms first.
publish-preview:
if: ${{ !github.event.repository.fork && github.ref == 'refs/heads/master' }}
needs: package
runs-on: ubuntu-latest
steps:
- name: Download NuGet package artifacts
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: dist
- name: Publish to NuGet
run: dotnet nuget push "dist/Consul.*.nupkg" --api-key ${{ secrets.FEEDZIO_API_KEY }} --source https://f.feedz.io/consuldotnet/preview/nuget/index.json
# Publish NuGet packages when a tag is pushed.
# Tests need to succeed for all components and on all platforms first,
# including having a tag name that matches the version number.
publish-release:
if: ${{ !github.event.repository.fork && startsWith(github.ref, 'refs/tags/v') }}
needs: package
runs-on: ubuntu-latest
steps:
- name: Download NuGet package artifacts
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: dist
- name: Publish to NuGet
run: dotnet nuget push "dist/Consul.*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json