Skip to content

Commit

Permalink
Add triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed May 15, 2024
1 parent 8909f04 commit 5df21fc
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 12 deletions.
3 changes: 2 additions & 1 deletion docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ The `nf-test.config` file is a configuration file used to customize settings and
| `withTrace` | Enable or disable tracing options during testing. Disable tracing if your containers don't include the `procps` tool. | `true` |
| `autoSort` | Enable or disable sorted channels by default when running tests. | `true` |
| `options` | Custom Nextflow command-line options to be applied when running tests. For example `"-dump-channels -stub-run"` | |
| `ignore` | List of filenames or patterns that should be ignored when building the dependency graph. For example: `ignore ['folder/**/*.nf', 'modules/module.nf']` | `` |
| `ignore` | List of filenames or patterns that should be ignored when building the dependency graph. For example: `ignore 'folder/**/*.nf', 'modules/module.nf'` | `` |
| `triggers` | List of filenames or patterns that should be trigger a full test run. For example: `triggers 'nextflow.config', 'test-data/**/*'` | `` |
| `requires` | Can be used to specify the minimum required version of nf-test. Requires nf-test > 0.9.0 | `` |

Here's an example of what an `nf-test.config` file could look like:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Integer execute() throws Exception {

DependencyResolver resolver = new DependencyResolver(new File(new File("").getAbsolutePath()));
if (config != null) {
resolver.buildGraph(config.getIgnore());
resolver.buildGraph(config.getIgnore(), config.getTriggers());
} else {
resolver.buildGraph();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public Integer execute() throws Exception {

if (findRelatedTests) {

resolver.buildGraph(config.getIgnore());
resolver.buildGraph(config.getIgnore(), config.getTriggers());
scripts = resolver.findRelatedTestsByFiles(testPaths);
System.out.println("Found " + scripts.size() + " related test(s)");
if (scripts.isEmpty()) {
Expand All @@ -229,7 +229,7 @@ public Integer execute() throws Exception {

} else {
if (config != null) {
resolver.buildGraph(config.getIgnore());
resolver.buildGraph(config.getIgnore(), config.getTriggers());
} else {
resolver.buildGraph();
}
Expand Down
38 changes: 33 additions & 5 deletions src/main/java/com/askimed/nf/test/config/Config.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.askimed.nf.test.config;

import java.io.File;
import java.util.List;
import java.util.Vector;
import java.util.Map;
import java.util.*;

import com.askimed.nf.test.App;
import com.askimed.nf.test.nextflow.NextflowCommand;
Expand Down Expand Up @@ -52,6 +50,8 @@ public class Config {

private Map<String, Object> requires = null;

private List<String> triggers = new Vector<String>();

public void testsDir(String testsDir) {
this.testsDir = testsDir;
}
Expand Down Expand Up @@ -160,14 +160,42 @@ public List<String> getIgnore() {
return ignore;
}

public void ignore(List<String> ignores) {
this.ignore.addAll(ignores);
public void ignore(List<Object> ignores) {
for (Object ignore: ignores) {
this.ignore.add(ignore.toString());
}
}

public void ignore(String ignore) {
this.ignore.add(ignore);
}

public void ignore(String ... ignore) {
this.ignore.addAll(Arrays.asList(ignore));
}

public void setTriggers(List<String> triggers) {
this.triggers = triggers;
}

public List<String> getTriggers() {
return triggers;
}

public void triggers(List<Object> triggers) {
for (Object trigger: triggers) {
this.triggers.add(trigger.toString());
}
}

public void triggers(String ... triggers) {
this.triggers.addAll(Arrays.asList(triggers));
}

public void trigger(String trigger) {
this.triggers.add(trigger);
}

public void stage(Closure closure) {
closure.setDelegate(stageBuilder);
closure.setResolveStrategy(Closure.DELEGATE_ONLY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class DependencyResolver {

private DependencyGraph graph = new DependencyGraph();

private List<PathMatcher> triggerPatterns = new Vector<PathMatcher>();

private boolean followingDependencies = false;

private static Logger log = LoggerFactory.getLogger(DependencyResolver.class);
Expand Down Expand Up @@ -89,6 +91,13 @@ public List<File> findRelatedTestsByFiles(List<File> files) throws Exception {

public List<File> findRelatedTestsByFiles(File ... files) throws Exception {

for (File file: files) {
if (matches2(file.toPath(), triggerPatterns)) {
log.info("File " + file.getAbsolutePath() + " triggers full test run.");
return findAllTests();
}
}

Set<File> results = new HashSet<File>();

long time0 = System.currentTimeMillis();
Expand Down Expand Up @@ -149,16 +158,20 @@ private Set<File> findRelatedTestsByFile(File file, boolean followingDependencie


public void buildGraph() throws Exception {
buildGraph(new Vector<String>());
buildGraph(new Vector<String>(), new Vector<String>());
}

public void buildGraph(String ... ignoreGlobs) throws Exception {
List<String> list = new Vector<>();
Collections.addAll(list, ignoreGlobs);
buildGraph(list);
buildGraph(list, new Vector<>());
}

public void buildGraph(List<String> ignoreGlobs) throws Exception {
public void buildGraph(List<String> ignoreGlobs, List<String> triggerPatterns) throws Exception {

for (String glob: triggerPatterns) {
this.triggerPatterns.add(pathMatcher("glob:" + baseDir.getAbsolutePath() + "/" + glob));
}

List<TestFilePattern> ignorePatterns = new Vector<TestFilePattern>();
ignorePatterns.add(fileToPathMatcher(".nf-test/**"));
Expand Down Expand Up @@ -230,6 +243,7 @@ public TestFilePattern fileToPathMatcher(File file) {


public PathMatcher pathMatcher(String pattern) {
System.out.println(pattern);
return FileSystems.getDefault().getPathMatcher(pattern);
}

Expand All @@ -243,4 +257,15 @@ public TestFilePattern matches(Path path, List<TestFilePattern> ignorePatterns)
return null;
}

public boolean matches2(Path path, List<PathMatcher> ignorePatterns) {
PathMatcher pathMatcher;
for (PathMatcher pattern : ignorePatterns) {
if (pattern.matches(path)) {
return true;
}
}
return false;
}


}

0 comments on commit 5df21fc

Please sign in to comment.