|
1 | 1 | import os
|
| 2 | +import subprocess |
2 | 3 | import sys
|
3 | 4 |
|
4 | 5 | import pytest
|
@@ -244,6 +245,136 @@ def test_chartpress_run(git_repo, capfd, base_version):
|
244 | 245 | git_repo.git.stash("pop")
|
245 | 246 |
|
246 | 247 |
|
| 248 | +def test_tbump_release(git_repo, git_repo_base_version, capfd): |
| 249 | + """Run through tagging""" |
| 250 | + |
| 251 | + def get_base_version(): |
| 252 | + """Get baseVersion config from chartpress.yaml""" |
| 253 | + with open("chartpress.yaml") as f: |
| 254 | + chartpress_config = yaml.load(f) |
| 255 | + |
| 256 | + chart = chartpress_config["charts"][0] |
| 257 | + return chart["baseVersion"] |
| 258 | + |
| 259 | + def get_chart_version(): |
| 260 | + """Get the current version in Chart.yaml""" |
| 261 | + with open("testchart/Chart.yaml") as f: |
| 262 | + chart = yaml.load(f) |
| 263 | + return chart["version"] |
| 264 | + |
| 265 | + # run chartpress with --no-build and any additional arguments |
| 266 | + def run_chartpress(args=None): |
| 267 | + """run chartpress with --no-build and any additional arguments""" |
| 268 | + if args is None: |
| 269 | + args = [] |
| 270 | + if args != ["--reset"]: |
| 271 | + args = ["--no-build"] + args |
| 272 | + out = _capture_output(args, capfd) |
| 273 | + print(out) |
| 274 | + return out |
| 275 | + |
| 276 | + def tbump(args): |
| 277 | + """Run tbump with args""" |
| 278 | + subprocess.run(["git", "status"]) |
| 279 | + proc = subprocess.run( |
| 280 | + ["tbump", "--non-interactive", "--no-push"] + args, |
| 281 | + capture_output=True, |
| 282 | + text=True, |
| 283 | + ) |
| 284 | + # echo output before checking return code |
| 285 | + # so we see it on errors |
| 286 | + sys.stdout.write(proc.stdout) |
| 287 | + sys.stderr.write(proc.stderr) |
| 288 | + assert proc.returncode == 0 |
| 289 | + # increment commit count because tbump makes a commit |
| 290 | + nonlocal n |
| 291 | + n += 1 |
| 292 | + return proc.stdout, proc.stderr |
| 293 | + |
| 294 | + base_version = get_base_version() |
| 295 | + assert base_version == "1.0.0-0.dev" |
| 296 | + |
| 297 | + # summarize information from git_repo |
| 298 | + sha = git_repo.commit("HEAD").hexsha[:7] |
| 299 | + n = chartpress._count_commits(sha) |
| 300 | + tag = f"{base_version}.git.{n}.h{sha}" |
| 301 | + run_chartpress() |
| 302 | + assert get_chart_version() == tag |
| 303 | + |
| 304 | + # tag a prerelease |
| 305 | + run_chartpress(["--reset"]) |
| 306 | + version = "1.0.0-beta.1" |
| 307 | + with open("chartpress.yaml") as f: |
| 308 | + print(f.read()) |
| 309 | + tbump([version]) |
| 310 | + base_version = get_base_version() |
| 311 | + assert base_version == version |
| 312 | + |
| 313 | + # reset passes |
| 314 | + run_chartpress(["--reset"]) |
| 315 | + # after chartpress, version is correct (no suffix) |
| 316 | + run_chartpress() |
| 317 | + assert get_chart_version() == version |
| 318 | + |
| 319 | + extra_chart_path = "extra-chart-path.txt" |
| 320 | + # add a commit |
| 321 | + with open(extra_chart_path, "w") as f: |
| 322 | + f.write("first") |
| 323 | + |
| 324 | + git_repo.git.add(extra_chart_path) |
| 325 | + sha = git_repo.index.commit("Added commit").hexsha[:7] |
| 326 | + n += 1 # added a commit |
| 327 | + tag = f"{base_version}.git.{n}.h{sha}" |
| 328 | + |
| 329 | + # reset passes |
| 330 | + run_chartpress(["--reset"]) |
| 331 | + # after chartpress, version is correct (with suffix) |
| 332 | + run_chartpress() |
| 333 | + assert get_chart_version() == tag |
| 334 | + |
| 335 | + # tag a final release |
| 336 | + run_chartpress(["--reset"]) |
| 337 | + version = "1.0.0" |
| 338 | + tbump([version]) |
| 339 | + base_version = get_base_version() |
| 340 | + |
| 341 | + # reset passes |
| 342 | + run_chartpress(["--reset"]) |
| 343 | + |
| 344 | + # chartpress gets tag version |
| 345 | + run_chartpress() |
| 346 | + assert get_chart_version() == version |
| 347 | + |
| 348 | + # reset before making a commit |
| 349 | + run_chartpress(["--reset"]) |
| 350 | + |
| 351 | + # Add a commit (without bumping baseVersion) |
| 352 | + with open(extra_chart_path, "w") as f: |
| 353 | + f.write("second") |
| 354 | + |
| 355 | + git_repo.git.add(extra_chart_path) |
| 356 | + sha = git_repo.index.commit("Added commit").hexsha[:7] |
| 357 | + n += 1 # added a commit |
| 358 | + |
| 359 | + # reset balks because baseVersion hasn't been updated |
| 360 | + with pytest.raises(ValueError, match="not greater than latest tag"): |
| 361 | + run_chartpress(["--reset"]) |
| 362 | + |
| 363 | + # tbump next dev release (the last step of making a stable release) |
| 364 | + base_version = "1.1.0-0.dev" |
| 365 | + tbump(["--no-tag", base_version]) |
| 366 | + |
| 367 | + assert get_base_version() == base_version |
| 368 | + # reset is happy now |
| 369 | + run_chartpress(["--reset"]) |
| 370 | + |
| 371 | + # final chartpress render |
| 372 | + run_chartpress() |
| 373 | + sha = git_repo.heads.main.commit.hexsha[:7] |
| 374 | + tag = f"{base_version}.git.{n}.h{sha}" |
| 375 | + assert get_chart_version() == tag |
| 376 | + |
| 377 | + |
247 | 378 | def test_chartpress_paths_configuration(git_repo, capfd):
|
248 | 379 | """
|
249 | 380 | Background:
|
|
0 commit comments