prefix version tags with 'v' (#6810)

This commit is contained in:
Maximilian Hils 2024-04-19 21:28:05 +02:00 committed by GitHub
parent 4d00ec03b4
commit 2c96c96e75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 30 additions and 17 deletions

View file

@ -19,7 +19,9 @@ tag: str | None = None
if ref.startswith("refs/heads/"):
branch = ref.replace("refs/heads/", "")
elif ref.startswith("refs/tags/"):
tag = ref.replace("refs/tags/", "")
if not ref.startswith("refs/tags/v"):
raise AssertionError(f"Unexpected tag: {ref}")
tag = ref.replace("refs/tags/v", "")
else:
raise AssertionError("Failed to parse $GITHUB_REF")

View file

@ -83,9 +83,17 @@ def archive(path: Path) -> tarfile.TarFile | ZipFile2:
def version() -> str:
return os.environ.get("GITHUB_REF_NAME", "").replace("/", "-") or os.environ.get(
"BUILD_VERSION", "dev"
)
if ref := os.environ.get("GITHUB_REF", ""):
if ref.startswith("refs/tags/") and not ref.startswith("refs/tags/v"):
raise AssertionError(f"Unexpected tag: {ref}")
return (
ref.removeprefix("refs/heads/")
.removeprefix("refs/pull/")
.removeprefix("refs/tags/v")
.replace("/", "-")
)
else:
return os.environ.get("BUILD_VERSION", "dev")
def operating_system() -> str:

View file

@ -14,7 +14,9 @@ if __name__ == "__main__":
if ref.startswith("refs/heads/"):
branch = ref.replace("refs/heads/", "")
elif ref.startswith("refs/tags/"):
tag = ref.replace("refs/tags/", "")
if not ref.startswith("refs/tags/v"):
raise AssertionError(f"Unexpected tag: {ref}")
tag = ref.replace("refs/tags/v", "")
else:
raise AssertionError

View file

@ -99,7 +99,8 @@ if __name__ == "__main__":
subprocess.run(
["git", "commit", "-a", "-m", f"mitmproxy {version}"], cwd=root, check=True
)
subprocess.run(["git", "tag", version], cwd=root, check=True)
tag_name = f"v{version}"
subprocess.run(["git", "tag", tag_name], cwd=root, check=True)
release_sha = subprocess.run(
["git", "rev-parse", "HEAD"],
cwd=root,
@ -124,7 +125,7 @@ if __name__ == "__main__":
print("➡️ Pushing...")
subprocess.run(
["git", "push", "--atomic", "origin", branch, version], cwd=root, check=True
["git", "push", "--atomic", "origin", branch, tag_name], cwd=root, check=True
)
print("➡️ Creating release on GitHub...")
@ -133,7 +134,7 @@ if __name__ == "__main__":
"gh",
"release",
"create",
version,
tag_name,
"--title",
f"mitmproxy {version}",
"--notes-file",
@ -145,7 +146,7 @@ if __name__ == "__main__":
print("➡️ Dispatching release workflow...")
subprocess.run(
["gh", "workflow", "run", "main.yml", "--ref", version], cwd=root, check=True
["gh", "workflow", "run", "main.yml", "--ref", tag_name], cwd=root, check=True
)
print("")