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