1*06f32e7eSjoerg#!/usr/bin/env python3 2*06f32e7eSjoerg# ===-- github-upload-release.py ------------------------------------------===# 3*06f32e7eSjoerg# 4*06f32e7eSjoerg# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*06f32e7eSjoerg# See https://llvm.org/LICENSE.txt for license information. 6*06f32e7eSjoerg# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*06f32e7eSjoerg# 8*06f32e7eSjoerg#===------------------------------------------------------------------------===# 9*06f32e7eSjoerg# 10*06f32e7eSjoerg# Create and manage releases in the llvm github project. 11*06f32e7eSjoerg# 12*06f32e7eSjoerg# This script requires python3 and the PyGithub module. 13*06f32e7eSjoerg# 14*06f32e7eSjoerg# Example Usage: 15*06f32e7eSjoerg# 16*06f32e7eSjoerg# You will need to obtain a personal access token for your github account in 17*06f32e7eSjoerg# order to use this script. Instructions for doing this can be found here: 18*06f32e7eSjoerg# https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line 19*06f32e7eSjoerg# 20*06f32e7eSjoerg# Create a new release from an existing tag: 21*06f32e7eSjoerg# ./github-upload-release.py --token $github_token --release 8.0.1-rc4 create 22*06f32e7eSjoerg# 23*06f32e7eSjoerg# Upload files for a release 24*06f32e7eSjoerg# ./github-upload-release.py --token $github_token --release 8.0.1-rc4 upload --files llvm-8.0.1rc4.src.tar.xz 25*06f32e7eSjoerg# 26*06f32e7eSjoerg# You can upload as many files as you want at a time and use wildcards e.g. 27*06f32e7eSjoerg# ./github-upload-release.py --token $github_token --release 8.0.1-rc4 upload --files *.src.* 28*06f32e7eSjoerg#===------------------------------------------------------------------------===# 29*06f32e7eSjoerg 30*06f32e7eSjoerg 31*06f32e7eSjoergimport argparse 32*06f32e7eSjoergimport github 33*06f32e7eSjoerg 34*06f32e7eSjoergdef create_release(repo, release, tag = None, name = None, message = None): 35*06f32e7eSjoerg if not tag: 36*06f32e7eSjoerg tag = 'llvmorg-{}'.format(release) 37*06f32e7eSjoerg 38*06f32e7eSjoerg if not name: 39*06f32e7eSjoerg name = 'LLVM {}'.format(release) 40*06f32e7eSjoerg 41*06f32e7eSjoerg if not message: 42*06f32e7eSjoerg message = 'LLVM {} Release'.format(release) 43*06f32e7eSjoerg 44*06f32e7eSjoerg prerelease = True if "rc" in release else False 45*06f32e7eSjoerg 46*06f32e7eSjoerg repo.create_git_release(tag = tag, name = name, message = message, 47*06f32e7eSjoerg prerelease = prerelease) 48*06f32e7eSjoerg 49*06f32e7eSjoergdef upload_files(repo, release, files): 50*06f32e7eSjoerg release = repo.get_release('llvmorg-{}'.format(release)) 51*06f32e7eSjoerg for f in files: 52*06f32e7eSjoerg print('Uploading {}'.format(f)) 53*06f32e7eSjoerg release.upload_asset(f) 54*06f32e7eSjoerg print("Done") 55*06f32e7eSjoerg 56*06f32e7eSjoerg 57*06f32e7eSjoerg 58*06f32e7eSjoergparser = argparse.ArgumentParser() 59*06f32e7eSjoergparser.add_argument('command', type=str, choices=['create', 'upload']) 60*06f32e7eSjoerg 61*06f32e7eSjoerg# All args 62*06f32e7eSjoergparser.add_argument('--token', type=str) 63*06f32e7eSjoergparser.add_argument('--release', type=str) 64*06f32e7eSjoerg 65*06f32e7eSjoerg# Upload args 66*06f32e7eSjoergparser.add_argument('--files', nargs='+', type=str) 67*06f32e7eSjoerg 68*06f32e7eSjoerg 69*06f32e7eSjoergargs = parser.parse_args() 70*06f32e7eSjoerg 71*06f32e7eSjoerggithub = github.Github(args.token) 72*06f32e7eSjoergllvm_repo = github.get_organization('llvm').get_repo('llvm-project') 73*06f32e7eSjoerg 74*06f32e7eSjoergif args.command == 'create': 75*06f32e7eSjoerg create_release(llvm_repo, args.release) 76*06f32e7eSjoergif args.command == 'upload': 77*06f32e7eSjoerg upload_files(llvm_repo, args.release, args.files) 78