feat(input): support json schema path as an absolute path (#393)
* feat(input): support json schema path as an absolute path * update documentation
This commit is contained in:
@@ -40,6 +40,7 @@ Your Speckle Token must have write permissions for the Speckle Function with thi
|
||||
#### `speckle_function_input_schema_file_path`
|
||||
|
||||
*Optional.* The path to the JSON Schema file that describes the input schema for this version of the Speckle Function. This file is used to define the input form that will be presented to users when they compose an Automation based on this Function. If not provided, no input form will be presented to users.
|
||||
This can be an absolute path, or a path relative to the Home directory of the GitHub Action runner.
|
||||
|
||||
#### `speckle_function_command`
|
||||
|
||||
|
||||
+9
-5
@@ -38280,12 +38280,16 @@ const parseInputs = () => {
|
||||
const speckleTokenRaw = core.getInput('speckle_token', { required: true });
|
||||
core.setSecret(speckleTokenRaw);
|
||||
const rawInputSchemaPath = core.getInput('speckle_function_input_schema_file_path');
|
||||
const homeDir = process.env['HOME'];
|
||||
if (!homeDir)
|
||||
throw new Error('The home directory is not defined, cannot load inputSchema');
|
||||
let rawInputSchemaPathAbsolute = rawInputSchemaPath;
|
||||
if (!(0,external_node_path_.isAbsolute)(rawInputSchemaPath)) {
|
||||
const homeDir = process.env['HOME'];
|
||||
if (!homeDir)
|
||||
throw new Error('The home directory is not defined, cannot load inputSchema');
|
||||
rawInputSchemaPathAbsolute = (0,external_node_path_.join)(homeDir, rawInputSchemaPath);
|
||||
}
|
||||
let speckleFunctionInputSchema = null;
|
||||
if (rawInputSchemaPath) {
|
||||
const rawInputSchema = (0,external_node_fs_.readFileSync)((0,external_node_path_.join)(homeDir, rawInputSchemaPath), 'utf-8');
|
||||
if (rawInputSchemaPathAbsolute) {
|
||||
const rawInputSchema = (0,external_node_fs_.readFileSync)(rawInputSchemaPathAbsolute, 'utf-8');
|
||||
speckleFunctionInputSchema = JSON.parse(rawInputSchema);
|
||||
}
|
||||
const rawInputs = {
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+12
-6
@@ -3,7 +3,7 @@ import { ZodError, z } from 'zod'
|
||||
import fetch from 'node-fetch'
|
||||
import { retry } from '@lifeomic/attempt'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { isAbsolute, join } from 'node:path'
|
||||
|
||||
const InputVariablesSchema = z.object({
|
||||
speckleAutomateUrl: z.string().url().min(1),
|
||||
@@ -40,12 +40,18 @@ const parseInputs = (): InputVariables => {
|
||||
core.setSecret(speckleTokenRaw)
|
||||
|
||||
const rawInputSchemaPath = core.getInput('speckle_function_input_schema_file_path')
|
||||
const homeDir = process.env['HOME']
|
||||
if (!homeDir)
|
||||
throw new Error('The home directory is not defined, cannot load inputSchema')
|
||||
|
||||
let rawInputSchemaPathAbsolute = rawInputSchemaPath
|
||||
if (!isAbsolute(rawInputSchemaPath)) {
|
||||
const homeDir = process.env['HOME']
|
||||
if (!homeDir)
|
||||
throw new Error('The home directory is not defined, cannot load inputSchema')
|
||||
rawInputSchemaPathAbsolute = join(homeDir, rawInputSchemaPath)
|
||||
}
|
||||
|
||||
let speckleFunctionInputSchema: Record<string, unknown> | null = null
|
||||
if (rawInputSchemaPath) {
|
||||
const rawInputSchema = readFileSync(join(homeDir, rawInputSchemaPath), 'utf-8')
|
||||
if (rawInputSchemaPathAbsolute) {
|
||||
const rawInputSchema = readFileSync(rawInputSchemaPathAbsolute, 'utf-8')
|
||||
speckleFunctionInputSchema = JSON.parse(rawInputSchema)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user