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 project_directory to many actions #42

Merged
merged 12 commits into from
Aug 23, 2024
11 changes: 10 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ concurrency:
on:
workflow_call:
inputs:
project_directory:
type: string
description: 'The path to a Viash project'
required: false
version:
type: string
description: |
Expand Down Expand Up @@ -51,6 +55,7 @@ jobs:

- name: Determine variables
id: variables
working-directory: ${{ inputs.project_directory }}
run: |
VERSION="${{ inputs.version }}"
SOURCE_BRANCH=$(echo "$GITHUB_REF" | sed 's/refs\/heads\///')
Expand All @@ -76,6 +81,7 @@ jobs:
- uses: viash-io/viash-actions/project/build-target@v6
id: build-target
with:
project_directory: ${{ inputs.project_directory }}
target_branch: ${{ steps.variables.outputs.target_branch }}
version: ${{ steps.variables.outputs.version }}

Expand All @@ -84,7 +90,7 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: ${{ steps.variables.outputs.target_branch }}
publish_dir: .
publish_dir: ${{ inputs.project_directory }}

# phase 2
docker:
Expand Down Expand Up @@ -121,11 +127,13 @@ jobs:

- name: Build image
if: ${{ inputs.retag_image_tag == '' }}
working-directory: ${{ inputs.project_directory }}
run: |
${{matrix.component.executable}} ---engine docker ---setup build ---verbose

- name: Retag image
if: ${{ inputs.retag_image_tag != '' }}
working-directory: ${{ inputs.project_directory }}
run: |
source_image_tag="${{ inputs.retag_image_tag }}"

Expand All @@ -143,5 +151,6 @@ jobs:
docker tag "$source_image_id" "$dest_image_id"

- name: Push image
working-directory: ${{ inputs.project_directory }}
run: |
${{matrix.component.executable}} ---engine docker ---setup push ---verbose
12 changes: 11 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: Test
on:
workflow_call:
inputs:
project_directory:
type: string
description: 'The path to a Viash project'
required: false
timeout:
type: number
description: |
Expand Down Expand Up @@ -45,22 +49,27 @@ jobs:

- uses: viash-io/viash-actions/setup@v6

- uses: viash-io/viash-actions/project/sync-and-cache@main
- uses: viash-io/viash-actions/project/sync-and-cache@v6
id: cache
with:
project_directory: ${{ inputs.project_directory }}

- id: ns_list
uses: viash-io/viash-actions/ns-list@v6
with:
project_directory: ${{ inputs.project_directory }}
format: json
runner: executable

- id: ns_list_filter_changed
uses: viash-io/viash-actions/project/detect-changed-components@v6
with:
project_directory: ${{ inputs.project_directory }}
input_file: "${{ steps.ns_list.outputs.output_file }}"

- name: Filter out Nextflow scripts (testing currently not supported)
id: ns_list_filter_nextflow
working-directory: ${{ inputs.project_directory }}
run: |
OUTPUT_MATRIX=$(echo '${{ steps.ns_list_filter_changed.outputs.output_matrix }}' | jq -c 'map(select(.main_script_type != "nextflow_script"))')
echo "output_matrix=$OUTPUT_MATRIX" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -104,6 +113,7 @@ jobs:
timeout-minutes: ${{ inputs.timeout }}
env:
RUNNER_TEMP: "${{ runner.temp }}/viash_temp"
working-directory: ${{ inputs.project_directory }}
run: |
viash test \
"${{ matrix.component.config }}" \
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# viash-actions v6.6.0

## New functionality

