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

Add force_pr flag to sync, to force a PR even though there are no changes committed #2822

Merged
merged 8 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 4 additions & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ on:
- "ubuntu-latest"
- "self-hosted"
default: "self-hosted"
force_pr:
description: "Force a PR to be created"
type: boolean
default: false

# Cancel if a newer run is started
concurrency:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@

- Update CI to use nf-core/setup-nextflow v2 ([#2819](https://github.com/nf-core/tools/pull/2819))
- Changelog bot: handle also patch version before dev suffix ([#2820](https://github.com/nf-core/tools/pull/2820))
- Add `force_pr` flag to sync, to force a PR even though there are no changes committed ([#2822](https://github.com/nf-core/tools/pull/2822))
- update prettier to 3.2.5 ([#2830](https://github.com/nf-core/tools/pull/2830))
- Update GitHub Actions ([#2827](https://github.com/nf-core/tools/pull/2827))
mashehu marked this conversation as resolved.
Show resolved Hide resolved
- Update prettier to 3.2.5 ([#2830](https://github.com/nf-core/tools/pull/2830))
- Update GitHub Actions ([#2827](https://github.com/nf-core/tools/pull/2827)), ([#2902](https://github.com/nf-core/tools/pull/2902)), ([#2927](https://github.com/nf-core/tools/pull/2927)), ([#2939](https://github.com/nf-core/tools/pull/2939))
- Switch to setup-nf-test ([#2834](https://github.com/nf-core/tools/pull/2834))
Expand Down
10 changes: 8 additions & 2 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2147,10 +2147,16 @@ def logo(logo_text, dir, name, theme, width, format, force):
default=False,
help="Make a GitHub pull-request with the changes.",
)
@click.option(
"--force_pr",
is_flag=True,
default=False,
help="Force the creation of a pull-request, even if there are no changes.",
)
@click.option("-g", "--github-repository", type=str, help="GitHub PR: target repository.")
@click.option("-u", "--username", type=str, help="GitHub PR: auth username.")
@click.option("-t", "--template-yaml", help="Pass a YAML file to customize the template")
def sync(dir, from_branch, pull_request, github_repository, username, template_yaml):
def sync(dir, from_branch, pull_request, github_repository, username, template_yaml, force_pr):
"""
Sync a pipeline [cyan i]TEMPLATE[/] branch with the nf-core template.

Expand All @@ -2170,7 +2176,7 @@ def sync(dir, from_branch, pull_request, github_repository, username, template_y
is_pipeline_directory(dir)

# Sync the given pipeline dir
sync_obj = PipelineSync(dir, from_branch, pull_request, github_repository, username, template_yaml)
sync_obj = PipelineSync(dir, from_branch, pull_request, github_repository, username, template_yaml, force_pr)
try:
sync_obj.sync()
except (SyncExceptionError, PullRequestExceptionError) as e:
Expand Down
9 changes: 8 additions & 1 deletion nf_core/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class PipelineSync:
gh_username (str): GitHub username
gh_repo (str): GitHub repository name
template_yaml_path (str): Path to template.yml file for pipeline creation settings. DEPRECATED
force_pr (bool): Force the creation of a pull request, even if there are no changes to the template

Attributes:
pipeline_dir (str): Path to target pipeline directory
Expand All @@ -64,6 +65,7 @@ def __init__(
gh_repo=None,
gh_username=None,
template_yaml_path=None,
force_pr=False,
):
"""Initialise syncing object"""

Expand All @@ -76,6 +78,7 @@ def __init__(
self.make_pr = make_pr
self.gh_pr_returned_data = {}
self.required_config_vars = ["manifest.name", "manifest.description", "manifest.version", "manifest.author"]
self.force_pr = force_pr

self.gh_username = gh_username
self.gh_repo = gh_repo
Expand Down Expand Up @@ -132,8 +135,12 @@ def sync(self):
self.make_template_pipeline()
self.commit_template_changes()

if not self.made_changes and self.force_pr:
log.info("No changes made to TEMPLATE, but PR forced")
self.made_changes = True

# Push and make a pull request if we've been asked to
if self.made_changes and self.make_pr:
if self.made_changes and self.make_pr or self.force_pr:
try:
# Check that we have an API auth token
if os.environ.get("GITHUB_AUTH_TOKEN", "") == "":
Expand Down
Loading