-
Notifications
You must be signed in to change notification settings - Fork 11
311 lines (269 loc) · 10.7 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# .github/workflows/ci.yml
name: CI Job to Generate JUnit Reports with Diff and Allure Reports
on:
schedule:
- cron: 17 0 * * * # nightly run; 17th minute to decrease odds of delayed or dropped job
push:
branches:
- main
pull_request_target:
branches:
- main
permissions:
contents: write
pages: write
actions: write
checks: write
pull-requests: write
jobs:
generate-reports:
runs-on: ubuntu-latest
if: (github.repository == 'trueagi-io/metta-wam') || (github.event_name != 'schedule')
env:
JOB_TYPE: ${{ github.event_name == 'schedule' && 'nightly' || 'ci' }}
REPO_URL: https://github.com/${{ github.repository }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Ensure just-results branch exists
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
git ls-remote --heads ${{ env.REPO_URL }} just-results
if [ $? -ne 0 ]; then
echo "just-results branch does not exist. Creating it."
git init previous-results
cd previous-results
git checkout -b just-results
touch current_test_results.txt
git add current_test_results.txt
git commit -m "Initialize just-results branch"
git remote add origin ${{ env.REPO_URL }}
# Configure Git user information
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
# Set the remote URL with authentication
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
git push origin just-results
else
echo "just-results branch exists. Cloning it."
git clone --single-branch --branch just-results --depth 1 https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git previous-results
fi
- name: Copy Previous Test Results
run: |
if [ -f "previous-results/current_test_results.txt" ]; then
cp previous-results/current_test_results.txt previous_test_results.txt
else
echo "No previous test results found."
fi
- name: Make Install Script Executable
run: chmod +x INSTALL.sh
- name: Run Install Script to install Mettalog
run: |
. ./INSTALL.sh --easy
sudo chmod -R 777 .
echo $PATH >> $GITHUB_PATH
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install python packages
run: |
pip install ansi2html
pip install hyperon
pip install junit2html
- name: Make Scripts Executable
run: chmod +x scripts/*.sh
- name: Run Test Script to Generate Input File
continue-on-error: true
run: |
TIMESTAMP=$(date +"%Y-%m-%dT%H:%M:%S")
BASELINE_COMPAT_PATH=reports/tests_output/now
echo "TIMESTAMP=$TIMESTAMP" >> $GITHUB_ENV
echo "BASELINE_COMPAT_PATH=$BASELINE_COMPAT_PATH" >> $GITHUB_ENV
mkdir -p $BASELINE_COMPAT_PATH
if [ "${{ env.JOB_TYPE }}" == "nightly" ]; then
./scripts/run_nightly_tests.sh -t $TIMESTAMP
else
./scripts/run_commit_tests.sh -t $TIMESTAMP
fi
env:
TERM: xterm-256color
- name: Parse Test Results
run: |
# Extract test IDs and their statuses into a sorted file
awk -F '|' '{print $2 "|" $3}' /tmp/SHARED.UNITS | grep -E 'PASS|FAIL' | sort > current_test_results.txt
- name: Compare Test Results
run: |
if [ -f "previous_test_results.txt" ]; then
if diff previous_test_results.txt current_test_results.txt > /dev/null; then
echo "No changes in test results."
echo "TEST_CHANGED=false" >> $GITHUB_ENV
else
echo "Changes detected in test results."
echo "TEST_CHANGED=true" >> $GITHUB_ENV
fi
else
echo "No previous test results to compare."
echo "TEST_CHANGED=true" >> $GITHUB_ENV
fi
- name: Save Current Test Results to just-results branch
if: env.TEST_CHANGED == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
cp current_test_results.txt previous-results/
cd previous-results
# Configure Git user information
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
# Set the remote URL with authentication
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
git pull
# Stage and commit changes
git add current_test_results.txt
git commit -m "Update test results"
# Push changes to the just-results branch
git push origin just-results
# Continue only if tests changed
- name: Run JUnit Report Generation Script
if: env.TEST_CHANGED == 'true'
continue-on-error: true
run: |
python3 scripts/into_junit.py /tmp/SHARED.UNITS ${{ env.TIMESTAMP }} 1 > junit.xml
- name: Convert JUnit XML to Standard HTML Report
if: env.TEST_CHANGED == 'true'
continue-on-error: true
run: |
cat junit.xml
junit2html junit.xml ${{ env.BASELINE_COMPAT_PATH }}/junit-standard-report.html
- name: Convert JUnit XML to Matrix HTML Report
if: env.TEST_CHANGED == 'true'
continue-on-error: true
run: |
junit2html --report-matrix ${{ env.BASELINE_COMPAT_PATH }}/junit-matrix-report.html junit.xml
- name: Upload JUnit XML Report
if: env.TEST_CHANGED == 'true'
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: junit-report
path: junit.xml
- name: Upload Standard HTML Report
if: env.TEST_CHANGED == 'true'
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: junit-standard-html-report
path: ${{ env.BASELINE_COMPAT_PATH }}/junit-standard-report.html
- name: Upload Matrix HTML Report
if: env.TEST_CHANGED == 'true'
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: junit-matrix-html-report
path: ${{ env.BASELINE_COMPAT_PATH }}/junit-matrix-report.html
- name: Upload Test Output Log Files
if: env.TEST_CHANGED == 'true'
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: test-output-logs
path: ${{ env.BASELINE_COMPAT_PATH }}
- name: Display JUnit Test Results
if: (github.event_name == 'push') && (env.TEST_CHANGED == 'true')
uses: dorny/test-reporter@v1
with:
name: 'JUnit Results'
path: 'junit.xml'
reporter: 'java-junit'
fail-on-error: false
- name: Provide Report Links
if: env.TEST_CHANGED == 'true'
run: |
echo "JUnit reports are available as artifacts."
- name: Generate environment.properties
if: env.TEST_CHANGED == 'true'
run: |
python scripts/generate_allure_environment.py ${{ github.sha }} ${{ github.ref_name }} > environment.properties
- name: Upload environment.properties
if: env.TEST_CHANGED == 'true'
uses: actions/upload-artifact@v4
with:
name: environment
path: environment.properties
- name: Get Allure history
if: env.TEST_CHANGED == 'true'
uses: actions/checkout@v4
with:
ref: test-results
path: test-results
- name: Download JUnit XML Results
if: env.TEST_CHANGED == 'true'
uses: actions/download-artifact@v4
with:
name: junit-report
path: build/allure-results
- name: Include environment properties
if: env.TEST_CHANGED == 'true'
uses: actions/download-artifact@v4
with:
name: environment
path: build/allure-results
- name: Generate Allure Report
if: env.TEST_CHANGED == 'true'
uses: simple-elf/allure-report-action@master
id: allure-report
with:
allure_results: build/allure-results
gh_pages: test-results
allure_report: allure-report
allure_history: allure-history
subfolder: ${{ env.SUBFOLDER }}
keep_reports: 120
env:
SUBFOLDER: ${{ env.JOB_TYPE }}
- name: Copy JUnit HTML Reports to GitHub Pages Directory
if: env.TEST_CHANGED == 'true'
run: |
sudo chmod 777 . -R
ls -lA allure-history
mkdir -p allure-history/${{ env.BASELINE_COMPAT_PATH }}
cp -f ${{ env.BASELINE_COMPAT_PATH }}/* reports/tests_output/baseline-compat/
cp -rf reports/* allure-history/reports/
- name: Copy Help Docs to GitHub Pages Directory
if: env.TEST_CHANGED == 'true'
run: |
mkdir -p allure-history/help-docs/
cp -r ./docs/* allure-history/help-docs/
- name: Generate Root Index for GitHub Pages
if: env.TEST_CHANGED == 'true'
run: |
echo "<html>" > allure-history/index.html
echo "<head><title>Project Reports and Documentation</title></head>" >> allure-history/index.html
echo "<body>" >> allure-history/index.html
echo "<h1>Project Reports and Documentation</h1>" >> allure-history/index.html
echo "<ul>" >> allure-history/index.html
echo "<li><a href='./ci/'>Allure CI Reports</a></li>" >> allure-history/index.html
echo "<li><a href='./nightly/'>Allure Nightly Reports</a></li>" >> allure-history/index.html
echo "<li><a href='./${{ env.BASELINE_COMPAT_PATH }}/junit-standard-report.html'>JUnit Standard Report</a></li>" >> allure-history/index.html
echo "<li><a href='./${{ env.BASELINE_COMPAT_PATH }}/junit-matrix-report.html'>JUnit Matrix Report</a></li>" >> allure-history/index.html
#echo "<li><a href='./help-docs/'>Help Documentation</a></li>" >> allure-history/index.html
echo "</ul>" >> allure-history/index.html
echo "</body>" >> allure-history/index.html
echo "</html>" >> allure-history/index.html
- name: Deploy Allure reports, JUnit HTML reports, and help docs to GitHub Pages
if: env.TEST_CHANGED == 'true'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
personal_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: test-results
publish_dir: allure-history
- name: Auto-Approve the Pull Request
if: github.event_name == 'pull_request_target'
uses: hmarr/auto-approve-action@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}