1+ import shutil
2+ import textwrap
3+ import os
4+ import subprocess
5+ from functools import cache
6+ import re
7+
8+
9+ def run_cmd (args : list [str ], working_dir : str = "." ) -> str :
10+ print (f"\t Running command: { ' ' .join (args )} " )
11+ result = subprocess .run (args , cwd = working_dir , capture_output = True , text = True , check = True )
12+ if result .returncode != 0 :
13+ print (f"Command failed with exit code { result .returncode } : { result .args } " )
14+ os .exit (1 )
15+ return result .stdout
16+
17+ @cache
18+ def get_repo_path () -> str :
19+ cache_file = "openvadl-path.txt"
20+ if not os .path .exists (cache_file ):
21+ repo_path = input ("Enter the path to the OpenVADL repo:" )
22+ with open (cache_file , "w" ) as f :
23+ f .write (repo_path )
24+
25+ with open (cache_file ) as f :
26+ return f .read ()
27+
28+
29+ def build_lsp ():
30+ print ("1) Building LSP" )
31+ repo_path = get_repo_path ()
32+
33+ ## Checkout master
34+ current_branch = run_cmd (["git" , "rev-parse" , "--abbrev-ref" , "HEAD" ], repo_path ).strip ()
35+ if current_branch != "master" :
36+ print (f"Not on master branch ({ current_branch } )." )
37+ answer = input ("Can we switch to master? (y/n): " )
38+ if answer .lower () not in ["y" , "yes" ]:
39+ print ("Aborting LSP build." )
40+ return
41+
42+ run_cmd (["git" , "checkout" , "master" ], repo_path )
43+ run_cmd (["git" , "pull" ,], repo_path )
44+
45+ ## Build LSP
46+ run_cmd (["./gradlew" , ":vadl-lsp:installDist" ], repo_path )
47+
48+
49+ def copy_lsp ():
50+ print ("2) Copy LSP results" )
51+ repo_path = get_repo_path ()
52+ target_dir = "src/main/resources/openvadl-lsp"
53+
54+ if os .path .exists (target_dir ):
55+ shutil .rmtree (target_dir )
56+
57+ shutil .copytree (repo_path + "/vadl-lsp/build/install/openvadl-lsp" , target_dir )
58+
59+
60+ def update_metadata ():
61+ print ("3) Update Metadata" )
62+
63+ # Read build.gradle.kts
64+ build_file = "build.gradle.kts"
65+ with open (build_file , 'r' ) as f :
66+ content = f .read ()
67+
68+ # Find and increment the version
69+ version_pattern = r'version = "(\d+)\.(\d+)\.(\d+)"'
70+ match = re .search (version_pattern , content )
71+
72+ if match :
73+ major , minor , patch = match .groups ()
74+ new_patch = int (patch ) + 1
75+ new_version = f"{ major } .{ minor } .{ new_patch } "
76+
77+ # Replace the version
78+ new_content = re .sub (version_pattern , f'version = "{ new_version } "' , content )
79+
80+ with open (build_file , 'w' ) as f :
81+ f .write (new_content )
82+
83+ print (f"\t Updated version from { major } .{ minor } .{ patch } to { new_version } " )
84+ else :
85+ print ("\t Warning: Could not find version in build.gradle.kts" )
86+
87+
88+ def build_plugin ():
89+ print ("4) Building plugin" )
90+ run_cmd (["./gradlew" , "buildPlugin" ])
91+
92+
93+
94+ def publish ():
95+ print (textwrap .dedent ("""
96+ 5) Publishing LSP
97+ At the moment we are still awaiting approval from JetBrains. So all updates have to be done manually.
98+ https://plugins.jetbrains.com/plugin/29659-openvadl/edit
99+
100+ Build plugin is at:
101+ build/idea-sandbox/IU-2025.3/plugins/intellij-openvadl/lib/
102+ """ ).strip ())
103+
104+ def main ():
105+ build_lsp ()
106+ print ()
107+ copy_lsp ()
108+ print ()
109+ update_metadata ()
110+ print ()
111+ build_plugin ()
112+ print ()
113+ publish ()
114+ print ()
115+ print ("Done ✨" )
116+
117+ if __name__ == "__main__" :
118+ main ()
0 commit comments