Skip to content

Commit 76f401a

Browse files
committed
add push command
Signed-off-by: jorgee <jorge.ejarque@seqera.io>
1 parent b1e6c4a commit 76f401a

File tree

4 files changed

+106
-2
lines changed

4 files changed

+106
-2
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright 2013-2024, Seqera Labs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package nextflow.cli
18+
import com.beust.jcommander.Parameter
19+
import com.beust.jcommander.Parameters
20+
import groovy.transform.CompileStatic
21+
import groovy.util.logging.Slf4j
22+
import nextflow.exception.AbortOperationException
23+
import nextflow.plugin.Plugins
24+
import nextflow.scm.AssetManager
25+
import nextflow.scm.PushManager
26+
import nextflow.util.TestOnly
27+
import org.eclipse.jgit.api.Git
28+
import org.eclipse.jgit.transport.RemoteConfig
29+
import org.eclipse.jgit.transport.URIish
30+
31+
32+
/**
33+
* CLI sub-command Push
34+
*
35+
* @author Jorge Ejarque <jorge.ejarque@seqera.io>
36+
*/
37+
@Slf4j
38+
@CompileStatic
39+
@Parameters(commandDescription = "Pushes a local implementation to a remote repository")
40+
class CmdPush extends CmdBase implements HubOptions {
41+
42+
static final public NAME = 'push'
43+
44+
@Parameter(description = 'Repository URL to push to (optional if already configured as git remote)')
45+
List<String> args
46+
47+
@Parameter(names=['-d', '-directory'], description = 'Local directory to push (default: current directory)')
48+
String directory
49+
50+
@Parameter(names=['-r','-revision'], description = 'Revision of the project to run (either a git branch, tag or commit SHA number)')
51+
String revision = 'main'
52+
53+
@Parameter(names=['-max-size'], description = 'Maximum file size in MB to push without confirmation (default: 10)')
54+
int maxSizeMB = 10
55+
56+
@Parameter(names=['-message', '-m'], description = 'Commit message')
57+
String message = 'Push from nextflow'
58+
59+
@Override
60+
final String getName() { NAME }
61+
62+
@TestOnly
63+
protected File root
64+
65+
@Override
66+
void run() {
67+
if( args && args.size() > 1){
68+
throw new AbortOperationException('Incorrect number of arguments')
69+
}
70+
71+
// Get repository from args (optional)
72+
def repository = args && args.size() == 1 ? args[0] : null
73+
74+
// Folder defaults to current working directory if not specified
75+
def folder = directory
76+
? new File(directory).getAbsoluteFile()
77+
: new File(System.getProperty('user.dir')).getAbsoluteFile()
78+
79+
if( !folder.exists() )
80+
throw new AbortOperationException("Folder does not exist: ${folder.absolutePath}")
81+
82+
if( !folder.isDirectory() )
83+
throw new AbortOperationException("Path is not a directory: ${folder.absolutePath}")
84+
85+
// init plugin system
86+
Plugins.init()
87+
88+
try {
89+
final manager = new PushManager(folder)
90+
def resolvedRepo = repository
91+
if( !resolvedRepo ) {
92+
resolvedRepo = manager.resolveRepository()
93+
}
94+
95+
log.info "Pushing folder ${folder.absolutePath} to repository ${resolvedRepo}"
96+
manager.push(resolvedRepo, revision)
97+
}
98+
catch( Exception e ) {
99+
throw new AbortOperationException("Failed to push folder: ${e.message}", e)
100+
}
101+
}
102+
103+
}

modules/nextflow/src/main/groovy/nextflow/cli/Launcher.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class Launcher {
100100
new CmdList(),
101101
new CmdLog(),
102102
new CmdPull(),
103+
new CmdPush(),
103104
new CmdRun(),
104105
new CmdKubeRun(),
105106
new CmdDrop(),

plugins/nf-tower/src/main/io/seqera/tower/plugin/launch/PushManager.groovy renamed to modules/nextflow/src/main/groovy/nextflow/scm/PushManager.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
package io.seqera.tower.plugin.launch
1+
package nextflow.scm
22

33
import groovy.transform.CompileStatic
44
import groovy.util.logging.Slf4j
55
import nextflow.exception.AbortOperationException
6-
import nextflow.scm.AssetManager
76
import org.eclipse.jgit.api.Git
87
import org.eclipse.jgit.api.Status
98
import org.eclipse.jgit.transport.RemoteConfig

plugins/nf-tower/src/main/io/seqera/tower/plugin/launch/LaunchCommandImpl.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import io.seqera.tower.plugin.TowerClient
2626
import io.seqera.tower.plugin.datalink.DataLinkUtils
2727
import nextflow.BuildInfo
2828
import nextflow.cli.CmdLaunch
29+
import nextflow.scm.PushManager
2930
import nextflow.util.ColorUtil
3031
import nextflow.exception.AbortOperationException
3132
import nextflow.file.FileHelper

0 commit comments

Comments
 (0)