Skip to content

Commit 6118037

Browse files
committed
ci: fix change selection
1 parent 6cbdc9f commit 6118037

3 files changed

Lines changed: 145 additions & 50 deletions

File tree

‎.github/scripts/changes.py‎

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414
'rsync.1', 'rsync.1.html', 'rsync-ssl.1', 'rsync-ssl.1.html',
1515
'rsyncd.conf.5', 'rsyncd.conf.5.html', 'rrsync.1', 'rrsync.1.html',
1616
}
17+
NO_TEST_FILES = {
18+
'COPYING', 'INSTALL.md', 'NEWS.md', 'README.md', 'SECURITY.md', 'TODO',
19+
'csprotocol.txt', 'tech_report.tex', '.github/INTEROPERABILITY.md',
20+
'old_versions/README.md', 'testsuite/README.md', '.github/FUNDING.yml', 'rsync-web/.gitignore',
21+
'rsync-web/rsync-and-debian/.cvsignore',
22+
}
23+
WEBSITE_SUFFIXES = {'.html', '.css', '.txt', '.jpg', '.gif', '.xcf', '.sgml', '.tex', '.aux', '.log'}
24+
FULL_CHECK_FILES = {
25+
'.gitattributes', '.gitignore', 'Doxyfile', 'cmd-or-msg', 'config.guess',
26+
'config.sub', 'configure', 'daemon-parm.txt', 'install-sh', 'maybe-make-man',
27+
'md-convert', 'md2man', 'mkgitver', 'prepare-source', 'rsync-ssl', 'wildtest.txt',
28+
'rsync-web/bin/badge-update', 'rsync-web/bin/upload', 'rsync-web/convert-gpl',
29+
'rsync-web/filt', 'rsync-web/rsync-debug', 'rsync-web/rsync_wrapper.pl',
30+
'rsync-web/tech_report/images.pl', 'rsync-web/tech_report/labels.pl',
31+
}
32+
FULL_CHECK_DIRS = ('lib/', 'm4/', 'packaging/', 'popt/', 'support/', 'zlib/')
33+
SOURCE_SUFFIXES = {'.c', '.h', '.cpp', '.S', '.awk', '.in', '.ac', '.mak'}
1734

1835

1936
def empty():
@@ -29,11 +46,9 @@ def full():
2946
return {name: True for name in OUTPUTS}
3047

3148

32-
def documentation(path):
33-
name = PurePosixPath(path).name
34-
return (PurePosixPath(path).suffix in ('.md', '.markdown', '.rst', '.adoc')
35-
or name in ('README', 'NEWS', 'COPYING', 'COPYRIGHT', 'AUTHORS',
36-
'CONTRIBUTING', 'SUPPORT', 'GOVERNANCE', 'INSTALL'))
49+
def no_tests(path):
50+
return (path in NO_TEST_FILES
51+
or path.startswith('rsync-web/') and PurePosixPath(path).suffix in WEBSITE_SUFFIXES)
3752

3853

3954
def workflow(selected, name):
@@ -53,9 +68,8 @@ def workflow(selected, name):
5368
'interoperability-tests.yml': ('interoperability', 'diagnostics'),
5469
}
5570
if name not in mapping:
56-
return False
71+
raise ValueError('Unclassified changed path: ' + repr('.github/workflows/' + name))
5772
enable(selected, *mapping[name])
58-
return True
5973

6074

6175
def script(selected, name):
@@ -91,8 +105,7 @@ def script(selected, name):
91105
elif name == 'install-cygwin.ps1':
92106
enable(selected, 'other', 'diagnostics')
93107
else:
94-
return False
95-
return True
108+
raise ValueError('Unclassified changed path: ' + repr('.github/scripts/' + name))
96109

97110

98111
def testsuite(selected, path):
@@ -123,49 +136,61 @@ def testsuite(selected, path):
123136

124137

