3c9d74 Update branch detection for c10s

Authored and Committed by sgallagh a year ago
    Update branch detection for c10s
    
    In RHEL 10, the internal branch names have dropped the extra .0
    
    Additionally, there will now also be a rhel-X.0-beta branch.
    
    Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
    
        
file modified
+39 -30
src/centpkg/cli.py CHANGED
@@ -158,27 +158,33 @@ class centpkgClient(cliClient):
158
158
stream_version = self.cmd.target.split('-')[0]
159
159
rhel_version = centpkg.utils.stream_mapping(stream_version)
160
160
try:
161
- active_y, in_stabilization = centpkg.utils.determine_active_y_version(rhel_version, pp_api_url)
161
+ x_version, active_y, is_beta, in_stabilization = centpkg.utils.determine_active_y_version(rhel_version, pp_api_url)
162
162
except AssertionError as e:
163
163
self.log.error(" Error: centpkg cannot determine the development phase.")
164
164
self.log.error(" Please file an issue at https://git.centos.org/centos/centpkg")
165
165
self.log.error(" Workaround: Use the --rhel-target option")
166
166
self.log.error("Exiting")
167
167
raise SystemExit(1)
168
- divergent_branch = centpkg.utils.does_divergent_branch_exist(
169
- self.cmd.repo_name,
170
- rhel_version,
171
- active_y,
172
- rhel_dist_git,
173
- pp_api_url,
174
- "rpms")
168
+ if is_beta:
169
+ # Special case: for X.0 betas, there will never be a prior branch
170
+ # In this case, always work on the active branch.
171
+ divergent_branch = True
172
+ else:
173
+ divergent_branch = centpkg.utils.does_divergent_branch_exist(
174
+ self.cmd.repo_name,
175
+ x_version,
176
+ active_y,
177
+ rhel_dist_git,
178
+ "rpms")
175
179
# Good to know
176
180
if in_stabilization :
177
181
self.log.info(" we are in stabilization mode.")
178
182
else:
179
183
self.log.info(" we are not in stabilization mode.")
180
- if divergent_branch :
184
+ if divergent_branch and not is_beta:
181
185
self.log.info(" a divergent branch was found.")
186
+ elif divergent_branch and is_beta:
187
+ self.log.info(" we are working on a beta release.")
182
188
else:
183
189
self.log.info(" a divergent branch was not found.")
184
190
else:
@@ -253,35 +259,38 @@ class centpkgClient(cliClient):
253
259
stream_version = self.cmd.target.split('-')[0]
254
260
rhel_version = centpkg.utils.stream_mapping(stream_version)
255
261
256
- # Until RHEL 10.1 is starting, set 10 to latest, by setting divergent_branch to True
257
- if stream_version == "c10s" or rhel_version == "rhel-10":
262
+ try:
263
+ x_version, active_y, is_beta, in_stabilization = centpkg.utils.determine_active_y_version(rhel_version, pp_api_url)
264
+ except AssertionError as e:
265
+ self.log.error(" Error: centpkg cannot determine the development phase.")
266
+ self.log.error(" Please file an issue at https://git.centos.org/centos/centpkg")
267
+ self.log.error(" Workaround: Use the --rhel-target option")
268
+ self.log.error("Exiting")
269
+ raise SystemExit(1)
270
+
271
+ if is_beta:
272
+ # Special case: for X.0 betas, there will never be a prior branch
273
+ # In this case, always work on the active branch.
258
274
divergent_branch = True
259
275
else:
260
- try:
261
- active_y, in_stabilization = centpkg.utils.determine_active_y_version(rhel_version, pp_api_url)
262
- except AssertionError as e:
263
- self.log.error(" Error: centpkg cannot determine the development phase.")
264
- self.log.error(" Please file an issue at https://git.centos.org/centos/centpkg")
265
- self.log.error(" Workaround: Use the --rhel-target option")
266
- self.log.error("Exiting")
267
- raise SystemExit(1)
268
276
divergent_branch = centpkg.utils.does_divergent_branch_exist(
269
277
self.cmd.repo_name,
270
- rhel_version,
278
+ x_version,
271
279
active_y,
272
280
rhel_dist_git,
273
- pp_api_url,
274
281
"rpms")
275
282
276
- # Good to know
277
- if divergent_branch :
278
- self.log.info(" a divergent branch was found.")
279
- else:
280
- self.log.info(" a divergent branch was not found.")
281
- if in_stabilization :
282
- self.log.info(" we are in stabilization mode.")
283
- else:
284
- self.log.info(" we are not in stabilization mode.")
283
+ # Good to know
284
+ if divergent_branch and not is_beta:
285
+ self.log.info(" a divergent branch was found.")
286
+ elif divergent_branch and is_beta:
287
+ self.log.info(" we are working on a beta release.")
288
+ else:
289
+ self.log.info(" a divergent branch was not found.")
290
+ if in_stabilization :
291
+ self.log.info(" we are in stabilization mode.")
292
+ else:
293
+ self.log.info(" we are not in stabilization mode.")
285
294
286
295
# Update args.custom_user_metadata
287
296
if hasattr(self.args, 'custom_user_metadata') and self.args.custom_user_metadata:
file modified
+61 -24
src/centpkg/utils.py CHANGED
@@ -285,14 +285,22 @@ def stream_mapping(csname):
285
285
return "rhel-11"
286
286
return None
287
287
288
- def does_divergent_branch_exist(repo_name, rhel_version, active_y, rhel_dist_git, pp_api_url, namespace):
288
+ def does_divergent_branch_exist(repo_name, x_version, active_y, rhel_dist_git, namespace):
289
289
logger = logging.getLogger(__name__)
290
290
291
291
# Determine if the Y-1 branch exists for this repo
292
292
293
- divergent_branch = "{}.{}.0".format(rhel_version, active_y - 1)
293
+ if x_version >= 10 and active_y <= 0:
294
+ # For 10.0 and later X.0 releases, check for a rhel-X.0-beta branch
295
+ divergent_branch = "rhel-{}.0-beta".format(x_version)
296
+ elif x_version <= 9:
297
+ divergent_branch = "rhel-{}.{}.0".format(x_version, active_y - 1)
298
+ else:
299
+ # Starting with RHEL 10, the branch names have dropped the extra .0
300
+ divergent_branch = "rhel-{}.{}".format(x_version, active_y - 1)
301
+
294
302
logger.debug("Divergent branch: {}".format(divergent_branch))
295
-
303
+
296
304
g = gitpython.cmd.Git()
297
305
try:
298
306
g.ls_remote(
@@ -316,56 +324,85 @@ def _datesplit(isodate):
316
324
return [ int(x) for x in date_string_tuple ]
317
325
318
326
319
- def determine_active_y_version(rhel_version, pp_api_url):
327
+ def parse_rhel_shortname(shortname):
328
+ # The shortname is in the form rhel-9-1.0 or rhel-10.0[.beta]
329
+ m = re.match(
330
+ "rhel-(?P<major>[0-9]+)[.-](?P<minor>[0-9]+)([.]0|[.](?P<extra>.*))?", shortname
331
+ )
332
+ if not m:
333
+ raise RuntimeError("Could not parse version from {}".format(shortname))
334
+
335
+ major_version = int(m.group("major"))
336
+ minor_version = int(m.group("minor"))
337
+ extra_version = m.group("extra") or None
338
+
339
+ return major_version, minor_version, extra_version
340
+
341
+
342
+ def determine_active_y_version(rhel_version, api_url):
320
343
"""
321
- Returns: A 2-tuple of the active Y-stream version(int) and whether we are
322
- in the Exception Phase(bool)
344
+ Returns: A 4-tuple containing:
345
+ 0. The major release version(int)
346
+ 1. The active Y-stream version(int)
347
+ 2. Whether the active release is the pre-X.0 beta
348
+ 3. Whether we are in the Exception Phase(bool)
323
349
"""
324
350
logger = logging.getLogger(__name__)
325
351
326
- # Query the "package pages" API for the current active Y-stream release
352
+ # Phase Identifiers
327
353
# Phase 230 is "Planning / Development / Testing" (AKA DevTestDoc)
328
354
# Phase 450 is "Stabilization"
355
+ phase_devtestdoc = 230
356
+ phase_stabilization = 450
357
+
358
+ # Query the "package pages" API for the current active Y-stream release
329
359
request_params = {
330
- "phase__in": "230,450",
360
+ "phase__in": "{},{}".format(phase_devtestdoc, phase_stabilization),
331
361
"product__shortname": "rhel",
332
362
"relgroup__shortname": rhel_version,
333
363
"format": "json",
334
364
}
335
365
336
366
res = requests.get(
337
- os.path.join(pp_api_url, "latest", "releases"),
367
+ os.path.join(api_url, "latest", "releases"),
338
368
params=request_params,
339
369
timeout=60,
340
370
)
341
371
res.raise_for_status()
342
372
payload = json.loads(res.text)
343
- logger.debug(
373
+ logger.debug("Response from PP API: {}".format(json.dumps(payload, indent=2)))
344
- "Response from PP API: {}".format(json.dumps(payload, indent=2))
345
- )
346
374
if len(payload) < 1:
347
- raise RuntimeError("Received zero potential release matches")
375
+ # Received zero potential release matches
376
+ logger.warning("Didn't match any active releases. Assuming pre-Beta.")
377
+
378
+ # Fake up a Beta payload
379
+ payload = [
380
+ {
381
+ "shortname": "{}.0.beta".format(rhel_version),
382
+ "phase": phase_devtestdoc,
383
+ }
384
+ ]
348
385
349
- release_id = -1
350
386
active_y_version = -1
387
+ beta = False
351
388
for entry in payload:
352
389
shortname = entry["shortname"]
353
390
354
- # The shortname is in the form rhel-9-1.0
391
+ # The shortname is in the form rhel-9-1.0 or rhel-10.0[.beta]
355
392
# Extract the active Y-stream version
356
- m = re.search("(?<={}-)\d+(?=\.0)".format(rhel_version), shortname)
357
- if not m:
393
+ x_version, y_version, extra_version = parse_rhel_shortname(shortname)
394
+
358
- raise RuntimeError(
359
- "Could not determine active Y-stream version from shortname"
360
- )
361
- y_version = int(m.group(0))
362
395
if y_version > active_y_version:
363
396
active_y_version = y_version
364
- release_id = entry["id"]
397
+ beta = bool(extra_version and "beta" in extra_version)
365
398
366
399
in_exception_phase = entry["phase"] == 450
367
400
368
- logger.debug("Active Y-stream: {}, Enforcing: {}".format(active_y_version, in_exception_phase))
401
+ logger.debug(
402
+ "Active Y-stream: {}, Enforcing: {}, Beta: {}".format(
403
+ active_y_version, in_exception_phase, beta
404
+ )
405
+ )
369
406
370
- return active_y_version, in_exception_phase
407
+ return x_version, active_y_version, beta, in_exception_phase
371
408