4 Commits

Author SHA1 Message Date
Gergő Jedlicska 5462de9d2d functionReleaseTag as an input 2023-09-22 11:35:15 +02:00
Gergő Jedlicska ea219ded92 feat: use shorthened git commit id, change output variable to version tag 2023-09-18 17:26:12 +02:00
Gergő Jedlicska 4599eff830 explicitly read from the home directory 2023-08-11 16:04:42 +02:00
Gergő Jedlicska 352365220a move to a file based function input 2023-08-10 17:03:40 +02:00
5 changed files with 93 additions and 59 deletions
+2 -2
View File
@@ -15,8 +15,8 @@ inputs:
speckle_function_id:
description: 'The unique identifier of the function. Go to automate to generate one.'
required: true
speckle_function_input_schema:
description: 'JSON Schema of the parameters object required by the function.'
speckle_function_input_schema_file_path:
description: 'File path containing JSON Schema of the parameters object required by the function.'
required: false
speckle_function_command:
description: 'The command to run to execute the function in a runtime environment.'
Generated Vendored
+1 -1
View File
@@ -9,7 +9,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "toFormData": () => (/* binding */ toFormData)
/* harmony export */ });
/* harmony import */ var fetch_blob_from_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2777);
/* harmony import */ var fetch_blob_from_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2185);
/* harmony import */ var formdata_polyfill_esm_min_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8010);
Generated Vendored
+58 -39
View File
@@ -7137,6 +7137,20 @@ module.exports = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("net");
/***/ }),
/***/ 7561:
/***/ ((module) => {
module.exports = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs");
/***/ }),
/***/ 9411:
/***/ ((module) => {
module.exports = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:path");
/***/ }),
/***/ 7742:
/***/ ((module) => {
@@ -7305,28 +7319,18 @@ const File = _File
/***/ }),
/***/ 2777:
/***/ 2185:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => {
// EXPORTS
__nccwpck_require__.d(__webpack_exports__, {
"$B": () => (/* reexport */ file/* default */.Z)
});
// UNUSED EXPORTS: Blob, blobFrom, blobFromSync, default, fileFrom, fileFromSync
;// CONCATENATED MODULE: external "node:fs"
const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs");
;// CONCATENATED MODULE: external "node:path"
const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:path");
// EXTERNAL MODULE: ./node_modules/node-domexception/index.js
var node_domexception = __nccwpck_require__(7760);
// EXTERNAL MODULE: ./node_modules/fetch-blob/file.js
var file = __nccwpck_require__(3213);
// EXTERNAL MODULE: ./node_modules/fetch-blob/index.js
var fetch_blob = __nccwpck_require__(1410);
;// CONCATENATED MODULE: ./node_modules/fetch-blob/from.js
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
/* harmony export */ "$B": () => (/* reexport safe */ _file_js__WEBPACK_IMPORTED_MODULE_3__.Z)
/* harmony export */ });
/* unused harmony exports blobFrom, blobFromSync, fileFrom, fileFromSync */
/* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(7561);
/* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(9411);
/* harmony import */ var node_domexception__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(7760);
/* harmony import */ var _file_js__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(3213);
/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(1410);
@@ -7334,7 +7338,7 @@ var fetch_blob = __nccwpck_require__(1410);
const { stat } = external_node_fs_namespaceObject.promises
const { stat } = node_fs__WEBPACK_IMPORTED_MODULE_0__.promises
/**
* @param {string} path filepath on the disk
@@ -7425,7 +7429,7 @@ class BlobDataItem {
}
}
/* harmony default export */ const from = ((/* unused pure expression or super */ null && (blobFromSync)));
/* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = ((/* unused pure expression or super */ null && (blobFromSync)));
@@ -13594,8 +13598,8 @@ class AbortError extends FetchBaseError {
}
}
// EXTERNAL MODULE: ./node_modules/fetch-blob/from.js + 2 modules
var from = __nccwpck_require__(2777);
// EXTERNAL MODULE: ./node_modules/fetch-blob/from.js
var from = __nccwpck_require__(2185);
;// CONCATENATED MODULE: ./node_modules/node-fetch/src/index.js
/**
* Index.js
@@ -14010,26 +14014,38 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
// EXTERNAL MODULE: ./node_modules/@lifeomic/attempt/dist/src/index.js
var src = __nccwpck_require__(6494);
// EXTERNAL MODULE: external "node:fs"
var external_node_fs_ = __nccwpck_require__(7561);
// EXTERNAL MODULE: external "node:path"
var external_node_path_ = __nccwpck_require__(9411);
;// CONCATENATED MODULE: ./src/main.ts
const InputVariablesSchema = z.object({
speckleAutomateUrl: z.string().url().nonempty(),
speckleToken: z.string().nonempty(),
speckleFunctionId: z.string().nonempty(),
speckleFunctionInputSchema: z.record(z.string().nonempty(), z.unknown()).nullable(),
speckleFunctionCommand: z.string().nonempty().array()
speckleFunctionCommand: z.string().nonempty().array(),
speckleFunctionReleaseTag: z.string().max(10).nonempty()
});
const parseInputs = () => {
const speckleTokenRaw = core.getInput('speckle_token', { required: true });
core.setSecret(speckleTokenRaw);
let speckleFunctionInputSchema = null;
try {
const rawInputSchema = core.getInput('speckle_function_input_schema');
if (rawInputSchema)
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');
if (rawInputSchemaPath) {
const rawInputSchema = (0,external_node_fs_.readFileSync)((0,external_node_path_.join)(homeDir, rawInputSchemaPath), 'utf-8');
speckleFunctionInputSchema = JSON.parse(rawInputSchema);
}
}
catch (err) {
core.setFailed(`Parsing the function input schema failed with: ${err}`);
@@ -14041,7 +14057,10 @@ const parseInputs = () => {
speckleFunctionId: core.getInput('speckle_function_id', { required: true }),
speckleFunctionInputSchema,
speckleFunctionCommand: core.getInput('speckle_function_command', { required: true })
.split(' ')
.split(' '),
speckleFunctionReleaseTag: core.getInput('speckle_function_release_tag', {
required: true
})
};
const inputParseResult = InputVariablesSchema.safeParse(rawInputs);
if (inputParseResult.success)
@@ -14050,15 +14069,11 @@ const parseInputs = () => {
throw inputParseResult.error;
};
const RequiredEnvVarsSchema = z.object({
gitRefName: z.string().nonempty(),
gitRefType: z.string().nonempty(),
gitCommitSha: z.string().nonempty()
});
const parseEnvVars = () => {
const parseResult = RequiredEnvVarsSchema.safeParse({
gitCommitSha: process.env.GITHUB_SHA,
gitRefType: process.env.GITHUB_REF_TYPE,
gitRefName: process.env.GITHUB_REF_NAME
gitCommitSha: process.env.GITHUB_SHA
});
if (parseResult.success)
return parseResult.data;
@@ -14068,11 +14083,13 @@ const parseEnvVars = () => {
const FunctionVersionResponseBodySchema = z.object({
versionId: z.string().nonempty()
});
const registerNewVersionForTheSpeckleAutomateFunction = async ({ speckleAutomateUrl, speckleFunctionCommand, speckleFunctionId, speckleFunctionInputSchema, speckleToken }, { gitCommitSha, gitRefName, gitRefType }) => {
const registerNewVersionForTheSpeckleAutomateFunction = async ({ speckleAutomateUrl, speckleFunctionCommand, speckleFunctionId, speckleFunctionInputSchema, speckleToken, speckleFunctionReleaseTag }, commitId
// { gitCommitSha, gitRefName, gitRefType }: RequiredEnvVars
) => {
try {
const requestBody = {
commitId: gitCommitSha,
versionTag: gitRefType === 'tag' ? gitRefName : gitCommitSha,
commitId,
versionTag: speckleFunctionReleaseTag,
command: speckleFunctionCommand,
inputSchema: speckleFunctionInputSchema
};
@@ -14120,13 +14137,15 @@ async function run() {
const inputVariables = parseInputs();
core.info(`Parsed input variables to: ${JSON.stringify(inputVariables)}`);
const requiredEnvVars = parseEnvVars();
const { gitCommitSha } = requiredEnvVars;
core.info(`Parsed required environment variables to: ${JSON.stringify(requiredEnvVars)}`);
const { speckleAutomateUrl, speckleFunctionId } = inputVariables;
core.setOutput('speckle_automate_host', new URL(speckleAutomateUrl).host);
core.info(`Sending a new function version definition for function ${speckleFunctionId} to the automate server: ${speckleAutomateUrl}`);
const { versionId } = await registerNewVersionForTheSpeckleAutomateFunction(inputVariables, requiredEnvVars);
core.setOutput('version_id', versionId);
core.info(`Registered function version with new id: ${versionId}`);
// github uses 7 chars to identify commits
const commitId = gitCommitSha.substring(0, 7);
const { versionId } = await registerNewVersionForTheSpeckleAutomateFunction(inputVariables, commitId);
core.info(`Registered function version tagged as ${inputVariables.speckleFunctionReleaseTag} with new id: ${versionId}`);
}
run();
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+31 -16
View File
@@ -2,13 +2,16 @@ import * as core from '@actions/core'
import { z } from 'zod'
import fetch from 'node-fetch'
import { retry } from '@lifeomic/attempt'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
const InputVariablesSchema = z.object({
speckleAutomateUrl: z.string().url().nonempty(),
speckleToken: z.string().nonempty(),
speckleFunctionId: z.string().nonempty(),
speckleFunctionInputSchema: z.record(z.string().nonempty(), z.unknown()).nullable(),
speckleFunctionCommand: z.string().nonempty().array()
speckleFunctionCommand: z.string().nonempty().array(),
speckleFunctionReleaseTag: z.string().max(10).nonempty()
})
type InputVariables = z.infer<typeof InputVariablesSchema>
@@ -19,8 +22,14 @@ const parseInputs = (): InputVariables => {
let speckleFunctionInputSchema: Record<string, unknown> | null = null
try {
const rawInputSchema = core.getInput('speckle_function_input_schema')
if (rawInputSchema) speckleFunctionInputSchema = JSON.parse(rawInputSchema)
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')
if (rawInputSchemaPath) {
const rawInputSchema = readFileSync(join(homeDir, rawInputSchemaPath), 'utf-8')
speckleFunctionInputSchema = JSON.parse(rawInputSchema)
}
} catch (err) {
core.setFailed(`Parsing the function input schema failed with: ${err}`)
throw err
@@ -32,7 +41,10 @@ const parseInputs = (): InputVariables => {
speckleFunctionInputSchema,
speckleFunctionCommand: core
.getInput('speckle_function_command', { required: true })
.split(' ')
.split(' '),
speckleFunctionReleaseTag: core.getInput('speckle_function_release_tag', {
required: true
})
}
const inputParseResult = InputVariablesSchema.safeParse(rawInputs)
if (inputParseResult.success) return inputParseResult.data
@@ -43,8 +55,6 @@ const parseInputs = (): InputVariables => {
}
const RequiredEnvVarsSchema = z.object({
gitRefName: z.string().nonempty(),
gitRefType: z.string().nonempty(),
gitCommitSha: z.string().nonempty()
})
@@ -52,9 +62,7 @@ type RequiredEnvVars = z.infer<typeof RequiredEnvVarsSchema>
const parseEnvVars = (): RequiredEnvVars => {
const parseResult = RequiredEnvVarsSchema.safeParse({
gitCommitSha: process.env.GITHUB_SHA,
gitRefType: process.env.GITHUB_REF_TYPE,
gitRefName: process.env.GITHUB_REF_NAME
gitCommitSha: process.env.GITHUB_SHA
} as RequiredEnvVars)
if (parseResult.success) return parseResult.data
core.setFailed(
@@ -82,14 +90,16 @@ const registerNewVersionForTheSpeckleAutomateFunction = async (
speckleFunctionCommand,
speckleFunctionId,
speckleFunctionInputSchema,
speckleToken
speckleToken,
speckleFunctionReleaseTag
}: InputVariables,
{ gitCommitSha, gitRefName, gitRefType }: RequiredEnvVars
commitId: string
// { gitCommitSha, gitRefName, gitRefType }: RequiredEnvVars
): Promise<FunctionVersionResponseBody> => {
try {
const requestBody: FunctionVersionRequestBody = {
commitId: gitCommitSha,
versionTag: gitRefType === 'tag' ? gitRefName : gitCommitSha,
commitId,
versionTag: speckleFunctionReleaseTag,
command: speckleFunctionCommand,
inputSchema: speckleFunctionInputSchema
}
@@ -148,6 +158,7 @@ export async function run(): Promise<void> {
const inputVariables = parseInputs()
core.info(`Parsed input variables to: ${JSON.stringify(inputVariables)}`)
const requiredEnvVars = parseEnvVars()
const { gitCommitSha } = requiredEnvVars
core.info(
`Parsed required environment variables to: ${JSON.stringify(requiredEnvVars)}`
)
@@ -158,12 +169,16 @@ export async function run(): Promise<void> {
`Sending a new function version definition for function ${speckleFunctionId} to the automate server: ${speckleAutomateUrl}`
)
// github uses 7 chars to identify commits
const commitId = gitCommitSha.substring(0, 7)
const { versionId } = await registerNewVersionForTheSpeckleAutomateFunction(
inputVariables,
requiredEnvVars
commitId
)
core.info(
`Registered function version tagged as ${inputVariables.speckleFunctionReleaseTag} with new id: ${versionId}`
)
core.setOutput('version_id', versionId)
core.info(`Registered function version with new id: ${versionId}`)
}
run()