Skip to content

Commit e8510cc

Browse files
authored
Merge pull request #3142 from mashehu/master-to-main
Allow `main` as default channel
2 parents f4b5b5d + ce866c6 commit e8510cc

22 files changed

+71
-56
lines changed

.github/actions/create-lint-wf/action.yml

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ runs:
1515
cd create-lint-wf
1616
export NXF_WORK=$(pwd)
1717
18-
# Set up Nextflow
1918
- name: Install Nextflow
2019
uses: nf-core/setup-nextflow@v2
2120
with:

.github/workflows/create-lint-wf.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@ concurrency:
2727
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
2828
cancel-in-progress: true
2929

30-
env:
31-
NXF_ANSI_LOG: false
32-
3330
jobs:
3431
MakeTestWorkflow:
3532
runs-on: ${{ github.event.inputs.runners || github.run_number > 1 && 'ubuntu-latest' || 'self-hosted' }}
3633
env:
3734
NXF_ANSI_LOG: false
35+
3836
strategy:
3937
matrix:
4038
NXF_VER:

.github/workflows/create-test-lint-wf-template.yml

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
needs: prepare-matrix
5252
env:
5353
NXF_ANSI_LOG: false
54+
5455
strategy:
5556
matrix:
5657
TEMPLATE: ${{ fromJson(needs.prepare-matrix.outputs.all_features) }}

.github/workflows/create-test-wf.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ concurrency:
2727
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
2828
cancel-in-progress: true
2929

30-
env:
31-
NXF_ANSI_LOG: false
32-
3330
jobs:
3431
RunTestWorkflow:
3532
# use the runner given by the input if it is dispatched manually, run on github if it is a rerun or on self-hosted by default
3633
runs-on: ${{ github.event.inputs.runners || github.run_number > 1 && 'ubuntu-latest' || 'self-hosted' }}
3734
env:
3835
NXF_ANSI_LOG: false
36+
3937
strategy:
4038
matrix:
4139
NXF_VER:

