Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 142 additions & 43 deletions llvm/utils/release/github-upload-release.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,103 @@
from textwrap import dedent


# This is a tuple of sections of download links. Each section then contains
# an entry for each line in that section. Each line entry contains:
# * A unique tag to go in "<!-- <tag>" so we can find it later in the release
# message.
# * A format string for the line's content.
# * Filenames to substitute into the format string. Before substitution into
# the format string, file names will have the base download URL prepended to
# them and 'release' replaced with the release version.
#
# Between each set of links, an empty line will be added.
#
# This data is used to generate the links for the release message, and by
# uncomment_download_links to verify whether for any given link line, all files
# linked to are present in the release's assets.
release_links = (
(
(
"LINUX_X86",
"* [Linux x86_64]({0}) ([signature]({1}))",
"LLVM-{release}-Linux-X64.tar.xz",
"LLVM-{release}-Linux-X64.tar.xz.jsonl",
),
(
"LINUX_ARM64",
"* [Linux Arm64]({0}) ([signature]({1}))",
"LLVM-{release}-Linux-ARM64.tar.xz",
"LLVM-{release}-Linux-ARM64.tar.xz.jsonl",
),
(
"LINUX_ARMV7A",
"* [Linux Armv7-a]({0}) ([signature]({1}))",
"clang+llvm-{release}-armv7a-linux-gnueabihf.tar.gz",
"clang+llvm-{release}-armv7a-linux-gnueabihf.tar.gz.sig",
),
),
(
(
"MACOS_ARM64",
"* [macOS Apple Silicon]({0}) (ARM64) ([signature]({1}))",
"LLVM-{release}-macOS-ARM64.tar.xz",
"LLVM-{release}-macOS-ARM64.tar.xz.jsonl",
),
(
"MACOS_X86",
"* [macOS Intel]({0}) (x86-64) ([signature]({1})])",
"LLVM-{release}-macOS-X64.tar.xz",
"LLVM-{release}-macOS-X64.tar.xz.jsonl",
),
),
(
(
"WINDOWS_X64",
"* Windows x64 (64-bit): [installer]({0}) ([signature]({1})), [archive]({2}) ([signature]({3}))",
"LLVM-{release}-win64.exe",
"LLVM-{release}-win64.exe.sig",
"clang+llvm-{release}-x86_64-pc-windows-msvc.tar.xz",
"clang+llvm-{release}-x86_64-pc-windows-msvc.tar.xz.sig",
),
(
"WINDOWS_X86",
"* Windows x86 (32-bit): [installer]({0}) ([signature]({1}))",
"LLVM-{release}-win32.exe",
"LLVM-{release}-win32.exe.sig",
),
(
"WINDOWS_ARM64",
"* Windows on Arm (ARM64): [installer]({0}) ([signature]({1})), [archive]({2}) ([signature]({3}))",
"LLVM-{release}-woa64.exe",
"LLVM-{release}-woa64.exe.sig",
"clang+llvm-{release}-aarch64-pc-windows-msvc.tar.xz",
"clang+llvm-{release}-aarch64-pc-windows-msvc.tar.xz.sig",
),
),
)


def generate_download_links(release):
base_url = (
f"https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/"
)
markdown_lines = []

for section in release_links:
for line in section:
comment_tag, format_string, *files = line
markdown_line = f"<!-- {comment_tag} "
files = [base_url + f.format(release=release) for f in files]
markdown_line += format_string.format(*files)
markdown_line += " -->"
markdown_lines.append(markdown_line)

# Blank line between each section.
markdown_lines.append("")

return "\n".join(markdown_lines)


