forked from G-Research/consuldotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (78 loc) · 2.92 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
name: CI
on:
push:
pull_request:
env:
CONSUL_VERSION: 1.6.1
jobs:
# Build and test on all major platforms.
# Repack to avoid Newtonsoft.Json dependency in .NET Framework (This is to
# prevent issues with mismatched JSON.NET versions in user projects).
# Create a NuGet package on Windows only, as we build for .NET Framework 4.6.1
# and for .NET Standard 2.0.
build:
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]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup .NET Core SDK
if: runner.os != 'Windows'
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.300
- name: Download Consul
shell: bash
run: |
cd Consul.Test
SYSTEM=$(uname | sed 's/MINGW.*/windows/' | tr A-Z a-z)
curl -sSL https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_${SYSTEM}_amd64.zip -o consul.zip
unzip consul.zip
rm consul.zip
- name: Build
run: dotnet build --configuration=Release -p:TreatWarningsAsErrors=true
- name: Run tests
shell: bash
run: |
cd Consul.Test
./consul agent -dev -config-file test_config.json &
dotnet test --configuration=Release --no-build -v=Normal
- name: Create NuGet package
if: runner.os == 'Windows'
run: |
if ("${{ github.ref }}" -like "refs/tags/v*") {
$tag = "${{ github.ref }}".SubString(11)
$version = (Select-Xml -path Consul/Consul.csproj -XPath "/Project/PropertyGroup/VersionPrefix/text()").node.Value
if (-not ($tag -eq $version)) {
echo "There is a mismatch between the project version ($version) and the tag ($tag)"
exit 1
}
} else {
$params = "--version-suffix", $(git rev-parse --short HEAD)
}
dotnet pack --configuration=Release --no-build @params
- name: Upload NuGet package artifact
if: runner.os == 'Windows'
uses: actions/upload-artifact@v2
with:
name: nuget-package
path: dist
# Publish NuGet package when a tag is pushed.
# Tests need to succeed on all platforms first, including having a tag name that matches the version number.
publish:
if: startsWith(github.ref, 'refs/tags/v')
needs: build
runs-on: windows-latest
steps:
- name: Download NuGet package artifact
uses: actions/download-artifact@v2
with:
name: nuget-package
path: dist
- name: Publish to NuGet
shell: bash
run: dotnet nuget push dist/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json