Skip to content

Commit

Permalink
Merge pull request #84 from Serverless-Devs/develop
Browse files Browse the repository at this point in the history
pre 0.1.42
  • Loading branch information
heimanba authored Jul 1, 2022
2 parents c80466c + 1d29168 commit bb14bca
Show file tree
Hide file tree
Showing 16 changed files with 1,665 additions and 1,478 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ release-dev: push
-gh release delete dev -y
-git tag -d dev
-git push origin :refs/tags/dev
gh release create 0.1.36-beta.14 --notes "dev release" --target develop --title "Release dev" --prerelease
gh release create 0.1.42-beta.1 --notes "dev release" --target develop --title "Release dev" --prerelease

roll-back-dev:
git reset --soft HEAD~1
Expand Down
2,900 changes: 1,533 additions & 1,367 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/core",
"version": "0.1.41",
"version": "0.1.42",
"description": "Serverless Devs Tool Core Component",
"keywords": [
"Serverless",
Expand Down Expand Up @@ -75,7 +75,6 @@
"@serverless-devs/got": "^8.3.2",
"@serverless-devs/s-progress-bar": "^0.0.8",
"ansi-escapes": "^4.3.2",
"archive-type": "^4.0.0",
"archiver": "^5.3.0",
"art-template": "^4.13.2",
"chalk": "^4.1.0",
Expand All @@ -86,7 +85,6 @@
"execa": "^5.1.1",
"extend2": "^1.0.1",
"fs-extra": "^9.1.0",
"get-stream": "^4.1.0",
"getmac": "^5.20.0",
"ignore": "^5.1.8",
"inquirer": "^8.2.0",
Expand All @@ -97,7 +95,6 @@
"minimatch": "^5.0.0",
"minimist": "^1.2.6",
"ora": "^5.3.0",
"p-event": "^2.1.0",
"prettyjson": "^1.2.1",
"readline": "^1.3.0",
"rimraf": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Component
Name: core
Provider:
- 阿里云
Version: 0.1.41
Version: 0.1.42
Description: Serverless Devs 核心组件
HomePage: https://github.com/Serverless-Devs/core
Tags: #标签详情
Expand Down
6 changes: 4 additions & 2 deletions src/common/execCommand/getTemplatePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ async function isYamlFile(filePath: string) {
}
try {
await yaml.load(fs.readFileSync(filePath, 'utf8'));
} catch (error) {
} catch (error /* YAMLException */) {
const filename = path.basename(filePath);
let message = `${filename} format is incorrect`;
if (error.message) message += `: ${error.message}`;
throw new Error(
JSON.stringify({
message: `${filename} format is incorrect`,
message,
tips: `Please check the configuration of ${filename}, Serverless Devs' Yaml specification document can refer to:${chalk.underline(
'https://github.com/Serverless-Devs/Serverless-Devs/blob/master/docs/zh/yaml.md',
)}`,
Expand Down
6 changes: 6 additions & 0 deletions src/common/execCommand/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { getProjectConfig } from './utils';
import { getTemplatePath, transforYamlPath } from './getTemplatePath';
import ComponentExec from './component';
import { IGlobalArgs } from './interface';
import { execDaemon } from '../../execDaemon';
import { useLocal } from '../../libs';

interface IConfigs {
syaml?: string;
Expand Down Expand Up @@ -41,6 +43,10 @@ class ExecCommand {
await this.warnEnvironmentVariables(parsedObj.realVariables);
const analysis = new Analysis(parsedObj.realVariables, parsedObj.dependenciesMap);
const executeOrderList = analysis.getProjectOrder();
// 私有化部署不在进行上报数据
if (!useLocal()) {
execDaemon('reportTracker.js', { syaml: spath });
}
// 只有一个服务,或者指定服务操作
if (executeOrderList.length === 1 || serverName) {
const tempCustomerCommandName = executeOrderList[0];
Expand Down
27 changes: 27 additions & 0 deletions src/common/getAccountByAccess.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ALIYUN_CLI } from './constant';
import { getCredential, getCredentialFromEnv } from './credential';
import path from 'path';
import { getRootHome, getYamlContent } from '../libs';
import { get } from 'lodash';

const getAccountByAccess = async (access: string) => {
if (!access) return;
if (access === ALIYUN_CLI) {
return await getCredential(access);
}
const accessPath = path.join(getRootHome(), 'access.yaml');
const data = await getYamlContent(accessPath);

let credentials;
// 密钥存在 才去获取密钥信息
if (get(data, access)) {
credentials = await getCredential(access);
}
const accessFromEnv = await getCredentialFromEnv(access);
if (accessFromEnv) {
credentials = accessFromEnv;
}
return credentials;
};

export default getAccountByAccess;
1 change: 1 addition & 0 deletions src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export { default as modifyYaml } from './modifyYaml';
export * from './execCommand';
export * from './constant';
export { default as ignoreWalk } from './ignoreWalk';
export { default as getAccountByAccess } from './getAccountByAccess';
export { CatchableError } from './error';
3 changes: 2 additions & 1 deletion src/common/report.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execDaemon } from '../execDaemon';
import path from 'path';
import { getRootHome, getYamlContent } from '../libs';
import { getRootHome, getYamlContent, useLocal } from '../libs';

interface IConfig {
type: 'pv' | 'action' | 'jsError' | 'networkError' | 'initTemplate' | 'installError';
Expand All @@ -11,6 +11,7 @@ interface IConfig {
async function report(config: IConfig) {
const data = await getYamlContent(path.join(getRootHome(), 'set-config.yml'));
if (data?.analysis === 'disable') return;
if (useLocal()) return;
execDaemon('report.js', config);
}

Expand Down
2 changes: 1 addition & 1 deletion src/daemon/constant.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
DEFAULT_CORE_VERSION: '0.1.41',
DEFAULT_CORE_VERSION: '0.1.42',
};
51 changes: 51 additions & 0 deletions src/daemon/reportTracker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const {
got,
isDocker,
getCicdEnv,
getRootHome,
getCommand,
lodash: _,
getAccountByAccess,
getYamlContent,
} = require('../index');
const path = require('path');
const fs = require('fs');

async function init() {
const { CLI_VERSION, syaml } = process.env;
const core_version = await getCoreVersion();
const os = getCicdEnv() || process.platform;
const node_version = process.version;
const baseURL = 'http://cn-tracker.cn-heyuan.log.aliyuncs.com/logstores/serverless-devs/track';
let url = `${baseURL}?APIVersion=0.6.0&cli_version=${CLI_VERSION}&core_version=${core_version}&node_version=${node_version}&os=${os}&isDocker=${isDocker()}&trackerType=command`;
if (getCommand()) {
url = `${url}&trackerName=${getCommand()}`;
}
const mainUid = await getMainUid(syaml);
if (mainUid) {
url = `${url}&mainUid=${mainUid}`;
}
await got(url, { timeout: 3000 });
}

function getCoreVersion() {
const corePath = path.join(getRootHome(), 'cache', 'core', 'package.json');
return fs.existsSync(corePath) ? require(corePath).version : 'unknown';
}

async function getMainUid(syaml) {
try {
const data = await getYamlContent(syaml);
if (_.get(data, 'access')) {
const credentials = await getAccountByAccess(data.access);
return credentials.AccountID;
}
} catch (error) {}
}

(async () => {
await init();
process.exit();
})().catch(() => {
process.exit(1);
});
2 changes: 2 additions & 0 deletions src/execDaemon.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import { spawn } from 'child_process';
import { useLocal } from './libs';
import fs from 'fs-extra';
const TTL = 10 * 60 * 1000;

Expand Down Expand Up @@ -29,6 +30,7 @@ export function execDaemon(filename: string, config?: IConfig) {
}

export function execDaemonWithTTL(filename: string, config: IConfigWithTTL) {
if (useLocal()) return;
const { lockPath } = config;
const lockFileInfo = readJsonFile(lockPath);
const now = Date.now();
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export { default as minimatch } from 'minimatch';
export { default as archiver } from 'archiver';
export { default as tableLayout } from 'table-layout';
export { default as httpx } from 'httpx';
export { default as pEvent } from 'p-event';
export { default as got } from '@serverless-devs/got';
export { default as lodash } from 'lodash';
export { default as popCore } from '@alicloud/pop-core';
Expand Down
4 changes: 4 additions & 0 deletions src/libs/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export function isCiCdEnv() {
return includes(['cloud_shell', 'yunxiao', 'github', 'gitlab', 'jenkins'], getCicdEnv());
}

export function useLocal() {
return process.env.default_serverless_devs_registry_mode === 'local';
}

export function formatWorkspacePath(val: string) {
return val.replace(/~/, USER_HOME);
}
Expand Down
31 changes: 31 additions & 0 deletions test/common/execCommand/getTemplatePath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,35 @@ describe("transforYamlPath", () => {
}

});

it("should throws error when s.yaml contains duplicate key", (done) => {
fs.writeFileSync(s,
"\r\n" +
" default:\r\n" +
" props:\r\n" +
" function:\r\n" +
" environmentVariables:\r\n" +
" duplicate-key: value1\r\n" +
" duplicate-key: value2\r\n" +
"", {flag: "a" /* append */});

transforYamlPath(s)
.then(() => done("then() should not be invoked"))
.catch(error => {
let json = JSON.parse(error.message);
expect(json.message).toBeDefined();
expect(json.message).toContain("s.yaml format is incorrect");
expect(json.message).toContain("duplicated mapping key");
// s.yaml format is incorrect: duplicated mapping key (7:11)
//
// 4 | function:
// 5 | environmentVariables:
// 6 | duplicate-key: value1
// 7 | duplicate-key: value2
// ---------------^
// console.log(json.message);
expect(json.tips).toBeDefined();
done();
});
});
});
100 changes: 0 additions & 100 deletions test/fixtures/download.ts

This file was deleted.

0 comments on commit bb14bca

Please sign in to comment.