From b060030d09d33dbcbf1f6c2e03001ea26ae3edb7 Mon Sep 17 00:00:00 2001 From: wss-git Date: Thu, 12 Jan 2023 10:59:51 +0800 Subject: [PATCH 1/2] feat: version puhblish support --ignore-no-chang-error Signed-off-by: wss-git --- src/lib/component/version.ts | 10 +++++++--- src/lib/help/version.ts | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/component/version.ts b/src/lib/component/version.ts index a091e6db..ff34a1f5 100644 --- a/src/lib/component/version.ts +++ b/src/lib/component/version.ts @@ -13,10 +13,12 @@ interface IProps { description?: string; versionId?: string; assumeYes?: boolean; + ignoreNoChangError?: boolean; } interface Publish { serviceName: string; description?: string; + ignoreNoChangError?: boolean; } interface Remove { serviceName: string; @@ -38,7 +40,7 @@ export default class Version { logger.debug(`inputs.props: ${JSON.stringify(inputs.props)}`); const parsedArgs: { [key: string]: any } = core.commandParse(inputs, { - boolean: ['help', 'table', 'y'], + boolean: ['help', 'table', 'y', 'ignore-no-chang-error'], string: ['region', 'service-name', 'description', 'id'], alias: { help: 'h', 'version-id': 'id', 'assume-yes': 'y' }, }); @@ -70,6 +72,7 @@ export default class Version { description: parsedData.description, versionId: parsedData.id, assumeYes: parsedData.y, + ignoreNoChangError: parsedData['ignore-no-chang-error'], }; if (!endProps.region) { @@ -107,9 +110,10 @@ export default class Version { } } - async publish({ serviceName, description }: Publish) { + async publish({ serviceName, description, ignoreNoChangError }: Publish) { logger.info(`Creating service version: ${serviceName}`); - const { data } = await Client.fcClient.publishVersion(serviceName, description); + const headers = ignoreNoChangError ? { 'x-fc-ignore-version-publish-error': 'true' } : {}; + const { data } = await Client.fcClient.publishVersion(serviceName, description, headers); logger.debug(`publish version: ${JSON.stringify(data)}`); return data; } diff --git a/src/lib/help/version.ts b/src/lib/help/version.ts index 7a5edad8..4d3a5b5f 100644 --- a/src/lib/help/version.ts +++ b/src/lib/help/version.ts @@ -83,6 +83,11 @@ export const VERSION_PUBLISH = [ description: '[Optional] Specify the alias description', type: String, }, + { + name: 'ignore-no-chang-error', + description: '[Optional] Ignore no changes were made since last publish', + type: String, + }, ], }, { ...globalParams }, From 23a214414674861ed4f798990c9b6ab93379874c Mon Sep 17 00:00:00 2001 From: wss-git Date: Thu, 12 Jan 2023 11:11:36 +0800 Subject: [PATCH 2/2] docs: version publish Signed-off-by: wss-git --- docs/zh/command/version.md | 46 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/docs/zh/command/version.md b/docs/zh/command/version.md index 22e7d32b..1e4a2d60 100644 --- a/docs/zh/command/version.md +++ b/docs/zh/command/version.md @@ -23,7 +23,6 @@ category: '发布&配置' 当执行命令`version -h`/`version --help`时,可以获取帮助文档。 - 在该命令中,包括了两个子命令: - [list:查看版本列表](#version-list-命令) @@ -37,11 +36,11 @@ category: '发布&配置' ### 参数解析 -| 参数全称 | 参数缩写 | Yaml模式下必填 | Cli模式下必填 | 参数含义 | -| ------------ | -------- | -------------- | ------------- | ------------------------------------------------------------ | -| region | - | 选填 | 必填 | 地区,取值范围:`cn-hangzhou, cn-beijing, cn-beijing, cn-hangzhou, cn-shanghai, cn-qingdao, cn-zhangjiakou, cn-huhehaote, cn-shenzhen, cn-chengdu, cn-hongkong, ap-southeast-1, ap-southeast-2, ap-southeast-3, ap-southeast-5, ap-northeast-1, eu-central-1, eu-west-1, us-west-1, us-east-1, ap-south-1` | -| service-name | - | 选填 | 必填 | 服务名 | -| table | - | 选填 | 选填 | 是否以表格形式输出 | +| 参数全称 | 参数缩写 | Yaml 模式下必填 | Cli 模式下必填 | 参数含义 | +| ------------ | -------- | --------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| region | - | 选填 | 必填 | 地区,取值范围:`cn-hangzhou, cn-beijing, cn-beijing, cn-hangzhou, cn-shanghai, cn-qingdao, cn-zhangjiakou, cn-huhehaote, cn-shenzhen, cn-chengdu, cn-hongkong, ap-southeast-1, ap-southeast-2, ap-southeast-3, ap-southeast-5, ap-northeast-1, eu-central-1, eu-west-1, us-west-1, us-east-1, ap-south-1` | +| service-name | - | 选填 | 必填 | 服务名 | +| table | - | 选填 | 选填 | 是否以表格形式输出 | > 当前命令还支持部分全局参数(例如`-a/--access`, `--debug`等),详情可参考 [Serverless Devs 全局参数文档](https://serverless-devs.com/serverless-devs/command/readme#全局参数) @@ -53,8 +52,8 @@ category: '发布&配置' 上述命令的执行结果示例: ```text -fc-deploy-test: - - +fc-deploy-test: + - versionId: 1 description: test publish version createdTime: 2021-11-08T06:07:00Z @@ -71,7 +70,6 @@ fc-deploy-test: └───────────┴──────────────────────┴──────────────────────┴──────────────────────┘ ``` - ## version publish 命令 `version publish` 命令,是用于发布版本的命令。 @@ -80,11 +78,12 @@ fc-deploy-test: ### 参数解析 -| 参数全称 | 参数缩写 | Yaml模式下必填 | Cli模式下必填 | 参数含义 | -| ------------ | -------- | -------------- | ------------- | ------------------------------------------------------------ | -| region | - | 选填 | 必填 | 地区,取值范围:`cn-hangzhou, cn-beijing, cn-beijing, cn-hangzhou, cn-shanghai, cn-qingdao, cn-zhangjiakou, cn-huhehaote, cn-shenzhen, cn-chengdu, cn-hongkong, ap-southeast-1, ap-southeast-2, ap-southeast-3, ap-southeast-5, ap-northeast-1, eu-central-1, eu-west-1, us-west-1, us-east-1, ap-south-1` | -| service-name | - | 选填 | 必填 | 服务名 | -| description | - | 选填 | 选填 | 版本描述 | +| 参数全称 | 参数缩写 | Yaml 模式下必填 | Cli 模式下必填 | 参数含义 | +| --------------------- | -------- | --------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| region | - | 选填 | 必填 | 地区,取值范围:`cn-hangzhou, cn-beijing, cn-beijing, cn-hangzhou, cn-shanghai, cn-qingdao, cn-zhangjiakou, cn-huhehaote, cn-shenzhen, cn-chengdu, cn-hongkong, ap-southeast-1, ap-southeast-2, ap-southeast-3, ap-southeast-5, ap-northeast-1, eu-central-1, eu-west-1, us-west-1, us-east-1, ap-south-1` | +| service-name | - | 选填 | 必填 | 服务名 | +| description | - | 选填 | 选填 | 版本描述 | +| ignore-no-chang-error | - | 选填 | 选填 | 忽略发布版本 `No changes were made since last publish`异常 | > 当前命令还支持部分全局参数(例如`-a/--access`, `--debug`等),详情可参考 [Serverless Devs 全局参数文档](https://serverless-devs.com/serverless-devs/command/readme#全局参数) @@ -96,7 +95,7 @@ fc-deploy-test: 上述命令的执行结果示例: ```text -fc-deploy-test: +fc-deploy-test: versionId: 1 description: test publish version createdTime: 2021-11-08T06:07:00Z @@ -111,13 +110,14 @@ fc-deploy-test: ```yaml { - "Version": "1", - "Statement": [ - { - "Action": "fc:PublishServiceVersion", - "Effect": "Allow", - "Resource": "acs:fc:::services//versions" - } - ] + 'Version': '1', + 'Statement': + [ + { + 'Action': 'fc:PublishServiceVersion', + 'Effect': 'Allow', + 'Resource': 'acs:fc:::services//versions', + }, + ], } ```