|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright (c) nexB Inc. and others. All rights reserved. |
| 4 | +# http://nexb.com and https://github.com/nexB/scancode-toolkit/ |
| 5 | +# The ScanCode software is licensed under the Apache License version 2.0. |
| 6 | +# Data generated with ScanCode require an acknowledgment. |
| 7 | +# ScanCode is a trademark of nexB Inc. |
| 8 | +# |
| 9 | +# You may not use this software except in compliance with the License. |
| 10 | +# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 |
| 11 | +# Unless required by applicable law or agreed to in writing, software distributed |
| 12 | +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 13 | +# CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 14 | +# specific language governing permissions and limitations under the License. |
| 15 | +# |
| 16 | +# When you publish or redistribute any data created with ScanCode or any ScanCode |
| 17 | +# derivative work, you must accompany this data with the following acknowledgment: |
| 18 | +# |
| 19 | +# Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 20 | +# OR CONDITIONS OF ANY KIND, either express or implied. No content created from |
| 21 | +# ScanCode should be considered or used as legal advice. Consult an Attorney |
| 22 | +# for any legal advice. |
| 23 | +# ScanCode is a free software code scanning tool from nexB Inc. and others. |
| 24 | +# Visit https://github.com/nexB/scancode-toolkit/ for support and download. |
| 25 | + |
| 26 | +from __future__ import absolute_import |
| 27 | +from __future__ import print_function |
| 28 | + |
| 29 | +import argparse |
| 30 | +from commoncode.fileutils import resource_iter |
| 31 | +import fnmatch |
| 32 | +import os |
| 33 | +import subprocess |
| 34 | +import sys |
| 35 | + |
| 36 | + |
| 37 | +def release_asset(token, tag, repo, body, user, limit, file): |
| 38 | + """ |
| 39 | + Release .whl,.ABOUT,.NOTICE,.LICENSE to github repository from |
| 40 | + given directory. |
| 41 | + """ |
| 42 | + |
| 43 | + cwd = os.getcwd() |
| 44 | + os.environ["GITHUB_TOKEN"] = token |
| 45 | + thirdparty = list(resource_iter(file, with_dirs=False)) |
| 46 | + # FIXME this code is for py 3.6 and later we will update for all version |
| 47 | + dependencies = [ |
| 48 | + files |
| 49 | + for files in thirdparty |
| 50 | + if fnmatch.fnmatchcase(files, "*py3*") |
| 51 | + or fnmatch.fnmatchcase(files, "*cp36*") |
| 52 | + or ( |
| 53 | + fnmatch.fnmatchcase(files, "*tar.gz*") |
| 54 | + and not fnmatch.fnmatchcase(files, "*py2-ipaddress-3.4.1.tar.gz*") |
| 55 | + ) |
| 56 | + ] |
| 57 | + for deps in dependencies: |
| 58 | + print(deps) |
| 59 | + subprocess.run( |
| 60 | + [ |
| 61 | + "python3", |
| 62 | + "-m", |
| 63 | + "github_release_retry.github_release_retry", |
| 64 | + "--user", |
| 65 | + user, |
| 66 | + "--repo", |
| 67 | + repo, |
| 68 | + "--tag_name", |
| 69 | + tag, |
| 70 | + "--body_string", |
| 71 | + body, |
| 72 | + "--retry_limit", |
| 73 | + limit, |
| 74 | + deps, |
| 75 | + ] |
| 76 | + ) |
| 77 | + |
| 78 | + |
| 79 | +def main_with_args(args: str) -> None: |
| 80 | + parser = argparse.ArgumentParser( |
| 81 | + description="""Creates a GitHub release (if it does not already exist) and uploads files to the release. |
| 82 | +Please pass the GITHUB_TOKEN as an argument. |
| 83 | +EXAMPLE: |
| 84 | +github-release-asset \\ |
| 85 | + --user Abhishek-Dev09 \\ |
| 86 | + --repo thirdparty \\ |
| 87 | + --tag_name v1.0 \\ |
| 88 | + --body_string "Python 3.6 wheels" \\ |
| 89 | + hello-world.zip RELEASE_NOTES.txt |
| 90 | +""", |
| 91 | + formatter_class=argparse.RawDescriptionHelpFormatter, |
| 92 | + ) |
| 93 | + |
| 94 | + parser.add_argument( |
| 95 | + "--user", |
| 96 | + help="Required: The GitHub username or organization name in which the repo resides. ", |
| 97 | + type=str, |
| 98 | + required=True, |
| 99 | + ) |
| 100 | + |
| 101 | + parser.add_argument( |
| 102 | + "--token", |
| 103 | + help="Required: The Github token is required to acess the repository where you want to upload . ", |
| 104 | + type=str, |
| 105 | + required=True, |
| 106 | + ) |
| 107 | + |
| 108 | + parser.add_argument( |
| 109 | + "--repo", |
| 110 | + help="Required: The GitHub repo name in which to make the release. ", |
| 111 | + type=str, |
| 112 | + required=True, |
| 113 | + ) |
| 114 | + |
| 115 | + parser.add_argument( |
| 116 | + "--tag_name", |
| 117 | + help="Required: The name of the tag to create or use. ", |
| 118 | + type=str, |
| 119 | + required=True, |
| 120 | + ) |
| 121 | + |
| 122 | + parser.add_argument( |
| 123 | + "--body_string", |
| 124 | + help="Required (or use --body_file): Text describing the release. Ignored if the release already exists.", |
| 125 | + type=str, |
| 126 | + ) |
| 127 | + |
| 128 | + parser.add_argument( |
| 129 | + "--retry_limit", |
| 130 | + help="The number of times to retry creating/getting the release and/or uploading each file. ", |
| 131 | + type=str, |
| 132 | + default="10", |
| 133 | + ) |
| 134 | + |
| 135 | + parser.add_argument( |
| 136 | + "--files", type=str, help="The files to upload to the release.", |
| 137 | + ) |
| 138 | + |
| 139 | + args = parser.parse_args() |
| 140 | + |
| 141 | + token = args.token |
| 142 | + tag = args.tag_name |
| 143 | + repo = args.repo |
| 144 | + body = args.body_string |
| 145 | + user = args.user |
| 146 | + limit = args.retry_limit |
| 147 | + file = args.files |
| 148 | + |
| 149 | + release_asset(token, tag, repo, body, user, limit, file) |
| 150 | + |
| 151 | + |
| 152 | +def main() -> None: |
| 153 | + main_with_args(sys.argv[1:]) |
| 154 | + |
| 155 | + |
| 156 | +if __name__ == "__main__": |
| 157 | + main() |
0 commit comments