-
Notifications
You must be signed in to change notification settings - Fork 163
151 lines (146 loc) · 4.91 KB
/
test.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
name: Run code tests
on:
pull_request:
branches:
- master
- develop
paths:
- src/**
- tests/**
- samples/**
- .github/workflows/**
- "*.props"
- "*.targets"
- "*.sln"
# Upload code coverage results when PRs are merged
push:
branches:
- master
- develop
paths:
- src/**
- tests/**
- samples/**
- .github/workflows/**
- "*.props"
- "*.targets"
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
2.1.x
3.1.x
5.0.x
6.0.x
7.0.x
8.0.x
source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Install dependencies
run: dotnet restore
- name: Build solution [Release]
run: dotnet build --no-restore -c Release
- name: Build solution [Debug]
run: dotnet build --no-restore -c Debug
- name: Test solution [Debug] with code coverage
if: ${{ startsWith(matrix.os, 'ubuntu') }}
run: dotnet test --no-restore --no-build -p:CollectCoverage=true
- name: Test solution [Debug] without code coverage
if: ${{ startsWith(matrix.os, 'windows') }}
run: dotnet test --no-restore --no-build
- name: Upload coverage to codecov
if: ${{ startsWith(matrix.os, 'ubuntu') }}
uses: codecov/codecov-action@v5
with:
files: .coverage/GraphQL.Server.Transports.AspNetCore.Tests/coverage.net7.0.opencover.xml,.coverage/GraphQL.Server.Transports.AspNetCore.Tests/coverage.netcoreapp2.1.opencover.xml,.coverage/GraphQL.Server.Samples.Server.Tests/coverage.net7.0.opencover.xml
nativeaot:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
name: NativeAOT Sample on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Setup .NET SDK for NativeAOT
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish NativeAOT sample
working-directory: samples/Samples.NativeAot
run: dotnet publish -c Release -o published
- name: Start NativeAOT sample in background
working-directory: samples/Samples.NativeAot/published
shell: bash
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
./GraphQL.Server.Samples.NativeAot.exe &
else
./GraphQL.Server.Samples.NativeAot &
fi
- name: Wait for NativeAOT sample to spin up
shell: bash
run: |
# Disable exit-on-error to allow retries
set +e
for i in {1..60}; do
echo "Request $i to the GraphQL endpoint..."
response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5000/ || true)
if [ "$response" -eq 200 ]; then
echo "Received 200 response, NativeAOT sample is ready."
exit 0
fi
echo "Did not receive a 200 response, sleeping for 0.5 second..."
sleep 0.5
done
echo "NativeAOT sample did not spin up in time."
exit 1
- name: Run GraphQL query against NativeAOT sample
working-directory: samples/Samples.NativeAot
shell: bash
run: |
# Run a simple GraphQL query. Adjust the request as needed for your sample.
curl -X POST -H "Content-Type: application/json" \
-d @sample-request.json \
http://localhost:5000/graphql > nativeaot_response.json
- name: Print query result
working-directory: samples/Samples.NativeAot
shell: bash
run: cat nativeaot_response.json
- name: Compare query result to expected response
working-directory: samples/Samples.NativeAot
shell: bash
run: |
jq . nativeaot_response.json > actual-response.json
jq . sample-response.json > expected-response.json
diff -b actual-response.json expected-response.json
buildcheck:
needs:
- test
- nativeaot
runs-on: ubuntu-latest
if: always()
steps:
- name: Pass build check
if: ${{ needs.test.result == 'success' && needs.nativeaot.result == 'success' }}
run: exit 0
- name: Fail build check
if: ${{ needs.test.result != 'success' || needs.nativeaot.result != 'success' }}
run: exit 1