* Many actions: Add input `project_directory` to allow specifying the project directory (PR #42):
- `ns-build`
- `ns-list`
- `project/build-target`
- `project/detect-changed-components`
- `project/sync-and-cache`

## Bug fixes

* `project/build-target`: Do not throw an error if there is no `.gitignore` in place (PR #42).

* `ns-build`, `ns-list`: If Viash throws an error, make sure that the error message gets printed (PR #42).

* `project/detect-changed-components`: Fix the action not listening to 'ci force' in commit messages (PR #42).

# viash-actions v6.5.0

## New functionality
Expand Down
5 changes: 5 additions & 0 deletions ns-build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ We recommend using a Linux or MacOS runner if possible.
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”.
- `config`: - *optional*. Filter which component get selected by
specifying the config path.
- `src`: - *optional*. A source directory containing viash config files,
possibly structured in a hierarchical folder structure. Default: src/.
- `platform`: - *optional*. (viash \< 0.9.0) Acts as a regular
Expand Down Expand Up @@ -54,6 +56,9 @@ We recommend using a Linux or MacOS runner if possible.
are: “error”, “warn”, “info”, “debug”, “trace”.
- `setup`: - *optional*. Which docker_setup_strategy for creating the
container to use \[Docker Engine only\].
- `project_directory`: - *optional*. Path to the project directory. This
is the directory where the project’s `_viash.yaml` file is located. If
not provided, the current working directory is used.

### Outputs

Expand Down
8 changes: 8 additions & 0 deletions ns-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ inputs:
description: 'Filter which components get selected by component name. Can be a
regex. Example: "^component1".'
required: false
config:
description: Filter which component get selected by specifying the config path.
required: false
src:
description: 'A source directory containing viash config files, possibly structured
in a hierarchical folder structure. Default: src/.'
Expand Down Expand Up @@ -61,6 +64,11 @@ inputs:
description: Which docker_setup_strategy for creating the container to use [Docker
Engine only].
required: false
project_directory:
description: Path to the project directory. This is the directory where the project's
`_viash.yaml` file is located. If not provided, the current working directory
is used.
required: false
outputs:
output:
description: The output of 'viash ns build'.
Expand Down
12 changes: 5 additions & 7 deletions ns-build/generate_yml.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ input_values <- sapply(selected_opts, function(opt) {
)
setNames(list(out), opt$name)
})
# workaround for viash 0.9.0-RC6, should be fixed in 0.9.0
if (!"platform" %in% names(input_values)) {
input_values$platform <- list(
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. Deprecated in Viash 0.9.0, will be removed in Viash 1.0.0.",
required = FALSE
)
}

input_values$project_directory <- list(
description = "Path to the project directory. This is the directory where the project's `_viash.yaml` file is located. If not provided, the current working directory is used.",
required = FALSE
)

out <- list(
name = schema$bannerCommand,
Expand Down
96 changes: 52 additions & 44 deletions ns-build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,67 @@ const core = require("@actions/core");
const exec = require("@actions/exec");

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

const options = {};
options.listeners = {
stdout: (data) => {
myOutput += data.toString();
},
stderr: (data) => {
myError += data.toString();
}
};
const options = {};
options.listeners = {
stdout: (data) => {
myOutput += data.toString();
core.info(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",
"runner", "engine", "parallel", "config_mod", "target", "setup"
]
const booleanInputs = ["parallel"]
const multilineInputs = ["config_mod"]
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 if (multilineInputs.indexOf(argName) >= 0) {
const values = core.getMultilineInput(argName)
return values.flatMap(function(value) {
return ["--" + argName, value];
})
// set up workdir
const workdir = core.getInput("project_directory");
if (workdir) {
options.cwd = workdir;
}

// fetch arguments for command
// skip "parallel"
// todo: can I extract these inputNames from the action.yml?
const inputNames = [
"query", "query_namespace", "query_name", "config", "src", "runner", "engine",
"platform", "parallel", "config_mod", "target", "setup"
]
const booleanInputs = ["parallel"]
const multilineInputs = ["config_mod"]
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 ["--" + argName, value];
return [];
}
})
let args = ["ns", "build"].concat(inputArgs);
} else if (multilineInputs.indexOf(argName) >= 0) {
const values = core.getMultilineInput(argName)
return values.flatMap(function(value) {
return ["--" + argName, value];
})
} else {
return ["--" + argName, value];
}
})
let args = ["ns", "build"].concat(inputArgs);

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

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

// pass output
core.setOutput("output", myOutput);
}

run();
19 changes: 8 additions & 11 deletions ns-list/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ We recommend using a Linux or MacOS runner if possible.
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”.
- `config`: - *optional*. Filter which component get selected by
specifying the config path.
- `src`: - *optional*. A source directory containing viash config files,
possibly structured in a hierarchical folder structure. Default: src/.
- `platform`: - *optional*. (viash \< 0.9.0) Use –runner and –engine
Expand Down Expand Up @@ -54,6 +56,9 @@ We recommend using a Linux or MacOS runner if possible.
- `parse_argument_groups`: - *optional*. DEPRECATED. This is now always
enabled. Whether or not to postprocess each component’s
argument_groups.
- `project_directory`: - *optional*. Path to the project directory. This
is the directory where the project’s `_viash.yaml` file is located. If
not provided, the current working directory is used.
- `output_file`: - *optional*. Path of a file to which the output will
be written. If not set, this action will create a file with a random
name in `RUNNER_TEMP`.
Expand All @@ -63,24 +68,16 @@ We recommend using a Linux or MacOS runner if possible.
- `output`: The output of the ‘viash ns list’ command, which is a list
of all of the components found. By default this will be a yaml, unless
the format argument was set to ‘json’.

- `output_file`: Path of a file to which the output was written (same as
\`inputs.output_file\`\`). We recommend using this property for
capturing the action’s output because there is a limit in the object
size that github actions can manage. Additionally, if you use this
property instead of a static file path, changing the location of the
output file will not require you to adjust settings for downstream
actions as well.

- `output_matrix`: Matrix of components. The matrix is a json array with
the following fields:

- name: The name of the component
- namespace: The namespace of the component
- full_name: The full name of the component
- config: The path to the config file of the component
- dir: The directory of the config file of the component
- main_script_type: The type of the main script of the component
- `output_matrix`: A simplified version of the output, which is a list
of components with fields ‘name’, ‘namespace’, ‘full_name’, ‘config’,
and ‘dir’.

## Usage

Expand Down
19 changes: 10 additions & 9 deletions ns-list/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ inputs:
description: 'Filter which components get selected by component name. Can be a
regex. Example: "^component1".'
required: false
config:
description: Filter which component get selected by specifying the config path.
required: false
src:
description: 'A source directory containing viash config files, possibly structured
in a hierarchical folder structure. Default: src/.'
Expand Down Expand Up @@ -58,6 +61,11 @@ inputs:
description: DEPRECATED. This is now always enabled. Whether or not to postprocess
each component's argument_groups.
required: false
project_directory:
description: Path to the project directory. This is the directory where the project's
`_viash.yaml` file is located. If not provided, the current working directory
is used.
required: false
output_file:
description: Path of a file to which the output will be written. If not set, this
action will create a file with a random name in `RUNNER_TEMP`.
Expand All @@ -75,15 +83,8 @@ outputs:
of the output file will not require you to adjust settings for downstream actions
as well.
output_matrix:
description: |
Matrix of components. The matrix is a json array with the following fields:

- name: The name of the component
- namespace: The namespace of the component
- full_name: The full name of the component
- config: The path to the config file of the component
- dir: The directory of the config file of the component
- main_script_type: The type of the main script of the component
description: A simplified version of the output, which is a list of components
with fields 'name', 'namespace', 'full_name', 'config', and 'dir'.
runs:
using: node20
main: index.js
Expand Down
Loading