Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set upstream branch when pushing workflows to GitHub #1249

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions planemo/commands/cmd_workflow_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

@click.command("workflow_upload")
@options.github_namespace()
@options.github_branch()
@options.dry_run()
@options.optional_tools_or_packages_arg(multiple=True)
@command_function
def cli(ctx, paths, namespace, dry_run, **kwds):
def cli(ctx, paths, namespace, dry_run, github_branch, **kwds):
"""Upload workflows to github organization."""
owner = namespace
for path in paths:
Expand All @@ -40,5 +41,12 @@ def cli(ctx, paths, namespace, dry_run, **kwds):
raise Exception(f"All workflows in repository must have same version.\n{msg}")
if versions:
create_release(
ctx, from_dir=path, target_dir=repo, owner=owner, repo=repo, version=version, dry_run=dry_run
ctx,
from_dir=path,
target_dir=repo,
owner=owner,
repo=repo,
version=version,
dry_run=dry_run,
branch=github_branch,
)
10 changes: 6 additions & 4 deletions planemo/github_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ def rm_dir_contents(directory, ignore_dirs=(".git")):
item.unlink()


def add_dir_contents_to_repo(ctx, from_dir, target_dir, target_repository_path, version, dry_run, notes=""):
def add_dir_contents_to_repo(
ctx, from_dir, target_dir, target_repository_path, version, dry_run, branch="main", notes=""
):
ctx.log(f"From {from_dir} to {target_repository_path}")
rm_dir_contents(target_repository_path)
copy_tree(from_dir, target_repository_path)
Expand All @@ -117,7 +119,7 @@ def add_dir_contents_to_repo(ctx, from_dir, target_dir, target_repository_path,
message += f"\n{notes}"
git.commit(ctx, repo_path=target_repository_path, message=message)
if not dry_run:
git.push(ctx, target_repository_path)
git.push(ctx, target_repository_path, to="origin", branch=branch)


def assert_new_version(ctx, version, owner, repo):
Expand Down Expand Up @@ -161,11 +163,11 @@ def changelog_in_repo(target_repository_path):
return "\n".join(changelog).rstrip()


def create_release(ctx, from_dir, target_dir, owner, repo, version, dry_run, notes="", **kwds):
def create_release(ctx, from_dir, target_dir, owner, repo, version, dry_run, branch, notes="", **kwds):
assert_new_version(ctx, version, owner=owner, repo=repo)
target_repository_path = get_or_create_repository(ctx, owner=owner, repo=repo, dry_run=dry_run)
add_dir_contents_to_repo(
ctx, from_dir, target_dir, target_repository_path, version=version, dry_run=dry_run, notes=notes
ctx, from_dir, target_dir, target_repository_path, version=version, dry_run=dry_run, branch=branch, notes=notes
)
gh_path = ensure_gh(ctx, **kwds)
gh_env = get_gh_env(ctx, dry_run=dry_run, **kwds)
Expand Down
8 changes: 8 additions & 0 deletions planemo/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,14 @@ def dry_run():
)


def github_branch():
return planemo_option(
"--github_branch",
help="GitHub branch to use for the action. Default is main.",
default="main",
)


def galaxy_run_options():
return _compose(
galaxy_target_options(),
Expand Down