brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.8 KiB · 893cda0 Raw
191 lines · python
1#!/usr/bin/env python32# ===-- github-upload-release.py  ------------------------------------------===#3#4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5# See https://llvm.org/LICENSE.txt for license information.6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7#8# ===------------------------------------------------------------------------===#9#10# Create and manage releases in the llvm github project.11#12# This script requires python3 and the PyGithub module.13 14# Requirements and lockfiles can be found in llvm/utils/git/requirements.upload_release.txt.in15# and llvm/utils/git/requirements.upload_release.txt16#17# Example Usage:18#19# You will need to obtain a personal access token for your github account in20# order to use this script.  Instructions for doing this can be found here:21# https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line22#23# Create a new release from an existing tag:24# ./github-upload-release.py --token $github_token --release 8.0.1-rc4 create25#26# Upload files for a release27# ./github-upload-release.py --token $github_token --release 8.0.1-rc4 upload --files llvm-8.0.1rc4.src.tar.xz28#29# You can upload as many files as you want at a time and use wildcards e.g.30# ./github-upload-release.py --token $github_token --release 8.0.1-rc4 upload --files *.src.*31# ===------------------------------------------------------------------------===#32 33 34import argparse35import github36import sys37from textwrap import dedent38 39 40def create_release(repo, release, tag=None, name=None, message=None):41    if not tag:42        tag = "llvmorg-{}".format(release)43 44    if not name:45        name = "LLVM {}".format(release)46 47    if not message:48        # Note that these lines are not length limited because if we do so, GitHub49        # assumes that should be how it is laid out on the page. We want GitHub to50        # do the reflowing for us instead.51        #52        # Once all the atuomatic binary builds have completed, the HTML comments53        # with UPPERCASE markers in them will be removed to reveal the download54        # links later. Other lines are surrounded in <!-- --> for release uploaders55        # to manually uncomment when they upload that package.56        message = dedent(57            """\58## LLVM {release} Release59 60<!-- AUTOMATIC_DOWNLOAD_LINKS_BEGIN61* [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))62* [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))63AUTOMATIC_DOWNLOAD_LINKS_END -->64<!-- * [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)) -->65 66<!-- AUTOMATIC_DOWNLOAD_LINKS_BEGIN67* [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))68* [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))69AUTOMATIC_DOWNLOAD_LINKS_END -->70 71<!-- * 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)) -->72<!-- * 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)) -->73<!-- * 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)) -->74 75Download links will appear here once builds have completed. <!-- AUTOMATIC_DOWNLOAD_LINKS_PLACEHOLDER -->76 77For 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.78 79## Package Types80 81Each platform has one binary release package. The file name starts with either `LLVM-` or `clang+llvm-` and ends with the platform's name. For example, `LLVM-{release}-Linux-ARM64.tar.xz` contains LLVM binaries for Arm64 Linux.82 83Except for Windows. Where `LLVM-*.exe` is an installer intended for using LLVM as a toolchain and the archive `clang+llvm-` contains the contents of the installer, plus libraries and tools not normally used in a toolchain. You most likely want the `LLVM-` installer, unless you are developing software which itself uses LLVM, in which case choose `clang+llvm-`.84 85In addition, source archives are available:86* `<sub-project>-{release}.src.tar.xz` are archives of the sources of specific sub-projects of `llvm-project` (except for `test-suite` which is an archive of the [LLVM Test Suite](https://github.com/llvm/llvm-test-suite)).87* To get all the `llvm-project` source code for this release, choose `llvm-project-{release}.src.tar.xz`.88 89## Verifying Packages90 91All packages come with a matching `.sig` or `.jsonl` file. You should use these to verify the integrity of the packages.92 93If it has a `.sig` file, it should have been signed by the release managers using GPG. Download the keys from the [LLVM website](https://releases.llvm.org/release-keys.asc), import them into your keyring and use them to verify the file:94```95$ gpg --import release-keys.asc96$ gpg --verify <package file name>.sig <package file name>97```98 99If it has a `.jsonl` file, use [gh](https://cli.github.com/manual/gh_attestation_verify) to verify the package:100```101$ gh attestation verify --repo llvm/llvm-project <package file name>102(if you are able to connect to GitHub)103$ gh attestation verify --repo llvm/llvm-project <package file name> --bundle <package file name>.jsonl104(using attestation file on disk)105```"""106        ).format(release=release)107 108    prerelease = True if "rc" in release else False109 110    repo.create_git_release(tag=tag, name=name, message=message, prerelease=prerelease)111 112 113def upload_files(repo, release, files):114    release = repo.get_release("llvmorg-{}".format(release))115    for f in files:116        print("Uploading {}".format(f))117        release.upload_asset(f)118        print("Done")119 120 121def uncomment_download_links(repo, release):122    release = repo.get_release("llvmorg-{}".format(release))123 124    new_message = []125    to_remove = [126        "AUTOMATIC_DOWNLOAD_LINKS_BEGIN",127        "AUTOMATIC_DOWNLOAD_LINKS_END",128        "AUTOMATIC_DOWNLOAD_LINKS_PLACEHOLDER",129    ]130    for line in release.body.splitlines():131        for comment in to_remove:132            if comment in line:133                break134        else:135            new_message.append(line)136 137    release.update_release(138        name=release.title,139        message="\n".join(new_message),140        draft=release.draft,141        prerelease=release.prerelease,142    )143 144 145parser = argparse.ArgumentParser()146parser.add_argument(147    "command",148    type=str,149    choices=["create", "upload", "check-permissions", "uncomment_download_links"],150)151 152# All args153parser.add_argument("--token", type=str)154parser.add_argument("--release", type=str)155parser.add_argument("--user", type=str)156parser.add_argument("--user-token", type=str)157 158# Upload args159parser.add_argument("--files", nargs="+", type=str)160 161args = parser.parse_args()162 163gh = github.Github(args.token)164llvm_org = gh.get_organization("llvm")165llvm_repo = llvm_org.get_repo("llvm-project")166 167if args.user:168    if not args.user_token:169        print("--user-token option required when --user is used")170        sys.exit(1)171    # Validate that this user is allowed to modify releases.172    user = gh.get_user(args.user)173    team = (174        github.Github(args.user_token)175        .get_organization("llvm")176        .get_team_by_slug("llvm-release-managers")177    )178    if not team.has_in_members(user):179        print("User {} is not a allowed to modify releases".format(args.user))180        sys.exit(1)181elif args.command == "check-permissions":182    print("--user option required for check-permissions")183    sys.exit(1)184 185if args.command == "create":186    create_release(llvm_repo, args.release)187if args.command == "upload":188    upload_files(llvm_repo, args.release, args.files)189if args.command == "uncomment_download_links":190    uncomment_download_links(llvm_repo, args.release)191