@@ -142,6 +142,29 @@ def sign_package(package_path: str) -> None:
142142 run (command , check = True )
143143
144144
145+ def prepare_installer_release_artifact (work_dir , build_job_number , arch ):
146+ artifacts = send_ci_request_paged (
147+ f"/project/{ PROJECT_SLUG } /{ build_job_number } /artifacts" )
148+ module_url = None
149+ for artifact in artifacts :
150+ name = artifact ["path" ]
151+ if name == "nginx-configurator" :
152+ module_url = artifact ["url" ]
153+
154+ if module_url is None :
155+ raise Exception (
156+ f"Job number { build_job_number } doesn't have an 'nginx-configurator' build artifact."
157+ )
158+
159+ module_path = work_dir / "nginx-configurator"
160+ download_file (module_url , module_path )
161+
162+ # Package and sign
163+ tarball_path = (work_dir / f"nginx-configurator-{ arch } .tgz" )
164+ package (module_path , out = tarball_path )
165+ sign_package (tarball_path )
166+
167+
145168def prepare_release_artifact (work_dir , build_job_number , version , arch , waf ):
146169 waf_suffix = "-appsec" if waf else ""
147170 artifacts = send_ci_request_paged (
@@ -185,10 +208,19 @@ def prepare_release_artifact(work_dir, build_job_number, version, arch, waf):
185208 sign_package (debug_tarball_path )
186209
187210
188- def handle_job (job , work_dir ):
211+ def handle_job (job , work_dir , installer ):
212+
189213 # See the response schema for a list of statuses:
190214 # https://circleci.com/docs/api/v2/index.html#operation/listWorkflowJobs
191- if job ["name" ].startswith ("build " ):
215+ if installer and job ["name" ].startswith ("build installer " ):
216+ # name should be something like "build installer on arm64"
217+ match = re .match (r"build installer on (amd64|arm64)" , job ["name" ])
218+ if match is None :
219+ raise Exception (f'Job name does not match regex "{ re } ": { job } ' )
220+ arch = match .groups ()[0 ]
221+ prepare_installer_release_artifact (work_dir , job ["job_number" ], arch )
222+ if not installer and job ["name" ].startswith (
223+ "build " ) and not job ["name" ].startswith ("build installer " ):
192224 # name should be something like "build 1.25.4 on arm64 WAF ON"
193225 match = re .match (r"build ([\d.]+) on (amd64|arm64) WAF (ON|OFF)" ,
194226 job ["name" ])
@@ -213,6 +245,9 @@ def handle_job(job, work_dir):
213245 help =
214246 "ID of the release workflow. Find in job url. Example: https://app.circleci.com/pipelines/github/DataDog/nginx-datadog/542/workflows/<WORKFLOW_ID>" ,
215247 )
248+ parser .add_argument ("--installer" ,
249+ help = "Release the NGINX installer" ,
250+ action = argparse .BooleanOptionalAction )
216251 options = parser .parse_args ()
217252
218253 ci_api_token = options .ci_token
@@ -247,7 +282,7 @@ def handle_job(job, work_dir):
247282 sys .exit (1 )
248283
249284 for job in jobs :
250- result = handle_job (job , Path (work_dir ))
285+ result = handle_job (job , Path (work_dir ), options . installer )
251286 if result != "done" :
252287 sys .exit (1 )
253288
0 commit comments