Answer architecture round 1: 0 🔴, 7 🟡; build with the gate's Go, guard single-version channels on older tags, record the Cloudsmith tie, and return the tag from publish()
This commit is contained in:
@@ -36,19 +36,16 @@ changelog:
|
||||
disable: true
|
||||
|
||||
release:
|
||||
github:
|
||||
owner: larvit
|
||||
name: fejkdata
|
||||
mode: keep-existing
|
||||
replace_existing_artifacts: true
|
||||
|
||||
nfpms:
|
||||
- package_name: fejkdata
|
||||
vendor: Larvit
|
||||
homepage: https://github.com/larvit/fejkdata
|
||||
maintainer: Lilleman auf Larv <lilleman@larvit.se>
|
||||
description: Render locale-aware fake data from JSON templates.
|
||||
license: MIT
|
||||
homepage: &homepage https://github.com/larvit/fejkdata
|
||||
maintainer: &maintainer Lilleman auf Larv <lilleman@larvit.se>
|
||||
description: &description Render locale-aware fake data from JSON templates
|
||||
license: &license MIT
|
||||
formats: [deb, rpm, apk]
|
||||
contents:
|
||||
- src: LICENSE
|
||||
@@ -64,16 +61,16 @@ dockers_v2:
|
||||
- latest
|
||||
dockerfile: ../tooling/release-tooling/image.Dockerfile
|
||||
labels:
|
||||
org.opencontainers.image.source: https://github.com/larvit/fejkdata
|
||||
org.opencontainers.image.source: *homepage
|
||||
org.opencontainers.image.version: "{{ .Version }}"
|
||||
org.opencontainers.image.licenses: MIT
|
||||
org.opencontainers.image.licenses: *license
|
||||
|
||||
homebrew_casks:
|
||||
- name: fejkdata
|
||||
binaries: [fejkdata]
|
||||
homepage: https://github.com/larvit/fejkdata
|
||||
description: Render locale-aware fake data from JSON templates
|
||||
license: MIT
|
||||
homepage: *homepage
|
||||
description: *description
|
||||
license: *license
|
||||
repository:
|
||||
owner: larvit
|
||||
name: homebrew-tap
|
||||
@@ -87,9 +84,9 @@ homebrew_casks:
|
||||
|
||||
scoops:
|
||||
- name: fejkdata
|
||||
homepage: https://github.com/larvit/fejkdata
|
||||
description: Render locale-aware fake data from JSON templates.
|
||||
license: MIT
|
||||
homepage: *homepage
|
||||
description: *description
|
||||
license: *license
|
||||
repository:
|
||||
owner: larvit
|
||||
name: scoop-bucket
|
||||
@@ -97,11 +94,11 @@ scoops:
|
||||
|
||||
aurs:
|
||||
- name: fejkdata-bin
|
||||
homepage: https://github.com/larvit/fejkdata
|
||||
description: Render locale-aware fake data from JSON templates
|
||||
license: MIT
|
||||
homepage: *homepage
|
||||
description: *description
|
||||
license: *license
|
||||
maintainers:
|
||||
- Lilleman auf Larv <lilleman@larvit.se>
|
||||
- *maintainer
|
||||
private_key: "{{ .Env.AUR_KEY }}"
|
||||
git_url: ssh://aur@aur.archlinux.org/fejkdata-bin.git
|
||||
commit_author:
|
||||
|
||||
@@ -26,23 +26,24 @@ def request(path: str, data: dict | None = None):
|
||||
return json.load(resp)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
def publish() -> tuple[int, str | None]:
|
||||
"""Publish the release, returning the exit code and the tag it published, if any."""
|
||||
with open("CHANGELOG.md", encoding="utf-8") as f:
|
||||
top = HEADING.search(f.read())
|
||||
if top is None:
|
||||
print("CHANGELOG.md has no `## [...]` heading", file=sys.stderr)
|
||||
return 1
|
||||
return 1, None
|
||||
version, body = top.group(1), top.group(2).strip()
|
||||
if version == "Unreleased":
|
||||
print("top heading is Unreleased; nothing to publish")
|
||||
return 0
|
||||
return 0, None
|
||||
if not re.fullmatch(r"\d+\.\d+\.\d+", version):
|
||||
print(f"top heading `[{version}]` is neither Unreleased nor X.Y.Z", file=sys.stderr)
|
||||
return 1
|
||||
return 1, None
|
||||
tag = f"v{version}"
|
||||
try:
|
||||
print(f"{tag} already published: {request(f'releases/tags/{tag}')['html_url']}")
|
||||
return 0
|
||||
return 0, None
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code != 404:
|
||||
raise
|
||||
@@ -53,15 +54,21 @@ def main() -> int:
|
||||
at = request(f"git/tags/{at['sha']}")["object"]
|
||||
if at["sha"] != sha:
|
||||
print(f"{tag} exists at {at['sha']}, not {sha}; the version is burnt, bump the heading", file=sys.stderr)
|
||||
return 1
|
||||
return 1, None
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code != 404:
|
||||
raise
|
||||
release = request("releases", {"body": body, "name": tag, "tag_name": tag, "target_commitish": sha})
|
||||
print(release["html_url"])
|
||||
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as f:
|
||||
f.write(f"tag={tag}\n")
|
||||
return 0
|
||||
return 0, tag
|
||||
|
||||
|
||||
def main() -> int:
|
||||
code, tag = publish()
|
||||
if tag:
|
||||
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as f:
|
||||
f.write(f"tag={tag}\n")
|
||||
return code
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -25,8 +25,7 @@ class TagGuard(unittest.TestCase):
|
||||
self.addCleanup(os.chdir, cwd)
|
||||
with open("CHANGELOG.md", "w", encoding="utf-8") as f:
|
||||
f.write("# Changelog\n\n## [1.2.3]\n\n- A change.\n")
|
||||
open("output", "w").close()
|
||||
env = mock.patch.dict(os.environ, {"SHA": SHA, "GITHUB_OUTPUT": os.path.abspath("output")})
|
||||
env = mock.patch.dict(os.environ, {"SHA": SHA})
|
||||
env.start()
|
||||
self.addCleanup(env.stop)
|
||||
|
||||
@@ -44,13 +43,9 @@ class TagGuard(unittest.TestCase):
|
||||
|
||||
with mock.patch.object(publish_release, "request", request), \
|
||||
redirect_stdout(io.StringIO()), redirect_stderr(io.StringIO()):
|
||||
code = publish_release.main()
|
||||
code, self.tag = publish_release.publish()
|
||||
return code, created
|
||||
|
||||
def output(self):
|
||||
with open("output", encoding="utf-8") as f:
|
||||
return f.read()
|
||||
|
||||
def test_a_tag_at_another_commit_publishes_nothing(self):
|
||||
code, created = self.publish({"git/ref/tags/v1.2.3": {"object": {"sha": OTHER, "type": "commit"}}})
|
||||
self.assertEqual((code, created), (1, []))
|
||||
@@ -73,11 +68,11 @@ class TagGuard(unittest.TestCase):
|
||||
code, created = self.publish({})
|
||||
self.assertEqual(code, 0)
|
||||
self.assertEqual(created, [{"body": "- A change.", "name": "v1.2.3", "tag_name": "v1.2.3", "target_commitish": SHA}])
|
||||
self.assertEqual(self.output(), "tag=v1.2.3\n")
|
||||
self.assertEqual(self.tag, "v1.2.3")
|
||||
|
||||
def test_a_published_release_publishes_nothing(self):
|
||||
code, created = self.publish({"releases/tags/v1.2.3": {"html_url": "https://forge.example/release"}})
|
||||
self.assertEqual((code, created, self.output()), (0, [], ""))
|
||||
self.assertEqual((code, created, self.tag), (0, [], None))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user