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 --version to NfCoreTemplate #1951

Merged
merged 1 commit into from
Nov 18, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Fix lint warnings for `samplesheet_check.nf` module
- Add codespaces template ([#1957](https://github.com/nf-core/tools/pull/1957))
- Check that the workflow name provided with a template doesn't contain dashes ([#1822](https://github.com/nf-core/tools/pull/1822))
- `nextflow run <pipeline> --version` will now print the workflow version from the manifest and exit ([#1951](https://github.com/nf-core/tools/pull/1951))

### Linting

Expand Down
1 change: 0 additions & 1 deletion nf_core/lint/nextflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def nextflow_config(self):
]
# Old depreciated vars - fail if present
config_fail_ifdefined = [
"params.version",
"params.nf_required_version",
"params.container",
"params.singleEnd",
Expand Down
1 change: 0 additions & 1 deletion nf_core/pipeline-template/lib/NfcoreSchema.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class NfcoreSchema {
'quiet',
'syslog',
'v',
'version',

// Options for `nextflow run` command
'ansi',
Expand Down
26 changes: 23 additions & 3 deletions nf_core/pipeline-template/lib/NfcoreTemplate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ class NfcoreTemplate {
}
}

//
// Generate version string
//
public static String version(workflow) {
String version_string = ""

if (workflow.manifest.version) {
def prefix_v = workflow.manifest.version[0] != 'v' ? 'v' : ''
version_string += "${prefix_v}${workflow.manifest.version}"
}

if (workflow.commitId) {
def git_shortsha = workflow.commitId.substring(0, 7)
version_string += "-g${git_shortsha}"
}

return version_string
}

//
// Construct and send completion email
//
Expand Down Expand Up @@ -61,7 +80,7 @@ class NfcoreTemplate {
misc_fields['Nextflow Compile Timestamp'] = workflow.nextflow.timestamp

def email_fields = [:]
email_fields['version'] = workflow.manifest.version
email_fields['version'] = NfcoreTemplate.version(workflow)
email_fields['runName'] = workflow.runName
email_fields['success'] = workflow.success
email_fields['dateComplete'] = workflow.complete
Expand Down Expand Up @@ -170,7 +189,7 @@ class NfcoreTemplate {
misc_fields['nxf_timestamp'] = workflow.nextflow.timestamp

def msg_fields = [:]
msg_fields['version'] = workflow.manifest.version
msg_fields['version'] = NfcoreTemplate.version(workflow)
msg_fields['runName'] = workflow.runName
msg_fields['success'] = workflow.success
msg_fields['dateComplete'] = workflow.complete
Expand Down Expand Up @@ -300,6 +319,7 @@ class NfcoreTemplate {
//
public static String logo(workflow, monochrome_logs) {
Map colors = logColours(monochrome_logs)
String workflow_version = NfcoreTemplate.version(workflow)
String.format(
"""\n
${dashedLine(monochrome_logs)}{% if branded %}
Expand All @@ -308,7 +328,7 @@ class NfcoreTemplate {
${colors.blue} |\\ | |__ __ / ` / \\ |__) |__ ${colors.yellow}} {${colors.reset}
${colors.blue} | \\| | \\__, \\__/ | \\ |___ ${colors.green}\\`-._,-`-,${colors.reset}
${colors.green}`._,._,\'${colors.reset}{% endif %}
${colors.purple} ${workflow.manifest.name} v${workflow.manifest.version}${colors.reset}
${colors.purple} ${workflow.manifest.name} ${workflow_version}${colors.reset}
${dashedLine(monochrome_logs)}
""".stripIndent()
)
Expand Down
11 changes: 9 additions & 2 deletions nf_core/pipeline-template/lib/WorkflowMain.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class WorkflowMain {
}

//
// Print help to screen if required
// Generate help string
//
public static String help(workflow, params, log) {
{% if igenomes -%}
Expand All @@ -36,7 +36,7 @@ class WorkflowMain {
}

//
// Print parameter summary log to screen
// Generate parameter summary log string
//
public static String paramsSummaryLog(workflow, params, log) {
def summary_log = ''
Expand All @@ -57,6 +57,13 @@ class WorkflowMain {
System.exit(0)
}

// Print workflow version and exit on --version
if (params.version) {
String workflow_version = NfcoreTemplate.version(workflow)
log.info "${workflow.manifest.name} ${workflow_version}"
System.exit(0)
}

// Validate workflow parameters via the JSON schema
if (params.validate_params) {
NfcoreSchema.validateParameters(workflow, params, log)
Expand Down
1 change: 1 addition & 0 deletions nf_core/pipeline-template/nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ params {
monochrome_logs = false
hook_url = null
help = false
version = false
validate_params = true
show_hidden_params = false
schema_ignore_params = 'genomes'
Expand Down
6 changes: 6 additions & 0 deletions nf_core/pipeline-template/nextflow_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@
"fa_icon": "fas fa-question-circle",
"hidden": true
},
"version": {
"type": "boolean",
"description": "Display version and exit.",
"fa_icon": "fas fa-question-circle",
"hidden": true
},
"publish_dir_mode": {
"type": "string",
"default": "copy",
Expand Down