125138
def select(paths):
126-
if not paths:
127-
raise ValueError('No changed paths')
128139
selected = empty()
129140
for raw in paths:
130141
path = raw.replace('\\', '/')
131142
parsed = PurePosixPath(path)
132143
if not path or parsed.is_absolute() or '..' in parsed.parts:
133144
raise ValueError('Invalid changed path')
134145
if path == 'rsync.1.md':
135-
return full()
136-
if path in ARCHIVE_DOCUMENTS:
146+
enable(selected, *OUTPUTS)
147+
elif path in ARCHIVE_DOCUMENTS:
137148
enable(selected, 'archive', 'diagnostics')
138-
elif documentation(path):
149+
elif no_tests(path):
139150
continue
140151
elif path.startswith('testsuite/'):
141152
testsuite(selected, path)
142153
elif path.startswith('old_versions/'):
143154
enable(selected, 'versions', 'diagnostics')
144-
elif path.startswith('.github/workflows/'):
145-
if not workflow(selected, parsed.name):
146-
return full()
147-
elif path.startswith('.github/scripts/'):
148-
if not script(selected, parsed.name):
149-
return full()
155+
elif parsed.parent == PurePosixPath('.github/workflows'):
156+
workflow(selected, parsed.name)
157+
elif parsed.parent == PurePosixPath('.github/scripts'):
158+
script(selected, parsed.name)
150159
elif path.startswith('.github/actions/interoperability/'):
151160
enable(selected, 'interoperability', 'diagnostics')
152-
elif path.startswith('.github/actions/'):
153-
return full()
161+
elif (path in FULL_CHECK_FILES or path.startswith(FULL_CHECK_DIRS)
162+
or len(parsed.parts) == 1 and parsed.suffix in SOURCE_SUFFIXES):
163+
enable(selected, *OUTPUTS)
154164
else:
155-
return full()
165+
raise ValueError('Unclassified changed path: ' + repr(path))
156166
return selected
157167

158168

159-
def changed_paths(event):
160-
request = event.get('pull_request')
161-
if not isinstance(request, dict):
162-
raise ValueError('Pull request event has no request')
163-
base = request.get('base', {}).get('sha', '')
164-
head = request.get('head', {}).get('sha', '')
165-
if not re.fullmatch(r'[0-9a-f]{40}', base) or not re.fullmatch(r'[0-9a-f]{40}', head):
166-
raise ValueError('Invalid pull request revisions')
167-
result = subprocess.run(['git', 'diff', '--name-only', '--no-renames', '-z', '--diff-filter=ACDMRTUXB',
168-
base + '...' + head], capture_output=True, timeout=30)
169+
def changed_paths(event, event_name):
170+
if not isinstance(event, dict):
171+
raise ValueError('Invalid CI event')
172+
if event_name == 'pull_request':
173+
request = event.get('pull_request')
174+
if not isinstance(request, dict):
175+
raise ValueError('Pull request event has no request')
176+
base = request.get('base', {}).get('sha', '')
177+
head = request.get('head', {}).get('sha', '')
178+
separator = '...'
179+
elif event_name == 'push':
180+
base, head = event.get('before', ''), event.get('after', '')
181+
separator = '..'
182+
else:
183+
raise ValueError('Unsupported CI event')
184+
if (not isinstance(base, str) or not isinstance(head, str)
185+
or not re.fullmatch(r'[0-9a-f]{40}', base) or not re.fullmatch(r'[0-9a-f]{40}', head)
186+
or head == '0' * 40 or event_name == 'pull_request' and base == '0' * 40):
187+
raise ValueError('Invalid change revisions')
188+
if base == '0' * 40:
189+
command = ['git', 'ls-tree', '--name-only', '-r', '-z', head]
190+
else:
191+
command = ['git', 'diff', '--name-only', '--no-renames', '-z', '--diff-filter=ACDMRTUXB',
192+
base + separator + head]
193+
result = subprocess.run(command, capture_output=True, timeout=30)
169194
if result.returncode or len(result.stdout) > 1024 * 1024:
170195
raise ValueError('Cannot determine changed paths')
171196
paths = [os.fsdecode(value) for value in result.stdout.split(b'\0') if value]
@@ -176,11 +201,13 @@ def changed_paths(event):
176201

