This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add a CI job to check that schema deltas are in the correct folder. #13063
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add a CI job to check that schema deltas are in the correct folder. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,7 +272,7 @@ parameterized = ">=0.7.4" | |
idna = ">=2.5" | ||
|
||
# The following are used by the release script | ||
click = "==8.1.0" | ||
click = "==8.1.1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, this'll be my fault for making scripts-dev by checked by mypy. (Not sorry) |
||
# GitPython was == 3.1.14; bumped to 3.1.20, the first release with type hints. | ||
GitPython = ">=3.1.20" | ||
commonmark = "==0.9.1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Check that no schema deltas have been added to the wrong version. | ||
|
||
import re | ||
from typing import Any, Dict, List | ||
|
||
import click | ||
import git | ||
|
||
SCHEMA_FILE_REGEX = re.compile(r"^synapse/storage/schema/(.*)/delta/(.*)/(.*)$") | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"--force-colors", | ||
is_flag=True, | ||
flag_value=True, | ||
default=None, | ||
help="Always output ANSI colours", | ||
) | ||
def main(force_colors: bool) -> None: | ||
click.secho( | ||
"+++ Checking schema deltas are in the right folder", | ||
fg="green", | ||
bold=True, | ||
color=force_colors, | ||
) | ||
|
||
click.secho("Updating repo...") | ||
|
||
repo = git.Repo() | ||
repo.remote().fetch() | ||
|
||
click.secho("Getting current schema version...") | ||
|
||
r = repo.git.show("origin/develop:synapse/storage/schema/__init__.py") | ||
|
||
locals: Dict[str, Any] = {} | ||
exec(r, locals) | ||
current_schema_version = locals["SCHEMA_VERSION"] | ||
|
||
click.secho(f"Current schema version: {current_schema_version}") | ||
|
||
diffs: List[git.Diff] = repo.remote().refs.develop.commit.diff(None) | ||
|
||
seen_deltas = False | ||
bad_files = [] | ||
for diff in diffs: | ||
if not diff.new_file or diff.b_path is None: | ||
continue | ||
|
||
match = SCHEMA_FILE_REGEX.match(diff.b_path) | ||
if not match: | ||
continue | ||
|
||
seen_deltas = True | ||
|
||
_, delta_version, _ = match.groups() | ||
|
||
if delta_version != str(current_schema_version): | ||
bad_files.append(diff.b_path) | ||
Comment on lines
+61
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes PRs that
Workaround for now is to split those two bullet points across separate PRs. |
||
|
||
if not seen_deltas: | ||
click.secho( | ||
"No deltas found.", | ||
fg="green", | ||
bold=True, | ||
color=force_colors, | ||
) | ||
return | ||
|
||
if not bad_files: | ||
click.secho( | ||
f"All deltas are in the correct folder: {current_schema_version}!", | ||
fg="green", | ||
bold=True, | ||
color=force_colors, | ||
) | ||
return | ||
|
||
bad_files.sort() | ||
|
||
click.secho( | ||
"Found deltas in the wrong folder!", | ||
fg="red", | ||
bold=True, | ||
color=force_colors, | ||
) | ||
|
||
for f in bad_files: | ||
click.secho( | ||
f"\t{f}", | ||
fg="red", | ||
bold=True, | ||
color=force_colors, | ||
) | ||
|
||
click.secho() | ||
click.secho( | ||
f"Please move these files to delta/{current_schema_version}/", | ||
fg="red", | ||
bold=True, | ||
color=force_colors, | ||
) | ||
|
||
click.get_current_context().exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd be using the poetry locked environment here (and indeed in
check-sampleconfig
andlint-newsfile
)---but I won't block this on that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mainly did this as its so much faster than installing all the deps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but FWIW there's a bunch of caching in https://github.com/matrix-org/setup-python-poetry which should help mitigate that