Skip to content

Commit 9634fcf

Browse files
committed
release: repair rules_go@0.63.0 registry module version
1 parent c8d5986 commit 9634fcf

2 files changed

Lines changed: 127 additions & 0 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ on:
1919
description: git tag being released
2020
required: true
2121
type: string
22+
repair_registry:
23+
description: Repair the existing rules_go registry pull request
24+
required: false
25+
default: false
26+
type: boolean
2227
jobs:
2328
release:
29+
if: ${{ !inputs.repair_registry }}
2430
uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v7.7.0
2531
permissions:
2632
actions: read
@@ -60,3 +66,44 @@ jobs:
6066
- uses: softprops/action-gh-release@718ea10b132b3b2eba29c1007bb80653f286566b # v3.0.1
6167
with:
6268
tag_name: ${{ inputs.tag_name }}
69+
repair_registry:
70+
if: ${{ github.event_name == 'workflow_dispatch' && inputs.repair_registry }}
71+
runs-on: ubuntu-latest
72+
permissions:
73+
contents: read
74+
steps:
75+
- name: Checkout recovery workflow
76+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
77+
with:
78+
path: recovery
79+
persist-credentials: false
80+
- name: Checkout released rules_go source
81+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
82+
with:
83+
ref: ${{ inputs.tag_name }}
84+
path: source
85+
persist-credentials: false
86+
- name: Checkout existing registry pull request
87+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
88+
with:
89+
repository: bazel-contrib/bazel-central-registry
90+
ref: rules_go-v0.63.0
91+
path: registry
92+
token: ${{ secrets.publish_token || secrets.BCR_PUBLISH_TOKEN }}
93+
- name: Correct rules_go registry entry
94+
run: |
95+
python3 recovery/.github/workflows/repair_bcr_registry.py \
96+
--source source \
97+
--registry registry \
98+
--tag '${{ inputs.tag_name }}'
99+
git -C source apply --check \
100+
"$GITHUB_WORKSPACE/registry/modules/rules_go/0.63.0/patches/module_dot_bazel_version.patch"
101+
git -C registry diff --check
102+
- name: Update existing registry pull request
103+
run: |
104+
git -C registry add -A modules/rules_go/0.63.0
105+
git -C registry \
106+
-c user.name='David Zbarsky' \
107+
-c user.email='dzbarsky@gmail.com' \
108+
commit -m 'Fix rules_go@0.63.0 module version'
109+
git -C registry push origin HEAD:refs/heads/rules_go-v0.63.0
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import base64
5+
import hashlib
6+
import json
7+
from pathlib import Path
8+
9+
10+
def main() -> None:
11+
parser = argparse.ArgumentParser()
12+
parser.add_argument("--source", type=Path, required=True)
13+
parser.add_argument("--registry", type=Path, required=True)
14+
parser.add_argument("--tag", required=True)
15+
args = parser.parse_args()
16+
17+
if args.tag != "v0.63.0":
18+
raise ValueError(f"unexpected release tag: {args.tag}")
19+
20+
version = args.tag.removeprefix("v")
21+
module_directory = args.registry / "modules" / "rules_go" / version
22+
source_module = (args.source / "MODULE.bazel").read_text()
23+
marker = ' repo_name = "io_bazel_rules_go",\n'
24+
if source_module.count(marker) != 1:
25+
raise ValueError("could not identify the rules_go module declaration")
26+
27+
module_block = source_module.partition("\n)\n")[0]
28+
if " version = " in module_block:
29+
raise ValueError("the tagged rules_go module already declares a version")
30+
31+
corrected_module = source_module.replace(
32+
marker, marker + f' version = "{version}",\n', 1
33+
)
34+
expected_dependency = 'bazel_dep(name = "bazel_features", version = "1.36.0",'
35+
if expected_dependency not in corrected_module:
36+
raise ValueError("the released bazel_features dependency is unexpected")
37+
(module_directory / "MODULE.bazel").write_text(corrected_module)
38+
39+
previous_patch = (
40+
args.registry
41+
/ "modules"
42+
/ "rules_go"
43+
/ "0.62.0"
44+
/ "patches"
45+
/ "module_dot_bazel_version.patch"
46+
).read_text()
47+
if previous_patch.count('"0.62.0"') != 1:
48+
raise ValueError("the previous module-version patch is unexpected")
49+
50+
corrected_patch = previous_patch.replace('"0.62.0"', f'"{version}"', 1)
51+
patch_path = module_directory / "patches" / "module_dot_bazel_version.patch"
52+
patch_path.write_text(corrected_patch)
53+
54+
patch_digest = hashlib.sha256(patch_path.read_bytes()).digest()
55+
patch_integrity = "sha256-" + base64.b64encode(patch_digest).decode()
56+
expected_patch_integrity = "sha256-78UHBUbfVo/yuxxWI+c+Irs0ujETcjVVhr7V76rAkVg="
57+
if patch_integrity != expected_patch_integrity:
58+
raise ValueError(f"unexpected module-version patch integrity: {patch_integrity}")
59+
60+
source_json_path = module_directory / "source.json"
61+
source_json = json.loads(source_json_path.read_text())
62+
expected_archive_integrity = "sha256-w+JTI3EJqy4qjTywdWiLmKbm/OQ9hJhJZI6OOoTyDW8="
63+
if source_json["integrity"] != expected_archive_integrity:
64+
raise ValueError("the published release archive integrity changed")
65+
source_json["patches"]["module_dot_bazel_version.patch"] = patch_integrity
66+
source_json_path.write_text(json.dumps(source_json, indent=4) + "\n")
67+
68+
attestations_path = module_directory / "attestations.json"
69+
if not attestations_path.is_file():
70+
raise ValueError("the invalid registry attestation manifest is missing")
71+
attestations_path.unlink()
72+
73+
print(f"Corrected rules_go module version: {version}")
74+
print(f"Preserved bazel_features version: 1.36.0")
75+
print(f"Preserved archive integrity: {expected_archive_integrity}")
76+
print(f"Updated module patch integrity: {patch_integrity}")
77+
78+
79+
if __name__ == "__main__":
80+
main()

0 commit comments

Comments
 (0)