TobKed commented on a change in pull request #12150: URL: https://github.com/apache/beam/pull/12150#discussion_r457921957
########## File path: release/src/main/scripts/download_github_actions_artifacts.py ########## @@ -0,0 +1,314 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +"""Script for downloading GitHub Actions artifacts from 'Build python wheels' workflow.""" +import argparse +import itertools +import os +import pprint +import shutil +import sys +import tempfile +import time +import zipfile + +import dateutil.parser +import requests + +GH_API_URL_WORKLOW_FMT = "https://api.github.com/repos/{repo_url}/actions/workflows/build_wheels.yml" +GH_API_URL_WORKFLOW_RUNS_FMT = "https://api.github.com/repos/{repo_url}/actions/workflows/{workflow_id}/runs" +GH_API_URL_WORKFLOW_RUN_FMT = "https://api.github.com/repos/{repo_url}/actions/runs/{run_id}" +GH_WEB_URL_WORKLOW_RUN_FMT = "https://github.com/{repo_url}/actions/runs/{run_id}" + + +def parse_arguments(): + """ + Gets all neccessary data from the user by parsing arguments or asking for input. + Return: github_token, user_github_id, repo_url, release_branch, release_commit, artifacts_dir + """ + parser = argparse.ArgumentParser( + description= + "Script for downloading GitHub Actions artifacts from 'Build python wheels' workflow." + ) + parser.add_argument("--github-user", required=True) + parser.add_argument("--repo-url", required=True) + parser.add_argument("--release-branch", required=True) + parser.add_argument("--release-commit", required=True) + parser.add_argument("--artifacts_dir", required=True) + + args = parser.parse_args() + github_token = ask_for_github_token() + + print("You passed following arguments:") + pprint.pprint({**vars(args), **{"github_token": github_token}}) + + if not get_yes_or_no_answer("Do you want to continue?"): + print("You said NO. Quitting ...") + sys.exit(1) + + user_github_id = args.github_user + repo_url = args.repo_url + release_branch = args.release_branch + release_commit = args.release_commit + artifacts_dir = args.artifacts_dir + + return github_token, user_github_id, repo_url, release_branch, release_commit, artifacts_dir + + +def ask_for_github_token(): + """Ask for github token and print basic information about it.""" + url = "https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token" + message = ( + f"You need to have a github access token with public_repo scope. " + f"More info about creating access tokens can be found here {url}") + print(message) + github_token = input("Enter github token: ") + if not github_token: + return ask_for_github_token() + return github_token + + +def request_url(url, github_token, return_json=True, *args, **kwargs): + """Helper function form making requests authorized by GitHub token.""" Review comment: Fixed. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org