Skip to content

Commit

Permalink
Merge pull request #42 from Serverless-Devs/zxy/fix-workflow
Browse files Browse the repository at this point in the history
fix: flow stuck when flow projects > 1 and diff
  • Loading branch information
zxypro1 authored May 13, 2024
2 parents 2faa191 + 9a553bc commit 3d6ec19
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 43 deletions.
2 changes: 1 addition & 1 deletion packages/credential/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/credential",
"version": "0.0.6-beta.1",
"version": "0.0.6",
"description": "credential for serverless-devs",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/engine",
"version": "0.1.2-beta.9",
"version": "0.1.2",
"description": "a engine lib for serverless-devs",
"main": "lib/index.js",
"scripts": {
Expand Down
7 changes: 5 additions & 2 deletions packages/engine/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createMachine, interpret } from 'xstate';
import { isEmpty, get, each, map, isFunction, has, uniqueId, filter, omit, includes, set, isNil, isUndefined, keys } from 'lodash';
import { isEmpty, get, each, map, isFunction, has, uniqueId, filter, omit, includes, set, isNil, isUndefined, keys, size } from 'lodash';
import { IStepOptions, IRecord, IStatus, IEngineOptions, IContext, IEngineError, STEP_STATUS } from './types';
import { getProcessTime, getCredential, stringify, getAllowFailure } from './utils';
import ParseSpec, { getInputs, ISpec, IHookType, IStep as IParseStep, IActionLevel } from '@serverless-devs/parse-spec';
Expand Down Expand Up @@ -597,10 +597,13 @@ class Engine {
*/
private async doSrc(item: IStepOptions, data: Record<string, any> = {}) {
// Extract command and projectName from the specification.
const { command = '', projectName } = this.spec;
const { command = '', projectName, yaml } = this.spec;

// Retrieve properties for the given project step.
const newInputs = await this.getProps(item);
// default '-y' when flow projects > 1 (workaround for inquirer bug)
const flowProject = yaml.useFlow ? filter(this.context.steps, o => o.flowId === item.flowId) : [item];
if (size(flowProject) > 1) newInputs.args.push('-y');

// Set component properties based on the provided data or the newly retrieved properties.
this.record.componentProps = isEmpty(data.pluginOutput) ? newInputs : data.pluginOutput;
Expand Down
2 changes: 1 addition & 1 deletion packages/load-application/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/load-application",
"version": "0.0.13-beta.6",
"version": "0.0.13",
"description": "load application for serverless-devs",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/load-component/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/load-component",
"version": "0.0.7-beta.4",
"version": "0.0.7",
"description": "request for serverless-devs",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/logger",
"version": "0.0.5-beta.2",
"version": "0.0.5",
"description": "",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/parse-spec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/parse-spec",
"version": "0.0.26-beta.3",
"version": "0.0.26",
"description": "a parse yaml spec lib for serverless-devs",
"main": "lib/index.js",
"scripts": {
Expand Down
57 changes: 26 additions & 31 deletions packages/parse-spec/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,38 +125,33 @@ class ParseSpec {
});
}
}
if (has(this.yaml.content, ENVIRONMENT_KEY)) {
const envPath: string = utils.getAbsolutePath(get(this.yaml.content, ENVIRONMENT_KEY), path.dirname(this.yaml.path));
const envYamlContent = utils.getYamlContent(envPath);
// 若存在环境变量,默认项目为devsProject
const devsProject = process.env.ALIYUN_DEVS_REMOTE_PROJECT_NAME;
const project = devsProject ? devsProject : get(this.yaml.content, 'name');
// env.yaml is not exist
if (isEmpty(envYamlContent)) {
this.options.logger.warnOnce(`Environment file [${envPath}] is not found, run without environment.`);
return {};
}
// default-env.json is not exist
if (!fs.existsSync(ENVIRONMENT_FILE_PATH)) {
this.options.logger.warnOnce(`Default env config file [${ENVIRONMENT_FILE_PATH}] is not found, run without environment.`);
return {};
}
const { environments } = envYamlContent;
const defaultEnvContent = require(ENVIRONMENT_FILE_PATH);
const defaultEnv = get(find(defaultEnvContent, { project: project }), 'default');
// project is not found in default-env.json
if (!defaultEnv) {
this.options.logger.warnOnce(`Default env is not set, run without environment.`);
return {};
}
const environment = find(environments, item => item.name === defaultEnv);
// default env is not found in env.yaml
if (isEmpty(environment)) {
this.options.logger.warnOnce(`Default env [${defaultEnv}] is not found, run without environment.`);
return {};
}
return { project, environment };
// default-env.json is not exist
if (!fs.existsSync(ENVIRONMENT_FILE_PATH)) {
return {};
}
// 若存在环境变量,默认项目为devsProject
const devsProject = process.env.ALIYUN_DEVS_REMOTE_PROJECT_NAME;
const project = devsProject ? devsProject : get(this.yaml.content, 'name');
const defaultEnvContent = require(ENVIRONMENT_FILE_PATH);
const defaultEnv = get(find(defaultEnvContent, { project: project }), 'default');
// project is not found in default-env.json
if (isEmpty(defaultEnv)) {
return {};
}
const envPath: string = utils.getAbsolutePath(get(this.yaml.content, ENVIRONMENT_KEY) || 'env.yaml', path.dirname(this.yaml.path));
const envYamlContent = utils.getYamlContent(envPath);
if (isEmpty(envYamlContent)) {
this.options.logger.warnOnce(`Environment file [${envPath}] is not found, run without environment.`);
return {};
}
const { environments } = envYamlContent;
const environment = find(environments, item => item.name === defaultEnv);
// default env is not found in env.yaml
if (isEmpty(environment)) {
this.options.logger.warnOnce(`Default env [${defaultEnv}] is not found, run without environment.`);
return {};
}
return { project, environment };
}
// specify --env
private doEnvWithSpecify() {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/utils",
"version": "0.0.14",
"version": "0.0.15",
"description": "utils for serverless-devs",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/get-yaml-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function getYamlContent(filePath: string): Record<string, any> {
let message = `${filename} format is incorrect`;
if (error.message) message += `: ${error.message}`;
throw new DevsError(message, {
tips: `Please check the configuration of ${filename}, Serverless Devs' Yaml specification document can refer to:'https://github.com/Serverless-Devs/Serverless-Devs/blob/master/docs/zh/yaml.md'`,
tips: `Please check the configuration of ${filename}, Serverless Devs' Yaml specification document can refer to:'https://docs.serverless-devs.com/user-guide/spec/'`,
trackerType: ETrackerType.parseException,
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/is-debug-mode.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import minimist from 'minimist';

const isDebugMode = () => {
const isDebugMode = (): boolean => {
if (process.env.DEBUG === 'true') return true;
const args = minimist(process.argv.slice(2));
return args.debug;
return args.debug ?? false;
};

export default isDebugMode;

0 comments on commit 3d6ec19

Please sign in to comment.