Skip to content

Commit f1639a3

Browse files
authored
CI: Check that test expectations are up-to-date (#23201)
This test will fail if the expectations are out-of-date on the main branch. This can happen due to either: 1. Somebody forgetting to update the expectations when they land an emscripten change 2. llvm or binaryen changes that rolled in on the auto-roller. For now I propose that we don't make this new check "Required" and we consider this the first step towards making these updates easy and automatic. I made this a github action rather than using CiricleCI since I anticipate using github automation here in the future (for example to suggest updates the current PR).
1 parent 84de057 commit f1639a3

File tree

3 files changed

+96
-43
lines changed

3 files changed

+96
-43
lines changed

.github/workflows/archive.yml

-27
This file was deleted.

.github/workflows/ci.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI
2+
3+
on:
4+
create:
5+
tags:
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
archive:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
19+
- name: make dist
20+
run: |
21+
make dist
22+
version=`cat emscripten-version.txt | sed s/\"//g`
23+
echo "VERSION=$version" >> $GITHUB_ENV
24+
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
25+
with:
26+
name: emscripten-${{ env.VERSION }}
27+
path: emscripten-${{ env.VERSION }}.tar.bz2
28+
29+
check-expectations:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout repo
33+
uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0 # We want access to other branches, specifically `main`
36+
- name: pip install
37+
run: |
38+
which python3
39+
python3 --version
40+
python3 -m pip install -r requirements-dev.txt
41+
- name: Install emsdk
42+
run: |
43+
EM_CONFIG=$HOME/emsdk/.emscripten
44+
echo $EM_CONFIG
45+
echo "EM_CONFIG=$EM_CONFIG" >> $GITHUB_ENV
46+
curl -# -L -o ~/emsdk-main.tar.gz https://github.com/emscripten-core/emsdk/archive/main.tar.gz
47+
tar -C ~ -xf ~/emsdk-main.tar.gz
48+
mv ~/emsdk-main ~/emsdk
49+
cd ~/emsdk
50+
./emsdk install tot
51+
./emsdk activate tot
52+
echo "JS_ENGINES = [NODE_JS]" >> $EM_CONFIG
53+
echo "final config:"
54+
cat $EM_CONFIG
55+
- name: Check test expectations on main
56+
run: |
57+
git checkout origin/main
58+
# Hack to honor changes to rebaseline_tests.py in the current PR
59+
git checkout - ./tools/maint/rebaseline_tests.py
60+
./bootstrap
61+
if ! ./tools/maint/rebaseline_tests.py --check-only; then
62+
echo "Test expectations are out-of-date on the main branch."
63+
echo "You can run `./tools/maint/rebaseline_tests.py --new-branch`"
64+
echo "and use it to create a seperate PR."
65+
exit 1
66+
fi

tools/maint/rebaseline_tests.py

+30-16
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

81-
if not run(['git', 'status', '-uno', '--porcelain']):
82-
print('no updates found')
83-
return 1
83+
if not run(['git', 'status', '-uno', '--porcelain', 'test']):
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)