Skip to content

Commit 7e5b9b5

Browse files
author
Jussi Kukkonen
authored
Merge pull request #1979 from lukpueh/verify_release-sign
Add option to sign release artifacts with verify_release
2 parents 6b511c6 + a3d5a37 commit 7e5b9b5

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

docs/RELEASE.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ on GitHub
4444
*An approval resumes the CD workflow to publish the release on PyPI, and to finalize the
4545
GitHub release (removes `-rc` suffix and updates release notes).*
4646

47-
8. `verify_release` may be used again to make sure the PyPI release artifacts match the
48-
local build as well.
47+
8. Run `verify_release` to make sure the PyPI release artifacts match the local build as
48+
well. When called as `verify_release --sign [<key id>]` the script additionally
49+
creates gpg release signatures. When signed by maintainers with a corresponding GPG
50+
fingerprint in the MAINTAINERS.md file, these signature files should be made available on
51+
the GitHub release page under Assets.
4952
9. Announce the release on [#tuf on CNCF Slack](https://cloud-native.slack.com/archives/C8NMD3QJ3)
5053
10. Ensure [POUF 1](https://github.com/theupdateframework/taps/blob/master/POUFs/reference-POUF/pouf1.md),
5154
for the reference implementation, is up-to-date

verify_release

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ def verify_pypi_release(version: str, compare_dir: str) -> bool:
122122
return sorted(same) == [wheel, tar]
123123

124124

125+
def sign_release_artifacts(
126+
version: str, build_dir: str, key_id: str = None
127+
) -> None:
128+
"""Sign built release artifacts with gpg and write signature files to cwd"""
129+
sdist = f"{PYPI_PROJECT}-{version}.tar.gz"
130+
wheel = f"{PYPI_PROJECT}-{version}-py3-none-any.whl"
131+
cmd = ["gpg", "--detach-sign", "--armor"]
132+
133+
if key_id is not None:
134+
cmd += ["--local-user", key_id]
135+
136+
for filename in [sdist, wheel]:
137+
artifact_path = os.path.join(build_dir, filename)
138+
signature_path = f"{filename}.asc"
139+
subprocess.run(
140+
cmd + ["--output", signature_path, artifact_path], check=True
141+
)
142+
assert os.path.exists(signature_path)
143+
144+
125145
def finished(s: str) -> None:
126146
# clear line
127147
sys.stdout.write("\033[K")
@@ -143,6 +163,15 @@ def main() -> int:
143163
dest="skip_pypi",
144164
help="Skip PyPI release check.",
145165
)
166+
parser.add_argument(
167+
"--sign",
168+
nargs="?",
169+
const=True,
170+
metavar="<key id>",
171+
dest="sign",
172+
help="Sign release artifacts with 'gpg'. If no <key id> is passed, the default "
173+
"signing key is used. Resulting '*.asc' files are written to CWD.",
174+
)
146175
args = parser.parse_args()
147176

148177
success = True
@@ -172,15 +201,27 @@ def main() -> int:
172201
# This is expected while build is not reproducible
173202
finished("ERROR: PyPI artifacts do not match built release")
174203
success = False
204+
else:
205+
finished("PyPI artifacts match the built release")
175206

176207
progress("Downloading release from GitHub")
177208
if not verify_github_release(build_version, build_dir):
178209
# This is expected while build is not reproducible
179210
finished("ERROR: GitHub artifacts do not match built release")
180211
success = False
181-
182-
if success:
183-
finished("Github and PyPI artifacts match the built release")
212+
else:
213+
finished("GitHub artifacts match the built release")
214+
215+
# NOTE: 'gpg' might prompt for password or ask if it should override files...
216+
if args.sign:
217+
progress("Signing built release with gpg")
218+
if success:
219+
key_id = args.sign if args.sign is not True else None
220+
221+
sign_release_artifacts(build_version, build_dir, key_id)
222+
finished("Created signatures in cwd (see '*.asc' files)")
223+
else:
224+
finished("WARNING: Skipped signing of non-matching artifacts")
184225

185226
return 0 if success else 1
186227

0 commit comments

Comments
 (0)