-
Notifications
You must be signed in to change notification settings - Fork 3
150 lines (124 loc) · 4.7 KB
/
build_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
name: Build and SonarQube Analysis
on:
pull_request:
branches:
# - dev # when working with a development seat of sonarServer
- main
push:
branches:
# - dev # when working with a development seat of sonarServer
- main
jobs:
build-and-test:
runs-on: macos-latest
env:
PORT: 4201
APP_PORT: 4200
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set Up Node.js
uses: actions/setup-node@v3
with:
node-version: 22.14.0
- name: Install Dependencies
run: |
echo "\nInstalling dependencies\n\n"
npm ci
- name: Run Translation Validation
run: |
echo "\nRunning translation validation\n\n"
cd tests/translation && npx ts-node translation-validation.ts
- name: Build the Client
run: |
echo "\nBuilding the client\n\n"
cd client && npm run build
- name: Run Server Tests
run: |
echo "\nRunning server tests\n\n"
cd server && npm test
- name: Run Client Tests
run: |
echo "\nRunning client tests\n\n"
cd client && npm test
# #e2e Tests
# TODO uncomment once testcafe works with chrome latest
# - name: Start Angular server
# run: npm run prod &
# - name: Wait for Angular server to start
# run: |
# until curl --output /dev/null --silent --head --fail http://localhost:4200; do
# echo 'Waiting for Angular server...'
# sleep 5
# done
# - name: Run E2E Tests
# run: |
# echo "\nRunning e2e tests\n\n"
# cd tests/e2e && node clean_screenshots && node test_runner
# - name: Run Screenshot Diff Tests
# run: |
# echo "\nRunning screenshot diff tests\n\n"
# cd tests/e2e && npx testcafe-blink-diff screenshots --compare accepted:tested --open --threshold 0.003
- name: Install SonarScanner
run: |
curl -sSLo sonar-scanner-cli.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.2.1.4610-macosx-aarch64.zip
unzip -q sonar-scanner-cli.zip -d $HOME/sonar-scanner
echo "$HOME/sonar-scanner/sonar-scanner-6.2.1.4610-macosx-aarch64/bin" >> $GITHUB_PATH
- name: Run SonarScanner
run: |
sonar-scanner \
-Dsonar.projectKey=TheGameKnave_angular-momentum \
-Dsonar.organization=thegameknave \
-Dsonar.host.url=https://sonarcloud.io
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Wait for Quality Gate
run: |
#!/bin/bash
TASK_FILE=.scannerwork/report-task.txt
echo "Fetching task status... for TASK_ID=$(cat $TASK_FILE)"
TASK_ID=$(grep "ceTaskId" "$TASK_FILE" | cut -d= -f2 | tr -d '[:space:]')
if [[ -z "$TASK_ID" ]]; then
echo "Error: TASK_ID is empty. Check Sonar task file."
exit 1
fi
# Wait for SonarCloud to complete the analysis
MAX_RETRIES=15
RETRY_DELAY=10
TRIES=0
while ((TRIES < MAX_RETRIES)); do
# Fetch task status from SonarCloud
RESPONSE=$(curl -s -u "${{ secrets.SONAR_TOKEN }}:" "https://sonarcloud.io/api/ce/task?id=$TASK_ID")
echo "Response: $RESPONSE" # This logs the response from SonarCloud
# Check if the response contains data
if [[ -z "$RESPONSE" ]]; then
echo "Warning: Empty response from SonarCloud. Retrying..."
sleep $RETRY_DELAY
((TRIES++))
continue
fi
# Attempt to extract the status from the response
STATUS=$(echo "$RESPONSE" | grep -o '"status":"[^"]*"' | cut -d: -f2 | tr -d '"')
if [[ -z "$STATUS" ]]; then
echo "Warning: STATUS is empty. Retrying..."
sleep $RETRY_DELAY
((TRIES++))
continue
fi
echo "Current Task Status: $STATUS"
if [[ "$STATUS" == "SUCCESS" ]]; then
break
elif [[ "$STATUS" == "FAILED" ]]; then
echo "SonarCloud analysis failed!"
echo "$RESPONSE" # Show full response on failure
exit 1
fi
((TRIES++))
if [[ "$TRIES" -ge "$MAX_RETRIES" ]]; then
echo "SonarCloud analysis taking too long. Exiting."
exit 1
fi
echo "Waiting for SonarCloud to complete analysis... (Attempt $TRIES/$MAX_RETRIES)"
sleep $RETRY_DELAY
done
shell: bash