nf_core/__main__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def command_pipelines_create(ctx, name, description, author, version, force, out
288288
@click.option(
289289
"--release",
290290
is_flag=True,
291-
default=os.path.basename(os.path.dirname(os.environ.get("GITHUB_REF", "").strip(" '\""))) == "master"
291+
default=Path(os.environ.get("GITHUB_REF", "").strip(" '\"")).parent.name in ["master", "main"]
292292
and os.environ.get("GITHUB_REPOSITORY", "").startswith("nf-core/")
293293
and not os.environ.get("GITHUB_REPOSITORY", "") == "nf-core/tools",
294294
help="Execute additional checks for release-ready workflows.",
@@ -2240,7 +2240,7 @@ def command_download(
22402240
@click.option(
22412241
"--release",
22422242
is_flag=True,
2243-
default=os.path.basename(os.path.dirname(os.environ.get("GITHUB_REF", "").strip(" '\""))) == "master"
2243+
default=Path(os.environ.get("GITHUB_REF", "").strip(" '\"")).parent.name in ["master", "main"]
22442244
and os.environ.get("GITHUB_REPOSITORY", "").startswith("nf-core/")
22452245
and not os.environ.get("GITHUB_REPOSITORY", "") == "nf-core/tools",
22462246
help="Execute additional checks for release-ready workflows.",

nf_core/pipeline-template/.github/CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ These tests are run both with the latest available version of `Nextflow` and als
6464

6565
:warning: Only in the unlikely and regretful event of a release happening with a bug.
6666

67-
- On your own fork, make a new branch `patch` based on `upstream/master`.
67+
- On your own fork, make a new branch `patch` based on `upstream/main` or `upstream/master`.
6868
- Fix the bug, and bump version (X.Y.Z+1).
69-
- Open a pull-request from `patch` to `master` with the changes.
69+
- Open a pull-request from `patch` to `main`/`master` with the changes.
7070

7171
{% if is_nfcore -%}
7272

nf_core/pipeline-template/.github/PULL_REQUEST_TEMPLATE.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ These are the most common things requested on pull requests (PRs).
88
99
Remember that PRs should be made against the dev branch, unless you're preparing a pipeline release.
1010
11-
Learn more about contributing: [CONTRIBUTING.md](https://github.com/{{ name }}/tree/master/.github/CONTRIBUTING.md)
11+
Learn more about contributing: [CONTRIBUTING.md](https://github.com/{{ name }}/tree/{{ default_branch }}/.github/CONTRIBUTING.md)
1212
-->
1313

1414
## PR checklist
1515

1616
- [ ] This comment contains a description of changes (with reason).
1717
- [ ] If you've fixed a bug or added code that should be tested, add tests!
18-
- [ ] If you've added a new tool - have you followed the pipeline conventions in the [contribution docs](https://github.com/{{ name }}/tree/master/.github/CONTRIBUTING.md)
18+
- [ ] If you've added a new tool - have you followed the pipeline conventions in the [contribution docs](https://github.com/{{ name }}/tree/{{ default_branch }}/.github/CONTRIBUTING.md)
1919
{%- if is_nfcore %}
2020
- [ ] If necessary, also make a PR on the {{ name }} _branch_ on the [nf-core/test-datasets](https://github.com/nf-core/test-datasets) repository.
2121
{%- endif %}

nf_core/pipeline-template/.github/workflows/awsfulltest.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: nf-core AWS full size tests
2-
# This workflow is triggered on PRs opened against the master branch.
2+
# This workflow is triggered on PRs opened against the main/master branch.
33
# It can be additionally triggered manually with GitHub actions workflow dispatch button.
44
# It runs the -profile 'test_full' on AWS batch
55

66
on:
77
pull_request:
88
branches:
9+
- main
910
- master
1011
workflow_dispatch:
1112
pull_request_review:

nf_core/pipeline-template/.github/workflows/branch.yml

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
name: nf-core branch protection
2-
# This workflow is triggered on PRs to master branch on the repository
3-
# It fails when someone tries to make a PR against the nf-core `master` branch instead of `dev`
2+
# This workflow is triggered on PRs to `main`/`master` branch on the repository
3+
# It fails when someone tries to make a PR against the nf-core `main`/`master` branch instead of `dev`
44
on:
55
pull_request_target:
6-
branches: [master]
6+
branches:
7+
- main
8+
- master
79

810
jobs:
911
test:
1012
runs-on: ubuntu-latest
1113
steps:
12-
# PRs to the nf-core repo master branch are only ok if coming from the nf-core repo `dev` or any `patch` branches
14+
# PRs to the nf-core repo main/master branch are only ok if coming from the nf-core repo `dev` or any `patch` branches
1315
- name: Check PRs
1416
if: github.repository == '{{ name }}'
1517
run: |
@@ -22,7 +24,7 @@ jobs:
2224
uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2
2325
with:
2426
message: |
25-
## This PR is against the `master` branch :x:
27+
## This PR is against the `${{github.event.pull_request.base.ref}}` branch :x:
2628
2729
* Do not close this PR
2830
* Click _Edit_ and change the `base` to `dev`
@@ -32,9 +34,9 @@ jobs:
3234
3335
Hi @${{ github.event.pull_request.user.login }},
3436
35-
It looks like this pull-request is has been made against the [${{github.event.pull_request.head.repo.full_name }}](https://github.com/${{github.event.pull_request.head.repo.full_name }}) `master` branch.
36-
The `master` branch on nf-core repositories should always contain code from the latest release.
37-
Because of this, PRs to `master` are only allowed if they come from the [${{github.event.pull_request.head.repo.full_name }}](https://github.com/${{github.event.pull_request.head.repo.full_name }}) `dev` branch.
37+
It looks like this pull-request is has been made against the [${{github.event.pull_request.head.repo.full_name }}](https://github.com/${{github.event.pull_request.head.repo.full_name }}) ${{github.event.pull_request.base.ref}} branch.
38+
The ${{github.event.pull_request.base.ref}} branch on nf-core repositories should always contain code from the latest release.
39+
Because of this, PRs to ${{github.event.pull_request.base.ref}} are only allowed if they come from the [${{github.event.pull_request.head.repo.full_name }}](https://github.com/${{github.event.pull_request.head.repo.full_name }}) `dev` branch.
3840
3941
You do not need to close this PR, you can change the target branch to `dev` by clicking the _"Edit"_ button at the top of this page.
4042
Note that even after this, the test will continue to show as failing until you push a new commit.

nf_core/pipeline-template/.github/workflows/download_pipeline.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Test successful pipeline download with 'nf-core pipelines download'
22

33
# Run the workflow when:
44
# - dispatched manually
5-
# - when a PR is opened or reopened to master branch
5+
# - when a PR is opened or reopened to main/master branch
66
# - the head branch of the pull request is updated, i.e. if fixes for a release are pushed last minute to dev.
77
on:
88
workflow_dispatch:
@@ -17,9 +17,11 @@ on:
1717
- edited
1818
- synchronize
1919
branches:
20+
- main
2021
- master
2122
pull_request_target:
2223
branches:
24+
- main
2325
- master
2426

2527
env:

nf_core/pipeline-template/assets/schema_input.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"$id": "https://raw.githubusercontent.com/{{ name }}/master/assets/schema_input.json",
3+
"$id": "https://raw.githubusercontent.com/{{ name }}/{{ default_branch }}/assets/schema_input.json",
44
"title": "{{ name }} pipeline - params.input schema",
55
"description": "Schema for the file provided with params.input",
66
"type": "array",

nf_core/pipeline-template/nextflow.config

+1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ manifest {
291291
homePage = 'https://github.com/{{ name }}'
292292
description = """{{ description }}"""
293293
mainScript = 'main.nf'
294+
defaultBranch = '{{ default_branch }}'
294295
nextflowVersion = '!>=24.04.2'
295296
version = '{{ version }}'
296297
doi = ''

nf_core/pipeline-template/nextflow_schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"$id": "https://raw.githubusercontent.com/{{ name }}/master/nextflow_schema.json",
3+
"$id": "https://raw.githubusercontent.com/{{ name }}/{{ default_branch }}/nextflow_schema.json",
44
"title": "{{ name }} pipeline parameters",
55
"description": "{{ description }}",
66
"type": "object",

nf_core/pipelines/create/create.py

+28-18
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(
5757
template_config: Optional[Union[CreateConfig, str, Path]] = None,
5858
organisation: str = "nf-core",
5959
from_config_file: bool = False,
60-
default_branch: Optional[str] = None,
60+
default_branch: str = "main",
6161
is_interactive: bool = False,
6262
) -> None:
6363
if isinstance(template_config, CreateConfig):
@@ -87,8 +87,17 @@ def __init__(
8787
# Read features yaml file
8888
self.template_features_yml = load_features_yaml()
8989

90+
# Set fields used by the class methods
91+
self.no_git = no_git
92+
self.default_branch = default_branch
93+
self.is_interactive = is_interactive
94+
9095
if self.config.outdir is None:
9196
self.config.outdir = str(Path.cwd())
97+
98+
# Get the default branch name from the Git configuration
99+
self.get_default_branch()
100+
92101
self.jinja_params, self.skip_areas = self.obtain_jinja_params_dict(
93102
self.config.skip_features or [], str(self.config.outdir)
94103
)
@@ -107,11 +116,6 @@ def __init__(
107116

108117
# Set convenience variables
109118
self.name = self.config.name
110-
111-
# Set fields used by the class methods
112-
self.no_git = no_git
113-
self.default_branch = default_branch
114-
self.is_interactive = is_interactive
115119
self.force = self.config.force
116120

117121
if self.config.outdir == ".":
@@ -233,6 +237,7 @@ def obtain_jinja_params_dict(
233237
jinja_params["name_docker"] = jinja_params["name"].replace(jinja_params["org"], jinja_params["prefix_nodash"])
234238
jinja_params["logo_light"] = f"{jinja_params['name_noslash']}_logo_light.png"
235239
jinja_params["logo_dark"] = f"{jinja_params['name_noslash']}_logo_dark.png"
240+
jinja_params["default_branch"] = self.default_branch
236241
if config_yml is not None:
237242
if (
238243
hasattr(config_yml, "lint")
@@ -254,6 +259,7 @@ def obtain_jinja_params_dict(
254259

255260
def init_pipeline(self):
256261
"""Creates the nf-core pipeline."""
262+
257263
# Make the new pipeline
258264
self.render_template()
259265

@@ -421,33 +427,37 @@ def make_pipeline_logo(self):
421427
force=bool(self.force),
422428
)
423429

424-
def git_init_pipeline(self) -> None:
425-
"""Initialises the new pipeline as a Git repository and submits first commit.
426-
427-
Raises:
428-
UserWarning: if Git default branch is set to 'dev' or 'TEMPLATE'.
429-
"""
430-
default_branch: Optional[str] = self.default_branch
430+
def get_default_branch(self) -> None:
431+
"""Gets the default branch name from the Git configuration."""
431432
try:
432-
default_branch = default_branch or str(git.config.GitConfigParser().get_value("init", "defaultBranch"))
433+
self.default_branch = (
434+
str(git.config.GitConfigParser().get_value("init", "defaultBranch")) or "main"
435+
) # default to main
433436
except configparser.Error:
434437
log.debug("Could not read init.defaultBranch")
435-
if default_branch in ["dev", "TEMPLATE"]:
438+
if self.default_branch in ["dev", "TEMPLATE"]:
436439
raise UserWarning(
437-
f"Your Git defaultBranch '{default_branch}' is incompatible with nf-core.\n"
440+
f"Your Git defaultBranch '{self.default_branch}' is incompatible with nf-core.\n"
438441
"'dev' and 'TEMPLATE' can not be used as default branch name.\n"
439442
"Set the default branch name with "
440443
"[white on grey23] git config --global init.defaultBranch <NAME> [/]\n"
441444
"Or set the default_branch parameter in this class.\n"
442445
"Pipeline git repository will not be initialised."
443446
)
444447

448+
def git_init_pipeline(self) -> None:
449+
"""Initialises the new pipeline as a Git repository and submits first commit.
450+
451+
Raises:
452+
UserWarning: if Git default branch is set to 'dev' or 'TEMPLATE'.
453+
"""
454+
445455
log.info("Initialising local pipeline git repository")
446456
repo = git.Repo.init(self.outdir)
447457
repo.git.add(A=True)
448458
repo.index.commit(f"initial template build from nf-core/tools, version {nf_core.__version__}")
449-
if default_branch:
450-
repo.active_branch.rename(default_branch)
459+
if self.default_branch:
460+
repo.active_branch.rename(self.default_branch)
451461
try:
452462
repo.git.branch("TEMPLATE")
453463
repo.git.branch("dev")

nf_core/pipelines/download.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ def tidy_tags_and_branches(self):
17441744
for tag in tags_to_remove:
17451745
self.repo.delete_tag(tag)
17461746

1747-
# switch to a revision that should be kept, because deleting heads fails, if they are checked out (e.g. "master")
1747+
# switch to a revision that should be kept, because deleting heads fails, if they are checked out (e.g. "main")
17481748
self.checkout(self.revision[0])
17491749

17501750
# delete unwanted heads/branches from repository

nf_core/pipelines/lint/actions_awsfulltest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def actions_awsfulltest(self) -> Dict[str, List[str]]:
4242

4343
# Check that the action is only turned on for published releases
4444
try:
45-
if wf[True]["pull_request"]["branches"] != ["master"]:
45+
if wf[True]["pull_request"]["branches"] != ["main", "master"]:
4646
raise AssertionError()
4747
if wf[True]["pull_request_review"]["types"] != ["submitted"]:
4848
raise AssertionError()

nf_core/pipelines/lint/version_consistency.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def version_consistency(self):
55
"""Pipeline and container version number consistency.
66
77
.. note:: This test only runs when the ``--release`` flag is set for ``nf-core pipelines lint``,
8-
or ``$GITHUB_REF`` is equal to ``master``.
8+
or ``$GITHUB_REF`` is equal to ``main``.
99
1010
This lint fetches the pipeline version number from three possible locations:
1111

nf_core/pipelines/schema.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,13 @@ def validate_schema_title_description(self, schema=None):
517517
if "title" not in self.schema:
518518
raise AssertionError("Schema missing top-level `title` attribute")
519519
# Validate that id, title and description match the pipeline manifest
520-
id_attr = "https://raw.githubusercontent.com/{}/master/nextflow_schema.json".format(
520+
id_attr = "https://raw.githubusercontent.com/{}/main/nextflow_schema.json".format(
521521
self.pipeline_manifest["name"].strip("\"'")
522522
)
523-
if self.schema["$id"] != id_attr:
524-
raise AssertionError(f"Schema `$id` should be `{id_attr}`\n Found `{self.schema['$id']}`")
523+
if self.schema["$id"] not in [id_attr, id_attr.replace("/main/", "/master/")]:
524+
raise AssertionError(
525+
f"Schema `$id` should be `{id_attr}` or {id_attr.replace('/main/', '/master/')}. \n Found `{self.schema['$id']}`"
526+
)
525527

526528
title_attr = "{} pipeline parameters".format(self.pipeline_manifest["name"].strip("\"'"))
527529
if self.schema["title"] != title_attr:

nf_core/synced_repo.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from git.exc import GitCommandError
1111

1212
from nf_core.components.components_utils import (
13+
NF_CORE_MODULES_DEFAULT_BRANCH,
1314
NF_CORE_MODULES_NAME,
1415
NF_CORE_MODULES_REMOTE,
1516
)
@@ -186,7 +187,7 @@ def setup_branch(self, branch):
186187
if branch is None:
187188
# Don't bother fetching default branch if we're using nf-core
188189
if self.remote_url == NF_CORE_MODULES_REMOTE:
189-
self.branch = "master"
190+
self.branch = NF_CORE_MODULES_DEFAULT_BRANCH
190191
else:
191192
self.branch = self.get_default_branch()
192193
else:

tests/pipelines/lint/test_actions_awstest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_actions_awstest_fail(self):
2424
new_pipeline = self._make_pipeline_copy()
2525
with open(Path(new_pipeline, ".github", "workflows", "awstest.yml")) as fh:
2626
awstest_yml = yaml.safe_load(fh)
27-
awstest_yml[True]["push"] = ["master"]
27+
awstest_yml[True]["push"] = ["main"]
2828
with open(Path(new_pipeline, ".github", "workflows", "awstest.yml"), "w") as fh:
2929
yaml.dump(awstest_yml, fh)
3030

tests/pipelines/test_lint.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def setUp(self) -> None:
2525
##########################
2626
class TestPipelinesLint(TestLint):
2727
def test_run_linting_function(self):
28-
"""Run the master run_linting() function in lint.py
28+
"""Run the run_linting() function in lint.py
2929
3030
We don't really check any of this code as it's just a series of function calls
3131
and we're testing each of those individually. This is mostly to check for syntax errors."""

0 commit comments

Comments
 (0)