Skip to content

Commit 5cfa098

Browse files
committed
CI: Check that test expectations are up-to-date
1 parent 84de057 commit 5cfa098

File tree

3 files changed

+75
-69
lines changed

3 files changed

+75
-69
lines changed

.circleci/config.yml

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -973,58 +973,4 @@ workflows:
973973
build-test:
974974
jobs:
975975
- 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
1030976
- test-mac-arm64
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
check-expectations:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repo
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # We want access to other branches, specifically `main`
17+
- name: pip install
18+
run: |
19+
which python3
20+
python3 --version
21+
python3 -m pip install -r requirements-dev.txt
22+
- name: Install emsdk
23+
run: |
24+
EM_CONFIG=$HOME/emsdk/.emscripten
25+
echo $EM_CONFIG
26+
echo "EM_CONFIG=$EM_CONFIG" >> $GITHUB_ENV
27+
curl -# -L -o ~/emsdk-main.tar.gz https://github.com/emscripten-core/emsdk/archive/main.tar.gz
28+
tar -C ~ -xf ~/emsdk-main.tar.gz
29+
mv ~/emsdk-main ~/emsdk
30+
cd ~/emsdk
31+
./emsdk install tot
32+
./emsdk activate tot
33+
echo "JS_ENGINES = [NODE_JS]" >> $EM_CONFIG
34+
echo "final config:"
35+
cat $EM_CONFIG
36+
- name: Check test expectaions on main
37+
run: |
38+
git checkout origin/main
39+
git checkout - ./tools/maint/rebaseline_tests.py
40+
./bootstrap
41+
if ! ./tools/maint/rebaseline_tests.py --check-only; then
42+
echo "Test expectations are out-of-date on the main branch."
43+
echo "You can run `./tools/maint/rebaseline_tests.py --new-branch`"
44+
echo "and use it to create a seperate PR."
45+
exit 1
46+
fi

tools/maint/rebaseline_tests.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
'browser.test_small_js_flags',
2727
'other.test_INCOMING_MODULE_JS_API',
2828
'other.*code_size*',
29-
'other.*codesize*'
29+
'other.*codesize*',
30+
'skip:other.test_jspi_code_size',
3031
]
3132

3233

@@ -63,33 +64,43 @@ def process_changed_file(filename):
6364

6465
def main(argv):
6566
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)')
67+
parser.add_argument('-s', '--skip-tests', action='store_true', help="Don't actually run the tests, just analyze the existing results")
68+
parser.add_argument('-b', '--new-branch', action='store_true', help='Create a new branch containing the updates')
69+
parser.add_argument('-c', '--clear-cache', action='store_true', help='Clear the cache before rebaselining (useful when working with llvm changes)')
70+
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')
6971
args = parser.parse_args()
7072

7173
if args.clear_cache:
7274
run(['emcc', '--clear-cache'])
7375

7476
if not args.skip_tests:
75-
if run(['git', 'status', '-uno', '--porcelain']).strip():
77+
if not args.check_only and run(['git', 'status', '-uno', '--porcelain']).strip():
7678
print('tree is not clean')
7779
return 1
7880

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

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

8587
output = run(['git', 'status', '-uno', '--porcelain'])
8688
filenames = []
8789
for line in output.splitlines():
88-
status, filename = line.strip().rsplit(' ', 1)
89-
if filename.startswith('test/'):
90+
filename = line.strip().rsplit(' ', 1)[1]
91+
if filename.startswith('test'):
9092
filenames.append(filename)
9193

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

103114
for file in filenames:
104-
commit_message += process_changed_file(file)
115+
message += process_changed_file(file)
105116

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

108-
commit_message += '```\n'
119+
message += '```\n'
120+
121+
print(message)
122+
if args.check_only:
123+
return 1
109124

110125
if args.new_branch:
111126
run(['git', 'checkout', '-b', 'rebaseline_tests'])
112127
run(['git', 'add', '-u', '.'])
113-
run(['git', 'commit', '-F', '-'], input=commit_message)
128+
run(['git', 'commit', '-F', '-'], input=message)
114129

115-
print(commit_message)
116130
return 0
117131

118132

0 commit comments

Comments
 (0)