Skip to content

Commit

Permalink
Add ns build (#5)
Browse files Browse the repository at this point in the history
* Add ns build action

* add node modules Y_Y

* update documentation

---------

Co-authored-by: Dries Schaumont <[email protected]>
  • Loading branch information
rcannood and DriesSchaumont authored Feb 1, 2023
1 parent 86a511e commit 8c078bb
Show file tree
Hide file tree
Showing 445 changed files with 98,431 additions and 17 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## New Features

* Added [build-nextflow-schemas](build-nextflow-schemas) - Build schemas from a viash config to use with nf-tower
* Added [ns-build](ns-build) - Build a namespace from many viash config files.

* Added [build_nextflow_schemas](build_nextflow_schemas) - Build schemas from a viash config to use with nf-tower

* Added [build-nextflow-params](build-nextflow-params) - build nextflow parameter file templates (see nextflow's -params-file option) from viash configs

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
This repository stores [Github Actions](https://github.com/features/actions) useful for building and publishing [Viash](https://viash.io) documents.

1. [viash-io/viash-actions/setup](setup) - Install Viash
1. [viash-io/viash-actions/ns-list](ns-list) - List Viash components in a repository
2. [viash-io/viash-actions/ns-list](ns-list) - List Viash components in a repository
3. [viash-io/viash-actions/ns-build](ns-build) - Build a namespace from many viash config files.

We recommend using `v1` for your actions.
We recommend using `v2` for your actions.

## Release Management

Expand Down
60 changes: 60 additions & 0 deletions ns-build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
ns-build
================

Build a namespace from many viash config files.

## Usage

This action will run `viash ns build`. See the reference documentation
on [ns build](https://viash.io/reference/viash/ns.html) for more info on
each of the arguments.

We recommend using a Linux or MacOS runner if possible.

### Inputs available

- `query`: - *optional*. Filter which components get selected by
component and namespace name. Can be a regex. Example:
“^mynamespace/component1\$”.
- `query_namespace`: - *optional*. Filter which namespaces get selected
by namespace name. Can be a regex. Example: “^mynamespace\$”.
- `query_name`: - *optional*. Filter which components get selected by
component name. Can be a regex. Example: “^component1”.
- `src`: - *optional*. A source directory containing viash config files,
possibly structured in a hierarchical folder structure. Default: src/.
- `platform`: - *optional*. Acts as a regular expression to filter the
platform ids specified in the found config files. If this is not
provided, all platforms will be used. If no platforms are defined in a
config, the native platform will be used. In addition, the path to a
platform yaml file can also be specified.
- `parallel`: - *optional*. Whether or not to run the process in
parallel.
- `config_mod`: - *optional*. Modify a viash config at runtime using
dynamic config modding.
- `target`: - *optional*. A target directory to build the executables
into. Default: target/.
- `setup`: - *optional*. Which setup strategy for creating the container
to use \[Docker Platform only\].

## Examples

``` yaml
name: demo of viash ns build

on:
branch: main

jobs:
viash-linux:
runs-on: ubuntu-latest
steps:
- uses: viash-io/viash-actions/setup@v1

- uses: viash-io/viash-actions/ns-build@v1
viash-macos:
runs-on: macos-latest
steps:
- uses: viash-io/viash-actions/setup@v1

- uses: viash-io/viash-actions/ns-build@v1
```
55 changes: 55 additions & 0 deletions ns-build/README.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: ns-build
format: gfm
---

```{r}
#| include: false
library(tidyverse)
# action <- yaml::read_yaml("ns-build/action.yml")
action <- yaml::read_yaml("action.yml")
```

`r action$description`

## Usage

This action will run `viash ns build`. See the reference documentation on [ns build](https://viash.io/reference/viash/ns.html) for more info on each of the arguments.

We recommend using a Linux or MacOS runner if possible.

### Inputs available

```{r}
#| echo: false
lines <- map_chr(names(action$inputs), function(name) {
input <- action$inputs[[name]]
required <- ifelse (input$required %||% FALSE, "required", "optional")
glue::glue("* `{name}`: - _{required}_. {input$description}")
})
knitr::asis_output(paste0(lines, collapse = "\n"))
```

## Examples

```yaml
name: demo of viash ns build

on:
branch: main

jobs:
viash-linux:
runs-on: ubuntu-latest
steps:
- uses: viash-io/viash-actions/setup@v1

- uses: viash-io/viash-actions/ns-build@v1
viash-macos:
runs-on: macos-latest
steps:
- uses: viash-io/viash-actions/setup@v1

- uses: viash-io/viash-actions/ns-build@v1
```
41 changes: 41 additions & 0 deletions ns-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: viash ns build
description: Build a namespace from many viash config files.
inputs:
query:
description: 'Filter which components get selected by component and namespace
name. Can be a regex. Example: "^mynamespace/component1$".'
required: false
query_namespace:
description: 'Filter which namespaces get selected by namespace name. Can be a
regex. Example: "^mynamespace$".'
required: false
query_name:
description: 'Filter which components get selected by component name. Can be a
regex. Example: "^component1".'
required: false
src:
description: ' A source directory containing viash config files, possibly structured
in a hierarchical folder structure. Default: src/.'
required: false
platform:
description: Acts as a regular expression to filter the platform ids specified
in the found config files. If this is not provided, all platforms will be used.
If no platforms are defined in a config, the native platform will be used. In
addition, the path to a platform yaml file can also be specified.
required: false
parallel:
description: Whether or not to run the process in parallel.
required: false
config_mod:
description: Modify a viash config at runtime using dynamic config modding.
required: false
target:
description: 'A target directory to build the executables into. Default: target/.'
required: false
setup:
description: Which setup strategy for creating the container to use [Docker Platform
only].
required: false
runs:
using: node16
main: index.js
71 changes: 71 additions & 0 deletions ns-build/generate_yml.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This script generates a github action given a Viash schema

library(tidyverse)

# parameters
skip_args <- c("push", "flatten")
dest_file <- "ns-build/action.yml"
subcommands <- c("ns", "build")

#################### common code
# fetch schema
out <- system("viash export cli_schema", intern = TRUE)
schema <- jsonlite::fromJSON(out, simplifyVector = FALSE)

# go down schema to find the right command
for (i in seq_along(subcommands)) {
subcommand <- subcommands[[i]]
schema <- schema[[which(sapply(schema, function(li) li$name == subcommand))]]

if (i != length(subcommands)) {
schema <- schema$subcommands
}
}

# construct yaml
selected_opts <- schema$opts[sapply(schema$opts, function(x) !x$name %in% skip_args)]
input_values <- sapply(selected_opts, function(opt) {
descr <- opt$descr %>%
str_replace_all("@\\[[^]]*\\]\\(([^\\)]*)\\)", "\\1") %>%
str_replace_all(". *$", ".")

choices_str <-
if (!is.null(opt$choices)) {
paste0(" Possible values are: \"", paste(opt$choices, collapse = "\", \""), "\".")
} else {
""
}
out <- list(
description = paste0(descr, choices_str),
required = opt$required
)
setNames(list(out), opt$name)
})
out <- list(
name = schema$bannerCommand,
description = schema$bannerDescription,
inputs = input_values,
# outputs = list(
# output = list(
# description = "A list of all of the components found. By default this will be a yaml, unless the format argument was set to 'json'."
# )
# ),
runs = list(
using = "node16",
main = "index.js"
)
)

# write github action
handlers <- list(
logical = function(x) {
result <- ifelse(x, "true", "false")
class(result) <- "verbatim"
return(result)
}
)
yaml::write_yaml(
out,
dest_file,
handlers = handlers
)
54 changes: 54 additions & 0 deletions ns-build/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const core = require("@actions/core");
const exec = require("@actions/exec");

async function run() {
try {
// set up listeners
let myOutput = "";
let myError = "";

const options = {};
options.listeners = {
stdout: (data) => {
myOutput += data.toString();
},
stderr: (data) => {
myError += data.toString();
}
};

// fetch arguments for command
// skip "parallel"
// todo: can I extract these inputNames from the action.yml?
const inputNames = [
"query", "query_namespace", "query_name", "src", "platform",
"parallel", "config_mod", "target", "setup"
]
const booleanInputs = ["parallel"]
const inputArgs = inputNames.flatMap(function(argName) {
const value = core.getInput(argName)
if (value == "") {
return [];
} else if (booleanInputs.indexOf(argName) >= 0) {
if (value.toLowerCase() == "true") {
return ["--" + argName];
} else {
return [];
}
} else {
return ["--" + argName, value];
}
})
let args = ["ns", "build"].concat(inputArgs);

// run command
await exec.exec("viash", args, options);

// pass output
core.setOutput("output", myOutput);
} catch (error) {
core.setFailed(error.message);
}
}

run();
1 change: 1 addition & 0 deletions ns-build/node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8c078bb

Please sign in to comment.