Skip to content

Commit f724afc

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

File tree

3 files changed

+86
-65
lines changed

3 files changed

+86
-65
lines changed

.circleci/config.yml

Lines changed: 23 additions & 55 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
1030-
- test-mac-arm64
998+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
15+
- name: Check test expectaions on main
16+
run: |
17+
pwd
18+
git branch -a
19+
git checkout origin/main
20+
if ./tools/maint/rebaseline_tests.py --check; then
21+
echo "Test expectations are out-of-date on the main branch."
22+
echo "You can run `./tools/maint/rebaseline_tests.py --new-branch`"
23+
echo "and use it to create a seperate PR."
24+
exit 1
25+
fi
26+
- name: Install emsdk
27+
run: |
28+
curl -# -L -o ~/emsdk-main.tar.gz https://github.com/emscripten-core/emsdk/archive/main.tar.gz
29+
tar -C ~ -xf ~/emsdk-main.tar.gz
30+
mv ~/emsdk-main ~/emsdk
31+
cd ~/emsdk
32+
./emsdk install tot
33+
./emsdk activate tot
34+
# Remove the emsdk version of emscripten to save space in the
35+
# persistent workspace and to avoid any confusion with the version
36+
# we are trying to test.
37+
echo "JS_ENGINES = [NODE_JS]" >> .emscripten
38+
echo "final .emscripten:"
39+
cat ~/emsdk/.emscripten

tools/maint/rebaseline_tests.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ 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('--check', action='store_true', help='Return non-zero if test expectations are out of date')
6970
args = parser.parse_args()
7071

7172
if args.clear_cache:
@@ -79,16 +80,25 @@ def main(argv):
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 check:
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,16 +110,20 @@ def main(argv):
100110
'''
101111

102112
for file in filenames:
103-
commit_message += process_changed_file(file)
113+
message += process_changed_file(file)
114+
115+
message += f'\nAverage change: {statistics.mean(all_deltas):+.2f}% ({min(all_deltas):+.2f}% - {max(all_deltas):+.2f}%)\n'
104116

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

107-
commit_message += '```\n'
119+
if check:
120+
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

114128
print(commit_message)
115129
return 0

0 commit comments

Comments
 (0)