177202
def main():
178203
event_name = os.environ.get('GITHUB_EVENT_NAME')
179-
if event_name == 'pull_request':
204+
if event_name in ('pull_request', 'push'):
180205
event = json.loads(Path(os.environ['GITHUB_EVENT_PATH']).read_text())
181-
selected = select(changed_paths(event))
182-
else:
206+
selected = select(changed_paths(event, event_name))
207+
elif event_name in ('schedule', 'workflow_dispatch'):
183208
selected = full()
209+
else:
210+
raise ValueError('Unsupported CI event')
184211
output = Path(os.environ['GITHUB_OUTPUT'])
185212
with output.open('a') as stream:
186213
for name in OUTPUTS:

‎.github/scripts/test-changes.py‎

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ def enabled(self, paths):
1919

2020
def test_documentation_selects_no_test_family(self):
2121
for paths in (['README.md'], ['SECURITY.md', '.github/INTEROPERABILITY.md'],
22-
['INSTALL.md', 'NEWS.md']):
22+
['INSTALL.md', 'NEWS.md', '.github/FUNDING.yml'],
23+
['README.md', 'SECURITY.md', 'rsync-web/security.html', 'rsync-web/bug-tracking.html'],
24+
['rsync-web/header.html', 'rsync-web/tech_report/tech_report.css', 'rsync-web/bar1.jpg']):
2325
with self.subTest(paths=paths):
2426
self.assertEqual(self.enabled(paths), set())
2527

@@ -30,14 +32,22 @@ def test_generated_document_inputs_select_build_qualification(self):
3032
with self.subTest(path=path):
3133
self.assertEqual(self.enabled([path]), {'archive', 'diagnostics'})
3234

33-
def test_production_and_unknown_paths_fail_closed(self):
35+
def test_production_paths_select_the_full_matrix(self):
3436
for path in ('receiver.c', 'Makefile.in', 'packaging/release.py',
35-
'README.c',
36-
'.github/scripts/new-helper.py', '.github/workflows/new.yml',
37-
'.github/actions/new/action.yml'):
37+
'README.c', 'support/README.md', 'lib/new.c', 'wildtest.txt',
38+
'rsync-web/bin/upload', 'rsync-web/rsync_wrapper.pl'):
3839
with self.subTest(path=path):
3940
self.assertEqual(self.enabled([path]), {*families, 'asan', 'coverage', 'clang'})
4041

42+
def test_unclassified_paths_fail_regardless_of_other_changes(self):
43+
for path in ('new-file', 'new-document.md', 'liberty/file.c',
44+
'.github/scripts/new-helper.py', '.github/workflows/new.yml',
45+
'.github/actions/new/action.yml', 'rsync-web/new-helper.py',
46+
'.github/scripts/nested/archive.py', '.github/workflows/nested/linux.yml'):
47+
for paths in ([path], ['receiver.c', path], [path, 'receiver.c']):
48+
with self.subTest(paths=paths), self.assertRaisesRegex(ValueError, 'Unclassified'):
49+
select(paths)
50+
4151
def test_testsuite_avoids_unrelated_product_lanes(self):
4252
expected = {'linux', 'bsd', 'macos', 'other', 'versions', 'diagnostics', 'asan'}
4353
self.assertEqual(self.enabled(['testsuite/tests/transfer/exclude.py']), expected)
@@ -81,26 +91,60 @@ def test_multiple_paths_union_their_owners(self):
8191
{'linux', 'bsd', 'macos', 'other', 'versions',
8292
'android', 'diagnostics', 'asan'})
8393

84-
def test_invalid_or_empty_paths_are_rejected(self):
85-
for paths in ([], ['../receiver.c'], ['/receiver.c']):
94+
def test_no_changed_paths_selects_no_test_family(self):
95+
self.assertEqual(self.enabled([]), set())
96+
97+
def test_invalid_paths_are_rejected(self):
98+
for paths in ([''], ['../receiver.c'], ['/receiver.c']):
8699
with self.subTest(paths=paths), self.assertRaises(ValueError):
87100
select(paths)
88101

