11import argparse
22import logging
3+ from pathlib import Path
34from typing import Literal , cast
45
56from .build_matrix import build_matrix
910from .versions import (
1011 decide_version_combinations ,
1112 find_new_or_updated ,
13+ load_build_contexts ,
1214 persist_versions ,
1315 supported_versions ,
1416)
@@ -25,6 +27,7 @@ class CLIArgs(argparse.Namespace):
2527
2628 context : str # dockerfile command arg
2729 event : str # build-matrix command arg
30+ builds_dir : Path # release command arg
2831
2932
3033def run_dockerfile (args : CLIArgs ) -> None :
@@ -39,10 +42,9 @@ def run_build_matrix(args: CLIArgs) -> None:
3942
4043
4144def run_release (args : CLIArgs ) -> None :
42- suported_python_versions , suported_nodejs_versions = supported_versions ()
43- versions = decide_version_combinations (args .distros , suported_python_versions , suported_nodejs_versions )
45+ versions = load_build_contexts (args .builds_dir )
4446 new_or_updated = find_new_or_updated (versions , args .force )
45-
47+ suported_python_versions , suported_nodejs_versions = supported_versions ()
4648 if not new_or_updated :
4749 logger .info ("No new or updated versions" )
4850 return
@@ -84,9 +86,11 @@ def parse_args() -> CLIArgs:
8486 parser .add_argument ("--verbose" , action = "store_true" , help = "Enable debug logging" )
8587
8688 subparsers = parser .add_subparsers (dest = "command" , help = "Sub-commands" )
89+
8790 # Dockerfile command
8891 parser_dockerfile = subparsers .add_parser ("dockerfile" , help = "Render a dockerfile based on version config" )
8992 parser_dockerfile .add_argument ("--context" , default = "" , help = "Dockerfile version config" )
93+
9094 # Build matrix command
9195 parser_build_matrix = subparsers .add_parser ("build-matrix" , help = "Generate CI build matrix" )
9296 parser_build_matrix .add_argument (
@@ -95,6 +99,22 @@ def parse_args() -> CLIArgs:
9599 # https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
96100 help = "GitHub Action event name (github.event_name)" ,
97101 )
102+
98103 # Release command
99- subparsers .add_parser ("release" , help = "Persist versions and make a release" )
100- return cast (CLIArgs , parser .parse_args ())
104+ parser_release = subparsers .add_parser ("release" , help = "Persist versions and make a release" )
105+ parser_release .add_argument (
106+ "--builds-dir" ,
107+ type = Path ,
108+ required = True ,
109+ help = "Builds directory with build context JSON files" ,
110+ )
111+
112+ cli_args = cast ("CLIArgs" , parser .parse_args ())
113+ if cli_args .command == "release" :
114+ if not cli_args .builds_dir .exists ():
115+ parser .error (f"Builds directory { cli_args .builds_dir .as_posix ()} does not exist" )
116+
117+ if not cli_args .builds_dir .is_dir ():
118+ parser .error (f"Builds directory { cli_args .builds_dir .as_posix ()} is not a directory" )
119+
120+ return cli_args
0 commit comments