improve ext ci output

This commit is contained in:
João Moreno 2021-02-02 11:39:26 +01:00
parent b2d303d16e
commit 7e0230677a
No known key found for this signature in database
GPG key ID: 896B853774D1A575
4 changed files with 84 additions and 22 deletions

View file

@ -31,6 +31,9 @@ const commander_1 = require("commander");
const storage_blob_1 = require("@azure/storage-blob");
const mkdirp = require("mkdirp");
const plimit = require("p-limit");
const colors = require("colors");
const byline = require("byline");
const stream_1 = require("stream");
const rootPath = path.resolve(path.join(__dirname, '..'));
const vsixsPath = path.join(rootPath, '.build', 'vsix');
var ExtensionType;
@ -39,11 +42,27 @@ var ExtensionType;
ExtensionType["Theme"] = "theme";
ExtensionType["Misc"] = "misc";
})(ExtensionType || (ExtensionType = {}));
async function spawn(cmd, argsOrOpts, opts = {}) {
class Prefixer extends stream_1.Transform {
constructor(prefix) {
super();
this.prefix = prefix;
}
_transform(line, _encoding, callback) {
callback(null, `${this.prefix} ${line}\n`);
}
}
async function spawn(cmd, argsOrOpts, _opts = {}) {
return new Promise((c, e) => {
var _a;
const opts = (_a = (Array.isArray(argsOrOpts) ? _opts : argsOrOpts)) !== null && _a !== void 0 ? _a : {};
const stdio = opts.prefix ? 'pipe' : 'inherit';
const child = Array.isArray(argsOrOpts)
? cp.spawn(cmd, argsOrOpts, Object.assign({ stdio: 'inherit', env: process.env }, opts))
: cp.spawn(cmd, Object.assign({ stdio: 'inherit', env: process.env }, argsOrOpts));
? cp.spawn(cmd, argsOrOpts, Object.assign({ stdio, env: process.env }, opts))
: cp.spawn(cmd, Object.assign({ stdio, env: process.env }, opts));
if (opts.prefix) {
child.stdout.pipe(new byline.LineStream()).pipe(new Prefixer(opts.prefix)).pipe(process.stdout);
child.stderr.pipe(new byline.LineStream()).pipe(new Prefixer(opts.prefix)).pipe(process.stderr);
}
child.on('close', code => code === 0 ? c() : e(`Returned ${code}`));
});
}
@ -129,9 +148,10 @@ async function runExtensionCI(extension, service) {
const container = service.getContainerClient('extensions');
const blobName = `${commit}/${vsixName}`;
const blob = container.getBlobClient(blobName);
const prefix = `📦 ${colors.green(extension.name)}`;
try {
await blob.downloadToFile(extension.vsixPath);
console.log(`📦 [${extension.name}] Downloaded from cache (${blobName})`);
console.log(`${prefix} Downloaded from cache ${colors.grey(`(${blobName})`)}`);
return;
}
catch (err) {
@ -139,17 +159,17 @@ async function runExtensionCI(extension, service) {
throw err;
}
}
console.log(`📦 [${extension.name}] Cache miss (${blobName})`);
console.log(`📦 [${extension.name}] Building...`);
await spawn(`yarn`, { shell: true, cwd: extension.path });
await spawn(`vsce package --yarn -o ${vsixsPath}`, { shell: true, cwd: extension.path });
console.log(`${prefix} Cache miss ${colors.grey(`(${blobName})`)}`);
console.log(`${prefix} Building...`);
await spawn(`yarn install --no-progress`, { prefix, shell: true, cwd: extension.path });
await spawn(`vsce package --yarn -o ${vsixsPath}`, { prefix, shell: true, cwd: extension.path });
if (service.credential instanceof storage_blob_1.AnonymousCredential) {
console.log(`📦 [${extension.name}] Skiping publish VSIX to cache (anonymous access only)`);
console.log(`${prefix} Skiping publish VSIX to cache (anonymous access only)`);
return;
}
const blockBlob = await blob.getBlockBlobClient();
await blockBlob.uploadFile(extension.vsixPath);
console.log(`📦 [${extension.name}] Successfully uploaded VSIX to cache`);
console.log(`${prefix} Successfully uploaded VSIX to cache`);
}
async function ci() {
var e_2, _a;

View file

@ -10,6 +10,9 @@ import { program } from 'commander';
import { AnonymousCredential, BlobServiceClient, StorageSharedKeyCredential } from '@azure/storage-blob';
import * as mkdirp from 'mkdirp';
import * as plimit from 'p-limit';
import * as colors from 'colors';
import * as byline from 'byline';
import { Transform, TransformCallback } from 'stream';
const rootPath = path.resolve(path.join(__dirname, '..'));
const vsixsPath = path.join(rootPath, '.build', 'vsix');
@ -45,13 +48,31 @@ interface IExtension {
// await fs.writeFile(controlFilePath, JSON.stringify(control, null, ' '));
// }
async function spawn(cmd: string, opts?: cp.SpawnOptions): Promise<void>;
async function spawn(cmd: string, args: string[], opts?: cp.SpawnOptions): Promise<void>;
async function spawn(cmd: string, argsOrOpts?: cp.SpawnOptions | string[], opts: cp.SpawnOptions = {}): Promise<void> {
interface SpawnOptions extends cp.SpawnOptions {
readonly prefix?: string;
}
class Prefixer extends Transform {
constructor(private prefix: string) { super(); }
_transform(line: string, _encoding: string, callback: TransformCallback): void {
callback(null, `${this.prefix} ${line}\n`);
}
}
async function spawn(cmd: string, opts?: SpawnOptions): Promise<void>;
async function spawn(cmd: string, args: string[], opts?: SpawnOptions): Promise<void>;
async function spawn(cmd: string, argsOrOpts?: SpawnOptions | string[], _opts: SpawnOptions = {}): Promise<void> {
return new Promise((c, e) => {
const opts = (Array.isArray(argsOrOpts) ? _opts : argsOrOpts) ?? {};
const stdio = opts.prefix ? 'pipe' : 'inherit';
const child = Array.isArray(argsOrOpts)
? cp.spawn(cmd, argsOrOpts, { stdio: 'inherit', env: process.env, ...opts })
: cp.spawn(cmd, { stdio: 'inherit', env: process.env, ...argsOrOpts });
? cp.spawn(cmd, argsOrOpts, { stdio, env: process.env, ...opts })
: cp.spawn(cmd, { stdio, env: process.env, ...opts });
if (opts.prefix) {
child.stdout!.pipe(new byline.LineStream()).pipe(new Prefixer(opts.prefix)).pipe(process.stdout);
child.stderr!.pipe(new byline.LineStream()).pipe(new Prefixer(opts.prefix)).pipe(process.stderr);
}
child.on('close', code => code === 0 ? c() : e(`Returned ${code}`));
});
@ -131,10 +152,11 @@ async function runExtensionCI(extension: IExtension, service: BlobServiceClient)
const container = service.getContainerClient('extensions');
const blobName = `${commit}/${vsixName}`;
const blob = container.getBlobClient(blobName);
const prefix = `📦 ${colors.green(extension.name)}`;
try {
await blob.downloadToFile(extension.vsixPath);
console.log(`📦 [${extension.name}] Downloaded from cache (${blobName})`);
console.log(`${prefix} Downloaded from cache ${colors.grey(`(${blobName})`)}`);
return;
} catch (err) {
if (err.statusCode !== 404) {
@ -142,19 +164,19 @@ async function runExtensionCI(extension: IExtension, service: BlobServiceClient)
}
}
console.log(`📦 [${extension.name}] Cache miss (${blobName})`);
console.log(`📦 [${extension.name}] Building...`);
await spawn(`yarn`, { shell: true, cwd: extension.path });
await spawn(`vsce package --yarn -o ${vsixsPath}`, { shell: true, cwd: extension.path });
console.log(`${prefix} Cache miss ${colors.grey(`(${blobName})`)}`);
console.log(`${prefix} Building...`);
await spawn(`yarn install --no-progress`, { prefix, shell: true, cwd: extension.path });
await spawn(`vsce package --yarn -o ${vsixsPath}`, { prefix, shell: true, cwd: extension.path });
if (service.credential instanceof AnonymousCredential) {
console.log(`📦 [${extension.name}] Skiping publish VSIX to cache (anonymous access only)`);
console.log(`${prefix} Skiping publish VSIX to cache (anonymous access only)`);
return;
}
const blockBlob = await blob.getBlockBlobClient();
await blockBlob.uploadFile(extension.vsixPath);
console.log(`📦 [${extension.name}] Successfully uploaded VSIX to cache`);
console.log(`${prefix} Successfully uploaded VSIX to cache`);
}
async function ci(): Promise<void> {

View file

@ -7,6 +7,7 @@
"@azure/storage-blob": "^12.4.0",
"@types/ansi-colors": "^3.2.0",
"@types/azure": "0.9.19",
"@types/byline": "^4.2.32",
"@types/debounce": "^1.0.0",
"@types/eslint": "4.16.1",
"@types/fancy-log": "^1.3.0",
@ -37,6 +38,8 @@
"@typescript-eslint/parser": "^3.3.0",
"applicationinsights": "1.0.8",
"azure-storage": "^2.1.0",
"byline": "^5.0.0",
"colors": "^1.4.0",
"commander": "^7.0.0",
"electron-osx-sign": "^0.4.16",
"esbuild": "^0.8.30",

View file

@ -144,6 +144,13 @@
dependencies:
"@types/node" "*"
"@types/byline@^4.2.32":
version "4.2.32"
resolved "https://registry.yarnpkg.com/@types/byline/-/byline-4.2.32.tgz#9d35ec15968056118548412ee24c2c3026c997dc"
integrity sha512-qtlm/J6XOO9p+Ep/ZB5+mCFEDhzWDDHWU4a1eReN7lkPZXW9rkloq2jcAhvKKmlO5tL2GSvKROb+PTsNVhBiyQ==
dependencies:
"@types/node" "*"
"@types/caseless@*":
version "0.12.1"
resolved "https://registry.yarnpkg.com/@types/caseless/-/caseless-0.12.1.tgz#9794c69c8385d0192acc471a540d1f8e0d16218a"
@ -671,6 +678,11 @@ buffer-fill@^1.0.0:
resolved "https://registry.yarnpkg.com/buffer-fill/-/buffer-fill-1.0.0.tgz#f8f78b76789888ef39f205cd637f68e702122b2c"
integrity sha1-+PeLdniYiO858gXNY39o5wISKyw=
byline@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/byline/-/byline-5.0.0.tgz#741c5216468eadc457b03410118ad77de8c1ddb1"
integrity sha1-dBxSFkaOrcRXsDQQEYrXfejB3bE=
caseless@~0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
@ -698,6 +710,11 @@ colors@1.0.3:
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
integrity sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=
colors@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"