89102
def test_pull_request_revisions_and_git_result_are_validated(self):
90103
event = {'pull_request': {'base': {'sha': 'a' * 40}, 'head': {'sha': 'b' * 40}}}
91104
result = subprocess.CompletedProcess([], 0, b'README.md\0receiver.c\0', b'')
92105
with patch.object(changes['subprocess'], 'run', return_value=result) as run:
93-
self.assertEqual(changes['changed_paths'](event), ['README.md', 'receiver.c'])
106+
self.assertEqual(changes['changed_paths'](event, 'pull_request'), ['README.md', 'receiver.c'])
94107
self.assertEqual(run.call_args[0][0][-1], 'a' * 40 + '...' + 'b' * 40)
95108
self.assertIn('--no-renames', run.call_args[0][0])
96109
self.assertIn('--diff-filter=ACDMRTUXB', run.call_args[0][0])
97110
for mutation in ({}, {'pull_request': {}},
98111
{'pull_request': {'base': {'sha': 'x'}, 'head': {'sha': 'b' * 40}}}):
99112
with self.subTest(event=mutation), self.assertRaises(ValueError):
100-
changes['changed_paths'](mutation)
113+
changes['changed_paths'](mutation, 'pull_request')
101114
with patch.object(changes['subprocess'], 'run', return_value=subprocess.CompletedProcess([], 1, b'', b'')), \
102115
self.assertRaises(ValueError):
103-
changes['changed_paths'](event)
116+
changes['changed_paths'](event, 'pull_request')
117+
118+
def test_push_uses_the_whole_before_after_range(self):
119+
event = {'before': 'a' * 40, 'after': 'b' * 40}
120+
result = subprocess.CompletedProcess([], 0, b'receiver.c\0README.md\0', b'')
121+
with patch.object(changes['subprocess'], 'run', return_value=result) as run:
122+
self.assertEqual(changes['changed_paths'](event, 'push'), ['receiver.c', 'README.md'])
123+
self.assertEqual(run.call_args[0][0][-1], 'a' * 40 + '..' + 'b' * 40)
124+
for mutation in ({}, {'before': 'a' * 40}, {'before': 'x', 'after': 'b' * 40},
125+
{'before': 'a' * 40, 'after': '0' * 40}, None, []):
126+
with self.subTest(event=mutation), self.assertRaises(ValueError):
127+
changes['changed_paths'](mutation, 'push')
128+
129+
def test_first_push_classifies_the_whole_tree(self):
130+
event = {'before': '0' * 40, 'after': 'b' * 40}
131+
result = subprocess.CompletedProcess([], 0, b'README.md\0receiver.c\0', b'')
132+
with patch.object(changes['subprocess'], 'run', return_value=result) as run:
133+
paths = changes['changed_paths'](event, 'push')
134+
self.assertEqual(run.call_args[0][0], ['git', 'ls-tree', '--name-only', '-r', '-z', 'b' * 40])
135+
self.assertEqual(self.enabled(paths), {*families, 'asan', 'coverage', 'clang'})
136+
137+
def test_unclassified_push_does_not_write_partial_outputs(self):
138+
with tempfile.TemporaryDirectory() as directory:
139+
output = Path(directory) / 'output'
140+
event = Path(directory) / 'event.json'
141+
event.write_text(json.dumps({'before': 'a' * 40, 'after': 'b' * 40}))
142+
git = subprocess.CompletedProcess([], 0, b'receiver.c\0unclassified\0', b'')
143+
with patch.dict(os.environ, GITHUB_EVENT_NAME='push', GITHUB_EVENT_PATH=str(event),
144+
GITHUB_OUTPUT=str(output)), patch.object(changes['subprocess'], 'run', return_value=git), \
145+
self.assertRaisesRegex(ValueError, 'unclassified'):
146+
changes['main']()
147+
self.assertFalse(output.exists())
104148

