-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
150 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Docker Image CI | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
|
||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v2 | ||
- name: build and push | ||
uses: docker/build-push-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: "vforwater" | ||
password: ${{ secrets.PAT }} | ||
repository: vforwater/tbr_template_node | ||
tags: latest,${{ github.ref_name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
A,B,C,D | ||
3,14,10,17 | ||
2,0,2,24 | ||
2,17,19,24 | ||
3,13,1,18 | ||
13,13,7,10 | ||
10,7,13,14 | ||
12,12,9,5 | ||
16,24,3,16 | ||
11,3,2,14 | ||
19,4,5,20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Created by Octave 6.4.0, Thu Oct 27 08:57:13 2022 UTC <root@b3d554c31921> | ||
# name: foo_matrix | ||
# type: matrix | ||
# rows: 3 | ||
# columns: 2 | ||
1 2 | ||
3 4 | ||
5 6.0999999999999996 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
{ | ||
"foobar": { | ||
"foo_int": "42", | ||
"foo_str": "Foobar" | ||
"foo_int": 42, | ||
"foo_float": 13.37, | ||
"foo_string": "Never eat yellow snow", | ||
"foo_enum": "bar", | ||
"foo_array": [34, 55, 23, 43, 23], | ||
"foo_matrix": "/in/foo_matrix.dat", | ||
"foo_csv": "/in/foo_csv.csv" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,80 @@ | ||
const { PARAM_FILE, CONF_FILE } = process.env; | ||
const { PARAM_FILE, CONF_FILE, TOOL_RUN } = process.env; | ||
const fs = require('fs'); | ||
const yaml = require('js-yaml'); | ||
const papa = require('papaparse'); | ||
|
||
const getParameter = () => { | ||
// load parameters file | ||
const params = require(PARAM_FILE || '/in/parameters.json'); | ||
|
||
return params; | ||
// if no tool name was passed, return first configured tool | ||
const toolName = TOOL_RUN ? TOOL_RUN : Object.keys(params)[0] | ||
|
||
// load the yaml file | ||
const config = yaml.load(fs.readFileSync(CONF_FILE || '/src/tool.yml')) | ||
const toolConf = config['tools'][toolName] | ||
|
||
// create the kwargs | ||
const kwargs = {} | ||
|
||
// foreach param passed | ||
Object.entries(params[toolName]).forEach(([key, val]) => { | ||
// get the param conf | ||
const parConf = toolConf[key] | ||
|
||
// if it is not specified, add anyway | ||
if (!parConf) { | ||
kwargs[key] = val | ||
} else { | ||
// parse dates | ||
if (['date', 'time', 'datetime'].includes(parConf['type'].toLowerCase())) { | ||
kwargs[key] = new Date(val) | ||
} | ||
|
||
if (parConf['type'] === 'file') { | ||
ext = val.split('.').pop().toLowerCase() | ||
|
||
// switch the file extension | ||
// json | ||
if (ext === 'json') { | ||
kwargs[key] = require(val) | ||
} | ||
|
||
// dat | ||
else if (ext === 'dat') { | ||
raw = fs.readFileSync(val) | ||
const dat = [] | ||
raw.split('\n').forEach(line => { | ||
if (!line.startsWith('#')) { | ||
dat.push(line.split(' ')) | ||
} | ||
}) | ||
|
||
// add data | ||
kwargs[key] = dat | ||
|
||
} | ||
|
||
// read csv data | ||
else if (ext === 'csv') { | ||
// | ||
raw = fs.readFileSync(val).split('\n') | ||
const recs = papa.parse(raw, {header: true}) | ||
|
||
// add | ||
kwargs[key] = recs | ||
} | ||
|
||
// else the tool should handle it | ||
else { | ||
// pass the file path anyway, because we don't know this file | ||
kwargs[key] = val | ||
} | ||
} | ||
} | ||
}) | ||
|
||
return kwargs; | ||
} | ||
|
||
module.exports = getParameter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,25 @@ | ||
tools: | ||
foobar: | ||
title: Foobar function | ||
description: Dummy default function of a toolbox template | ||
version: 1.0 | ||
title: Foo Bar | ||
description: A dummy tool to exemplify the YAML file | ||
version: 0.1 | ||
parameters: | ||
foo_int: | ||
foo_int: | ||
type: integer | ||
foo_str: | ||
type: string | ||
foo_float: | ||
type: float | ||
foo_string: | ||
type: string | ||
foo_enum: | ||
type: enum | ||
values: | ||
- foo | ||
- bar | ||
- baz | ||
foo_array: | ||
type: integer | ||
array: true | ||
foo_matrix: | ||
type: file | ||
foo_csv: | ||
type: file |