def create_release(repo, release, tag=None, name=None, message=None):
if not tag:
tag = "llvmorg-{}".format(release)
Expand All @@ -45,33 +142,15 @@ def create_release(repo, release, tag=None, name=None, message=None):
# Note that these lines are not length limited because if we do so, GitHub
# assumes that should be how it is laid out on the page. We want GitHub to
# do the reflowing for us instead.
#
# Once all the atuomatic binary builds have completed, the HTML comments
# with UPPERCASE markers in them will be removed to reveal the download
# links later. Other lines are surrounded in <!-- --> for release uploaders
# to manually uncomment when they upload that package.
download_links = generate_download_links(release)
message = dedent(
"""\
f"""\
## LLVM {release} Release

<!-- AUTOMATIC_DOWNLOAD_LINKS_BEGIN
* [Linux x86_64](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-Linux-X64.tar.xz) ([signature](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-Linux-X64.tar.xz.jsonl))
* [Linux Arm64](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-Linux-ARM64.tar.xz) ([signature](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-Linux-ARM64.tar.xz.jsonl))
AUTOMATIC_DOWNLOAD_LINKS_END -->
<!-- * [Linux Armv7-a](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/clang+llvm-{release}-armv7a-linux-gnueabihf.tar.gz) ([signature](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/clang+llvm-{release}-armv7a-linux-gnueabihf.tar.gz.sig)) -->

<!-- AUTOMATIC_DOWNLOAD_LINKS_BEGIN
* [macOS Apple Silicon](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-macOS-ARM64.tar.xz) (ARM64) ([signature](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-macOS-ARM64.tar.xz.jsonl))
* [macOS Intel](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-macOS-X64.tar.xz) (x86-64) ([signature](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-macOS-X64.tar.xz.jsonl))
AUTOMATIC_DOWNLOAD_LINKS_END -->

<!-- * Windows x64 (64-bit): [installer](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-win64.exe) ([signature](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-win64.exe.sig)), [archive](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/clang+llvm-{release}-x86_64-pc-windows-msvc.tar.xz) ([signature](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/clang+llvm-{release}-x86_64-pc-windows-msvc.tar.xz.sig)) -->
<!-- * Windows x86 (32-bit): [installer](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-win32.exe) ([signature](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-win32.exe.sig)) -->
<!-- * Windows on Arm (ARM64): [installer](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-woa64.exe) ([signature](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/LLVM-{release}-woa64.exe.sig)), [archive](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/clang+llvm-{release}-aarch64-pc-windows-msvc.tar.xz) ([signature](https://github.com/llvm/llvm-project/releases/download/llvmorg-{release}/clang+llvm-{release}-aarch64-pc-windows-msvc.tar.xz.sig)) -->
{download_links}
Download links for common platforms will appear above, if they are available. Check the full list of release packages at the bottom of this release page if you do not find a link above.

Download links will appear here once builds have completed. <!-- AUTOMATIC_DOWNLOAD_LINKS_PLACEHOLDER -->

For any other variants of platform and architecture, check the full list of release packages at the bottom of this release page. If you do not find a release package for your platform, you may be able to find a community built package on the LLVM Discourse forum thread for this release. Remember that these are built by volunteers and may not always be available. If you rely on a platform or configuration that is not one of the defaults, we suggest you use the binaries that your platform provides, or build your own release packages.
If you do not find a release package for your platform, you may be able to find a community built package on the LLVM Discourse forum thread for this release. Remember that these are built by volunteers and may not always be available. If you rely on a platform or configuration that is not one of the defaults, we suggest you use the binaries that your platform provides, or build your own release packages.

## Package Types

Expand Down Expand Up @@ -100,7 +179,7 @@ def create_release(repo, release, tag=None, name=None, message=None):
$ gh attestation verify --repo llvm/llvm-project <package file name> --bundle <package file name>.jsonl
(using attestation file on disk)
```"""
).format(release=release)
)

prerelease = True if "rc" in release else False

Expand All @@ -115,28 +194,48 @@ def upload_files(repo, release, files):
print("Done")


def uncomment_download_links(repo, release):
release = repo.get_release("llvmorg-{}".format(release))
def uncomment_download_links(repo, release_version):
release = repo.get_release("llvmorg-{}".format(release_version))

# At this point any automatic builds have finished and if
# they succeeded, uploaded files to the release assets.
release_assets = set([a.name for a in release.assets])
print("Found release assets: ", release_assets)

new_message = []
to_remove = [
"AUTOMATIC_DOWNLOAD_LINKS_BEGIN",
"AUTOMATIC_DOWNLOAD_LINKS_END",
"AUTOMATIC_DOWNLOAD_LINKS_PLACEHOLDER",
]
modified = False
for line in release.body.splitlines():
for comment in to_remove:
if comment in line:
break
else:
new_message.append(line)

release.update_release(
name=release.title,
message="\n".join(new_message),
draft=release.draft,
prerelease=release.prerelease,
)
# All hidden download links are of the form:
# <!-- <some unique tag> <markdown content> -->
if line.startswith("<!--"):
for section in release_links:
for comment_tag, _, *files in section:
if comment_tag in line:
print(f'Found link line "{comment_tag}":')
files = set([f.format(release=release_version) for f in files])
print(" Files required:", files)
if files.issubset(release_assets):
print(" All files present, revealing link line.")
line.replace("<!--", "").replace(comment_tag, "").replace(
"-->", ""
).strip()
modified = True
else:
print(
" These files are not present:",
files.difference(release_assets),
)
print(" Link line will remain hidden.")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaving the prints in for logging purposes, they're not leftover debug prints.

Some example output:

Found release assets:  {'clang+llvm-vX.Y.Z-1-aarch64-pc-windows-msvc.tar.xz', 'LLVM-vX.Y.Z-1-Linux-X64.tar.xz.jsonl', 'LLVM-vX.Y.Z-1-Linux-X64.tar.xz'}
Found link line "LINUX_X86":
  Files required: {'LLVM-vX.Y.Z-1-Linux-X64.tar.xz.jsonl', 'LLVM-vX.Y.Z-1-Linux-X64.tar.xz'}
  All files present, revealing link line.
<...>
Found link line "WINDOWS_ARM64":
  Files required: {'clang+llvm-vX.Y.Z-1-aarch64-pc-windows-msvc.tar.xz.sig', 'LLVM-vX.Y.Z-1-woa64.exe', 'LLVM-vX.Y.Z-1-woa64.exe.sig', 'clang+llvm-vX.Y.Z-1-aarch64-pc-windows-msvc.tar.xz'}
  These files are not present: {'clang+llvm-vX.Y.Z-1-aarch64-pc-windows-msvc.tar.xz.sig', 'LLVM-vX.Y.Z-1-woa64.exe', 'LLVM-vX.Y.Z-1-woa64.exe.sig'}
  Link line will remain hidden.

Either this will never go wrong and no one will see any of it, or, more likely, it will, and this will be helpful to have in the log.


new_message.append(line)

if modified:
release.update_release(
name=release.title,
message="\n".join(new_message),
draft=release.draft,
prerelease=release.prerelease,
)


parser = argparse.ArgumentParser()
Expand Down
Loading