def make_changelog_pr(auth, branch, repo, title, commit_message, body, dry_run=False): repo = repo or util.get_repo() # Make a new branch with a uuid suffix pr_branch = f"changelog-{uuid.uuid1().hex}" if not dry_run: util.run("git --no-pager diff") util.run("git stash") util.run(f"git fetch origin {branch}") util.run(f"git checkout -b {pr_branch} origin/{branch}") util.run("git stash apply") # Add a commit with the message util.run(commit_message) # Create the pull owner, repo_name = repo.split("/") gh = GhApi(owner=owner, repo=repo_name, token=auth) base = branch head = pr_branch maintainer_can_modify = True if dry_run: util.log("Skipping pull request due to dry run") return util.run(f"git push origin {pr_branch}") # title, head, base, body, maintainer_can_modify, draft, issue pull = gh.pulls.create(title, head, base, body, maintainer_can_modify, False, None) util.actions_output("pr_url", pull.html_url)
def publish_release(auth, dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, release_url): """Publish release asset(s) and finalize GitHub release""" util.log(f"Publishing {release_url} in with dry run: {dry_run}") match = parse_release_url(release_url) if npm_token: npm.handle_auth_token(npm_token) found = False for path in glob(f"{dist_dir}/*.*"): name = Path(path).name suffix = Path(path).suffix if suffix in [".gz", ".whl"]: util.run(f"{twine_cmd} {name}", cwd=dist_dir) found = True elif suffix == ".tgz": util.run(f"{npm_cmd} {name}", cwd=dist_dir) found = True else: util.log(f"Nothing to upload for {name}") if not found: # pragma: no cover raise ValueError("No assets published, refusing to finalize release") # Take the release out of draft gh = GhApi(owner=match["owner"], repo=match["repo"], token=auth) release = util.release_for_url(gh, release_url) release = gh.repos.update_release( release.id, release.tag_name, release.target_commitish, release.name, release.body, dry_run, release.prerelease, ) # Set the GitHub action output util.actions_output("release_url", release.html_url)
def publish_release(auth, release_url): """Publish GitHub release""" util.log(f"Publishing {release_url}") match = parse_release_url(release_url) # Take the release out of draft gh = GhApi(owner=match["owner"], repo=match["repo"], token=auth) release = util.release_for_url(gh, release_url) release = gh.repos.update_release( release.id, release.tag_name, release.target_commitish, release.name, release.body, False, release.prerelease, ) # Set the GitHub action output util.actions_output("release_url", release.html_url)
def draft_release( ref, branch, repo, auth, changelog_path, version_cmd, dist_dir, dry_run, post_version_spec, assets, ): """Publish Draft GitHub release and handle post version bump""" branch = branch or util.get_branch() repo = repo or util.get_repo() assets = assets or glob(f"{dist_dir}/*") version = util.get_version() body = changelog.extract_current(changelog_path) prerelease = util.is_prerelease(version) # Bump to post version if given if post_version_spec: post_version = bump_version(post_version_spec, version_cmd) util.log(f"Bumped version to {post_version}") util.run(f'git commit -a -m "Bump to {post_version}"') if dry_run: return owner, repo_name = repo.split("/") gh = GhApi(owner=owner, repo=repo_name, token=auth) # Remove draft releases over a day old if bool(os.environ.get("GITHUB_ACTIONS")): for release in gh.repos.list_releases(): if str(release.draft).lower() == "false": continue created = release.created_at d_created = datetime.strptime(created, r"%Y-%m-%dT%H:%M:%SZ") delta = datetime.utcnow() - d_created if delta.days > 0: gh.repos.delete_release(release.id) remote_url = util.run("git config --get remote.origin.url") if not os.path.exists(remote_url): util.run(f"git push origin HEAD:{branch} --follow-tags --tags") util.log(f"Creating release for {version}") util.log(f"With assets: {assets}") release = gh.create_release( f"v{version}", branch, f"Release v{version}", body, True, prerelease, files=assets, ) # Set the GitHub action output util.actions_output("release_url", release.html_url)
def publish_release(auth, dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, release_url): """Publish release asset(s) and finalize GitHub release""" util.log(f"Publishing {release_url} in with dry run: {dry_run}") if dry_run: # Start local pypi server with no auth, allowing overwrites, # in a temporary directory temp_dir = TemporaryDirectory() cmd = f"pypi-server -p 8081 -P . -a . -o -v {temp_dir.name}" proc = Popen(shlex.split(cmd), stderr=PIPE) # Wait for the server to start while True: line = proc.stderr.readline().decode("utf-8").strip() util.log(line) if "Listening on" in line: break atexit.register(proc.kill) atexit.register(temp_dir.cleanup) twine_cmd = "twine upload --repository-url=http://localhost:8081" os.environ["TWINE_USERNAME"] = "******" os.environ["TWINE_PASSWORD"] = "******" npm_cmd = "npm publish --dry-run" match = parse_release_url(release_url) if npm_token: npm.handle_auth_token(npm_token) found = False for path in glob(f"{dist_dir}/*.*"): name = Path(path).name suffix = Path(path).suffix if suffix in [".gz", ".whl"]: util.run(f"{twine_cmd} {name}", cwd=dist_dir) found = True elif suffix == ".tgz": util.run(f"{npm_cmd} {name}", cwd=dist_dir) found = True else: util.log(f"Nothing to upload for {name}") if not found: # pragma: no cover raise ValueError("No assets published, refusing to finalize release") # Take the release out of draft gh = GhApi(owner=match["owner"], repo=match["repo"], token=auth) release = util.release_for_url(gh, release_url) release = gh.repos.update_release( release.id, release.tag_name, release.target_commitish, release.name, release.body, dry_run, release.prerelease, ) # Set the GitHub action output util.actions_output("release_url", release.html_url)