Skip to content

Commit 7252f97

Browse files
committed
CI: Check that test expectations are up-to-date
1 parent c17479b commit 7252f97

File tree

4 files changed

+96
-69
lines changed

4 files changed

+96
-69
lines changed

.circleci/config.yml

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,28 @@ jobs:
732732
core0.test_hello_argc
733733
core2.test_demangle_stacks_symbol_map"
734734
- upload-test-results
735+
test-expectations:
736+
executor: bionic
737+
environment:
738+
LANG: "C.UTF-8"
739+
EMTEST_SKIP_V8: "1"
740+
steps:
741+
- checkout
742+
- run:
743+
name: submodule update
744+
command: git submodule update --init
745+
- pip-install
746+
- install-emsdk
747+
- run: git checkout origin/main
748+
- run:
749+
name: check test expectations are up-to-date
750+
command: |
751+
if ./tools/maint/rebaseline_tests.py --check; then
752+
echo "Test expectations are out-of-date on the main branch."
753+
echo "You can run `./tools/maint/rebaseline_tests.py --new-branch`
754+
echo "and use it to create a seperate PR."
755+
exit 1
756+
fi
735757
test-node-compat:
736758
# We don't use `bionic` here since its too old to run recent node versions:
737759
# `/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found`
@@ -973,58 +995,4 @@ workflows:
973995
build-test:
974996
jobs:
975997
- ruff
976-
- mypy
977-
- eslint
978-
- build-docs
979-
- build-linux
980-
- test-sanity:
981-
requires:
982-
- build-linux
983-
- test-posixtest:
984-
requires:
985-
- build-linux
986-
- test-core0:
987-
requires:
988-
- build-linux
989-
- test-core2:
990-
requires:
991-
- build-linux
992-
- test-core3:
993-
requires:
994-
- build-linux
995-
- test-wasm64:
996-
requires:
997-
- build-linux
998-
- test-wasm64-4gb:
999-
requires:
1000-
- build-linux
1001-
- test-wasm2js1:
1002-
requires:
1003-
- build-linux
1004-
- test-other:
1005-
requires:
1006-
- build-linux
1007-
- test-browser-chrome:
1008-
requires:
1009-
- build-linux
1010-
- test-browser-chrome-2gb:
1011-
requires:
1012-
- build-linux
1013-
- test-browser-chrome-wasm64:
1014-
requires:
1015-
- build-linux
1016-
- test-browser-chrome-wasm64-4gb:
1017-
requires:
1018-
- build-linux
1019-
- test-browser-firefox:
1020-
requires:
1021-
- build-linux
1022-
- test-browser-firefox-wasm64
1023-
- test-sockets-chrome:
1024-
requires:
1025-
- build-linux
1026-
- test-jsc
1027-
- test-spidermonkey
1028-
- test-node-compat
1029-
- test-windows
1030998
- test-mac-arm64
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: read
8+
9+
env:
10+
EMTEST_SKIP_V8: 1
11+
12+
jobs:
13+
check-expectations:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repo
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0 # We want access to other branches, specifically `main`
20+
- name: pip install
21+
run: |
22+
which python3
23+
python3 --version
24+
python3 -m pip install -r requirements-dev.txt
25+
- name: Install emsdk
26+
run: |
27+
EM_CONFIG=$HOME/emsdk/.emscripten
28+
echo $EM_CONFIG
29+
echo "EM_CONFIG=$EM_CONFIG" >> $GITHUB_ENV
30+
curl -# -L -o ~/emsdk-main.tar.gz https://github.com/emscripten-core/emsdk/archive/main.tar.gz
31+
tar -C ~ -xf ~/emsdk-main.tar.gz
32+
mv ~/emsdk-main ~/emsdk
33+
cd ~/emsdk
34+
./emsdk install tot
35+
./emsdk activate tot
36+
echo "JS_ENGINES = [NODE_JS]" >> $EM_CONFIG
37+
echo "final config:"
38+
cat $EM_CONFIG
39+
- name: Check test expectaions on main
40+
run: |
41+
git checkout origin/main
42+
git checkout - ./tools/maint/rebaseline_tests.py
43+
./bootstrap
44+
if ! ./tools/maint/rebaseline_tests.py --check-only; then
45+
echo "Test expectations are out-of-date on the main branch."
46+
echo "You can run `./tools/maint/rebaseline_tests.py --new-branch`"
47+
echo "and use it to create a seperate PR."
48+
exit 1
49+
fi

