-
Notifications
You must be signed in to change notification settings - Fork 87
156 lines (138 loc) · 4.92 KB
/
build.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
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Build
on:
push:
branches: [ "main" ]
paths:
- 'sdk/**'
- 'tools/**'
- 'samples/**'
- 'experimental/**'
pull_request:
branches: [ "main" ]
paths:
- 'sdk/**'
- 'tools/**'
- 'samples/**'
- 'experimental/**'
jobs:
javascript:
name: Build and Test JS code and samples
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
dotnet-version: [6.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Test VSCode Extension
# See https://code.visualstudio.com/api/working-with-extensions/continuous-integration#github-actions
run: cd ./tools/vscode-azurewebpubsub && npm install && xvfb-run -a npm run test && cd ../../
if: runner.os == 'Linux'
- name: Install and Test All Samples
run: |
find ./samples/javascript ./experimental -name 'node_modules' -prune -o -name 'package.json' -print0 | while IFS= read -r -d '' file; do
dir=$(dirname "$file")
echo "Processing directory: $dir"
cd "$dir"
echo "Installing dependencies in $dir"
npm install
echo "Running tests in $dir"
npm run test
echo "Finished tests in $dir"
cd - > /dev/null
done
- run: npm install -g yarn
- run: yarn install
- run: yarn workspaces run test
- name: Setup .NET ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Build C# samples
run: dotnet build samples/csharp/samples.sln
csharp:
name: Build and Test C#
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [6.x]
steps:
- uses: actions/checkout@v4
- name: Setup .NET ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Build C# samples
run: dotnet build samples/csharp/samples.sln
# Java Stage
java:
name: Build and Test Java
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: maven
- name: Build and Test Java Projects
run: |
find ./samples/java -name 'pom.xml' -print0 | while IFS= read -r -d '' file; do
dir=$(dirname "$file")
echo "Building and testing Java project in $dir"
cd "$dir"
mvn clean install
mvn test
cd - > /dev/null
done
# Python Stage
python:
name: Build and Test Python
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies and Test Python Projects
run: |
find ./samples/python -name 'requirements.txt' -print0 | while IFS= read -r -d '' file; do
dir=$(dirname "$file")
echo "Installing dependencies for Python project in $dir"
cd "$dir"
pip install -r requirements.txt
echo "Running tests for Python project in $dir"
pytest --maxfail=0 --disable-warnings --junitxml=results.xml --ignore=node_modules --ignore=venv || true
TEST_COUNT=$(grep -o 'tests="[^"]*"' results.xml | sed 's/tests="//g' | sed 's/"//g')
FAILED_COUNT=$(grep -o 'failures="[^"]*"' results.xml | sed 's/failures="//g' | sed 's/"//g')
echo "Tests found: $TEST_COUNT"
echo "Tests failed: $FAILED_COUNT"
if [[ "$TEST_COUNT" -gt 0 && "$FAILED_COUNT" -gt 0 ]]; then
echo "Tests ran and some tests failed in $dir. Failing the job."
exit 1
elif [[ "$TEST_COUNT" -eq 0 ]]; then
echo "No tests found for $dir. Exiting successfully."
else
echo "All tests passed in $dir. Exiting successfully."
fi
cd - > /dev/null
done