@@ -28,6 +28,34 @@ def template_path() -> pathlib.Path:
2828 return BINDIR / '..' / 'service_template'
2929
3030
31+ def version_file_path () -> pathlib .Path :
32+ if is_system_installed ():
33+ return BINDIR / '..' / 'share' / 'userver' / 'version.txt'
34+ return BINDIR / '..' / 'version.txt'
35+
36+
37+ def get_userver_version () -> str :
38+ version_path = version_file_path ()
39+ return version_path .read_text ().strip ()
40+
41+
42+ def get_devcontainer_version (userver_version : str ) -> str :
43+ if userver_version .endswith ('-rc' ):
44+ return 'latest'
45+ return f'v{ userver_version } '
46+
47+
48+ def patch_devcontainer_version (service_path : pathlib .Path ) -> None :
49+ devcontainer_path = service_path / '.devcontainer' / 'devcontainer.json'
50+
51+ userver_version = get_userver_version ()
52+ devcontainer_version = get_devcontainer_version (userver_version )
53+
54+ content = devcontainer_path .read_text ()
55+ content = re .sub (r'"(ghcr\.io/[^"]+)"' , rf'"\1:{ devcontainer_version } "' , content )
56+ devcontainer_path .write_text (content )
57+
58+
3159def parse_args ():
3260 parser = argparse .ArgumentParser (
3361 description = 'Create new C++ userver-based service' )
@@ -103,6 +131,7 @@ def main() -> None:
103131 args = parse_args ()
104132 check_dst_non_existing (args .service_path )
105133 copy_tree (template_path (), args .service_path , args )
134+ patch_devcontainer_version (args .service_path )
106135 run_ruff (args .service_path )
107136
108137
0 commit comments