requirements-dev.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ ruff==0.8.2
1010
types-requests==2.27.14
1111
unittest-xml-reporting==3.1.0
1212

13-
# See https://github.com/emscripten-core/emscripten/issues/19785
14-
lxml==4.9.2
15-
1613
# This version is mentioned in `site/source/docs/site/about.rst`.
1714
# Please keep them in sync.
1815
sphinx==7.1.2

tools/maint/rebaseline_tests.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,42 @@ def process_changed_file(filename):
6363

6464
def main(argv):
6565
parser = argparse.ArgumentParser()
66-
parser.add_argument('-s', '--skip-tests', action='store_true', help="don't actually run the tests, just analyze the existing results")
67-
parser.add_argument('-b', '--new-branch', action='store_true', help='create a new branch containing the updates')
68-
parser.add_argument('-c', '--clear-cache', action='store_true', help='clear the cache before rebaselining (useful when working with llvm changes)')
66+
parser.add_argument('-s', '--skip-tests', action='store_true', help="Don't actually run the tests, just analyze the existing results")
67+
parser.add_argument('-b', '--new-branch', action='store_true', help='Create a new branch containing the updates')
68+
parser.add_argument('-c', '--clear-cache', action='store_true', help='Clear the cache before rebaselining (useful when working with llvm changes)')
69+
parser.add_argument('-n', '--check-only', dest='check_only', action='store_true', help='Return non-zero if test expectations are out of date, and skip creating a git commit')
6970
args = parser.parse_args()
7071

7172
if args.clear_cache:
7273
run(['emcc', '--clear-cache'])
7374

7475
if not args.skip_tests:
75-
if run(['git', 'status', '-uno', '--porcelain']).strip():
76+
if not args.check_only and run(['git', 'status', '-uno', '--porcelain']).strip():
7677
print('tree is not clean')
7778
return 1
7879

7980
subprocess.check_call(['test/runner', '--rebaseline', '--browser=0'] + TESTS, cwd=root_dir)
8081

8182
if not run(['git', 'status', '-uno', '--porcelain']):
82-
print('no updates found')
83-
return 1
83+
print('test expectations are up-to-date')
84+
return 0
8485

8586
output = run(['git', 'status', '-uno', '--porcelain'])
8687
filenames = []
8788
for line in output.splitlines():
8889
status, filename = line.strip().split(' ', 1)
8990
filenames.append(filename)
9091

91-
commit_message = f'''
92+
if args.check_only:
93+
message = f'''Test expectations are out-of-date
94+
95+
The following ({len(filenames)}) test expectation files were updated by
96+
running the tests with `--rebaseline`:
97+
98+
```
99+
'''
100+
else:
101+
message = f'''
92102
Automatic rebaseline of codesize expectations. NFC
93103
94104
This is an automatic change generated by tools/maint/rebaseline_tests.py.
@@ -100,18 +110,21 @@ def main(argv):
100110
'''
101111

102112
for file in filenames:
103-
commit_message += process_changed_file(file)
113+
message += process_changed_file(file)
104114

105-
commit_message += f'\nAverage change: {statistics.mean(all_deltas):+.2f}% ({min(all_deltas):+.2f}% - {max(all_deltas):+.2f}%)\n'
115+
message += f'\nAverage change: {statistics.mean(all_deltas):+.2f}% ({min(all_deltas):+.2f}% - {max(all_deltas):+.2f}%)\n'
106116

107-
commit_message += '```\n'
117+
message += '```\n'
118+
119+
print(message)
120+
if args.check_only:
121+
return 1
108122

109123
if args.new_branch:
110124
run(['git', 'checkout', '-b', 'rebaseline_tests'])
111125
run(['git', 'add', '-u', '.'])
112-
run(['git', 'commit', '-F', '-'], input=commit_message)
126+
run(['git', 'commit', '-F', '-'], input=message)
113127

114-
print(commit_message)
115128
return 0
116129

117130

0 commit comments

Comments
 (0)