105149
def test_main_writes_every_output(self):
106150
with tempfile.TemporaryDirectory() as directory:
@@ -116,13 +160,37 @@ def test_main_writes_every_output(self):
116160
self.assertEqual(set(values), set(changes['OUTPUTS']))
117161
self.assertEqual(set(values.values()), {'false'})
118162

119-
def test_non_pull_request_selects_every_family(self):
163+
def test_push_of_the_security_documentation_selects_no_test_family(self):
120164
with tempfile.TemporaryDirectory() as directory:
121165
output = Path(directory) / 'output'
122-
with patch.dict(os.environ, GITHUB_EVENT_NAME='push', GITHUB_OUTPUT=str(output)):
166+
event = Path(directory) / 'event.json'
167+
event.write_text(json.dumps({'before': 'a' * 40, 'after': 'b' * 40}))
168+
git = subprocess.CompletedProcess([], 0,
169+
b'README.md\0SECURITY.md\0rsync-web/security.html\0rsync-web/bug-tracking.html\0', b'')
170+
with patch.dict(os.environ, GITHUB_EVENT_NAME='push', GITHUB_EVENT_PATH=str(event),
171+
GITHUB_OUTPUT=str(output)), patch.object(changes['subprocess'], 'run', return_value=git):
123172
self.assertEqual(changes['main'](), 0)
124173
values = dict(line.split('=', 1) for line in output.read_text().splitlines())
125-
self.assertEqual(set(values.values()), {'true'})
174+
self.assertEqual(set(values), set(changes['OUTPUTS']))
175+
self.assertEqual(set(values.values()), {'false'})
176+
177+
def test_scheduled_and_manual_runs_select_every_family(self):
178+
with tempfile.TemporaryDirectory() as directory:
179+
output = Path(directory) / 'output'
180+
for event in ('schedule', 'workflow_dispatch'):
181+
with self.subTest(event=event), \
182+
patch.dict(os.environ, GITHUB_EVENT_NAME=event, GITHUB_OUTPUT=str(output)):
183+
self.assertEqual(changes['main'](), 0)
184+
values = dict(line.split('=', 1) for line in output.read_text().splitlines())
185+
self.assertEqual(set(values.values()), {'true'})
186+
187+
def test_unknown_event_does_not_write_a_selection(self):
188+
with tempfile.TemporaryDirectory() as directory:
189+
output = Path(directory) / 'output'
190+
with patch.dict(os.environ, GITHUB_EVENT_NAME='unknown', GITHUB_OUTPUT=str(output)), \
191+
self.assertRaises(ValueError):
192+
changes['main']()
193+
self.assertFalse(output.exists())
126194

127195

128196
if __name__ == '__main__':

‎testsuite/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ With profiles active, an unsupported result is accepted only when the test decla
5656

5757
Linux jobs cover both xattr syscall paths, nested user namespaces, older libc and OpenSSL versions, musl and 32-bit behaviour. We pin one BSD and macOS release unless another release exercises distinct rsync behaviour. Check the workflow files for exact versions.
5858

59-
On pull requests we choose jobs from the changed paths. Documentation-only changes stop after Changes and Required. General tests and shared runner changes run the native platforms, version mixes and relevant diagnostics. We add Android, archive, Valgrind or interoperability only when their own files or shared code change. Any production, build, packaging or unknown path runs everything. Pushes to master and manual runs also run everything.
59+
On pull requests and pushes to master we choose jobs from the changed paths. Known documentation and static website files stop after Changes and Required. General tests and shared runner changes run the native platforms, version mixes and relevant diagnostics. We add Android, archive, Valgrind or interoperability only when their own files or shared code change. Production, build and packaging changes run everything. A path without a selection rule fails Changes. Scheduled and manual runs select the full matrix.
6060

6161
Installed-binary checks exercise restricted SSH and local TLS with certificate and hostname verification. Archive qualification builds and tests the release source archive without Git or Autoconf, then checks installation and removal. Linux storage checks use disposable filesystems and loop devices for encrypted volumes, mount boundaries, space exhaustion, device transfers and --copy-as.
6262

0 commit comments

Comments
 (0)