From b03f54e4503cee6b598ef06ca2d44a7e7c3181f3 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 Jan 2022 19:56:19 -0600 Subject: [PATCH 1/6] Only set a job as 'success' when the 'Sucess' message is at the end Otherwise, there can be a lot of 'Success' messages that can incorrectly trigger this. --- src/utils/showMainTerminalHelperMessages.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/utils/showMainTerminalHelperMessages.ts b/src/utils/showMainTerminalHelperMessages.ts index bdada0b0..023d0277 100644 --- a/src/utils/showMainTerminalHelperMessages.ts +++ b/src/utils/showMainTerminalHelperMessages.ts @@ -26,7 +26,17 @@ export default function showMainTerminalHelperMessages( ); process.stdout.on('data', (data) => { - if (data?.toString()?.includes('Success!')) { + const output = data?.toString(); + if (!output.length) { + return; + } + + // 'Sucess!' should be near the end of the output, to find the final job 'Success!' message. + // There can be lot of other 'Success!' messages that can trigger this incorrectly. + if ( + output?.includes('Success!') && + output.length - output.indexOf('Success!') < 15 + ) { job?.setIsSuccess(); if (doesJobCreateDynamicConfig) { @@ -39,12 +49,12 @@ export default function showMainTerminalHelperMessages( } } - if (data?.toString()?.includes('Task failed')) { + if (output.includes('Task failed')) { job?.setIsFailure(); jobProvider.refresh(job); } - if (data?.toString()?.includes(memoryMessage)) { + if (output.includes(memoryMessage)) { vscode.window.showInformationMessage( `This may have failed from a lack of Docker memory. You can increase it via Docker Desktop > Preferences > Resources > Advanced > Memory` ); From 9aff05e1294c225ea57c4753e180a20c3acb5042 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 Jan 2022 20:10:25 -0600 Subject: [PATCH 2/6] Add a link to learn more about adding a .circleci/config.yml file --- src/classes/JobProvider.ts | 2 ++ src/constants/index.ts | 3 +++ src/extension.ts | 14 ++++++++++++++ src/utils/getConfigFilePath.ts | 19 ++++++++++++++----- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/classes/JobProvider.ts b/src/classes/JobProvider.ts index c52ed22b..f53fd7db 100644 --- a/src/classes/JobProvider.ts +++ b/src/classes/JobProvider.ts @@ -17,6 +17,7 @@ import { ENTER_LICENSE_COMMAND, GET_LICENSE_COMMAND, JOB_TREE_VIEW_ID, + OPEN_LEARN_MORE_COMMAND, TRIAL_STARTED_TIMESTAMP, } from '../constants'; @@ -174,6 +175,7 @@ export default class JobProvider new vscode.TreeItem( 'Please add a .circleci/config.yml to this workspace' ), + new Command('Learn more', OPEN_LEARN_MORE_COMMAND), ]; case JobError.noConfigFilePathSelected: return [ diff --git a/src/constants/index.ts b/src/constants/index.ts index 08f6f722..caefa395 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -43,6 +43,9 @@ export const HOST_TMP_DIRECTORY = '/tmp/local-ci'; // Also hard-coded in node/un export const PROCESS_FILE_DIRECTORY = `${HOST_TMP_DIRECTORY}/process`; export const LOCAL_VOLUME_DIRECTORY = `${HOST_TMP_DIRECTORY}/volume`; export const RUN_JOB_COMMAND = 'local-ci.job.run'; +export const OPEN_LEARN_MORE_COMMAND = 'local-ci.open.learn-more.config'; +export const CONFIG_LEARN_MORE_URL = + 'https://circleci.com/docs/2.0/config-intro/'; export const CONTINUE_PIPELINE_STEP_NAME = 'Continue the pipeline'; export const SCHEDULE_INTERVIEW_URL = 'https://tidycal.com/localci/30-minute-meeting'; diff --git a/src/extension.ts b/src/extension.ts index 406567e9..1cb44110 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -8,6 +8,7 @@ import JobProvider from './classes/JobProvider'; import LicenseProvider from './classes/LicenseProvider'; import { COMMITTED_IMAGE_NAMESPACE, + CONFIG_LEARN_MORE_URL, ENTER_LICENSE_COMMAND, EXIT_JOB_COMMAND, EXTENSION_ID, @@ -16,6 +17,7 @@ import { HELP_URL, HOST_TMP_DIRECTORY, JOB_TREE_VIEW_ID, + OPEN_LEARN_MORE_COMMAND, RUN_JOB_COMMAND, SELECTED_CONFIG_PATH, TELEMETRY_KEY, @@ -122,6 +124,8 @@ export function activate(context: vscode.ExtensionContext): void { `${JOB_TREE_VIEW_ID}.selectRepo`, async () => { reporter.sendTelemetryEvent('selectRepo'); + + const learnMoreText = 'Learn more'; const quickPick = vscode.window.createQuickPick(); const configFilePaths = await getAllConfigFilePaths(context); quickPick.title = 'Repo to run CI on'; @@ -133,8 +137,14 @@ export function activate(context: vscode.ExtensionContext): void { description: 'Please add a .circleci/config.yml file so Local CI can run', }, + { + label: learnMoreText, + }, ]; quickPick.onDidChangeSelection((selection) => { + if (selection.length && selection[0].label === learnMoreText) { + vscode.commands.executeCommand(OPEN_LEARN_MORE_COMMAND); + } if ( selection?.length && (selection[0] as ConfigFileQuickPick)?.fsPath @@ -286,6 +296,10 @@ export function activate(context: vscode.ExtensionContext): void { licenseCompletedCallback, licenseSuccessCallback ); + }), + vscode.commands.registerCommand(OPEN_LEARN_MORE_COMMAND, () => { + reporter.sendTelemetryEvent('click.config.learnMore'); + vscode.env.openExternal(vscode.Uri.parse(CONFIG_LEARN_MORE_URL)); }) ); diff --git a/src/utils/getConfigFilePath.ts b/src/utils/getConfigFilePath.ts index a69d7299..436468f8 100644 --- a/src/utils/getConfigFilePath.ts +++ b/src/utils/getConfigFilePath.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode'; -import { SELECTED_CONFIG_PATH } from '../constants'; +import { OPEN_LEARN_MORE_COMMAND, SELECTED_CONFIG_PATH } from '../constants'; import getAllConfigFilePaths from './getAllConfigFilePaths'; // Gets the path of the selected .circleci/config.yml to run the jobs on. @@ -19,10 +19,19 @@ export default async function getConfigFilePath( const allConfigFilePaths = await getAllConfigFilePaths(context); if (!allConfigFilePaths.length) { - vscode.window.showInformationMessage( - 'Please add a .circleci/config.yml file so Local CI can run it', - { detail: 'There is no config file for Local CI to run' } - ); + const learnMoreText = 'Learn more'; + vscode.window + .showInformationMessage( + 'Please add a .circleci/config.yml file so Local CI can run it', + { detail: 'There is no config file for Local CI to run' }, + learnMoreText + ) + .then((clicked) => { + if (clicked === learnMoreText) { + vscode.commands.executeCommand(OPEN_LEARN_MORE_COMMAND); + } + }); + return ''; } From d2290499b332f103a137137278d825e8e70c667e Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 Jan 2022 20:44:14 -0600 Subject: [PATCH 3/6] Improve the search for 'Success!', as it wasn't working on some --- src/utils/showMainTerminalHelperMessages.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/utils/showMainTerminalHelperMessages.ts b/src/utils/showMainTerminalHelperMessages.ts index 023d0277..f2bb28b0 100644 --- a/src/utils/showMainTerminalHelperMessages.ts +++ b/src/utils/showMainTerminalHelperMessages.ts @@ -31,12 +31,9 @@ export default function showMainTerminalHelperMessages( return; } - // 'Sucess!' should be near the end of the output, to find the final job 'Success!' message. - // There can be lot of other 'Success!' messages that can trigger this incorrectly. - if ( - output?.includes('Success!') && - output.length - output.indexOf('Success!') < 15 - ) { + // This should be the final 'Success!' message when a job succeeds. + // There can be lot of other 'Success!' messages that might trigger this incorrectly. + if (output?.includes(`[32mSuccess!`)) { job?.setIsSuccess(); if (doesJobCreateDynamicConfig) { From 701fdd286d2043d62234434ac18b76907544ecf0 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 Jan 2022 21:08:55 -0600 Subject: [PATCH 4/6] Bump the version to 1.4.1, add a CHANGELOG entry --- CHANGELOG.md | 6 ++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dca1d10e..e08ad966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## 1.4.1 - 3 January 2022 + +### Added +- Improve detection of job success. [#67](https://github.com/getlocalci/local-ci/pull/67/) +- Add a 'Learn more' link when there's no `.circleci/config.yml`. [#67](https://github.com/getlocalci/local-ci/pull/67/) + ## 1.4.0 - 2 January 2022 ### Added diff --git a/package-lock.json b/package-lock.json index 9e1fc723..b71b6e43 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "local-ci", - "version": "1.4.0", + "version": "1.4.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "local-ci", - "version": "1.4.0", + "version": "1.4.1", "hasInstallScript": true, "license": "GPL-2.0-or-later", "os": [ diff --git a/package.json b/package.json index 225efcab..59da751f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "local-ci", "displayName": "Local CI", "description": "Debug CircleCI® workflows locally, with Bash access during and after. Free preview, then paid.", - "version": "1.4.0", + "version": "1.4.1", "publisher": "LocalCI", "contributors": [ "Ryan Kienstra" From c5ab6f385c5186849907c0381af8eb22d998c0e1 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 Jan 2022 21:12:56 -0600 Subject: [PATCH 5/6] Use the ? operator before .length --- src/utils/showMainTerminalHelperMessages.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/showMainTerminalHelperMessages.ts b/src/utils/showMainTerminalHelperMessages.ts index f2bb28b0..3245fac4 100644 --- a/src/utils/showMainTerminalHelperMessages.ts +++ b/src/utils/showMainTerminalHelperMessages.ts @@ -27,7 +27,7 @@ export default function showMainTerminalHelperMessages( process.stdout.on('data', (data) => { const output = data?.toString(); - if (!output.length) { + if (!output?.length) { return; } From 542c3c0b6ec608e4e156acf1b2ec977ab4e9e302 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 Jan 2022 21:15:04 -0600 Subject: [PATCH 6/6] Add 2 more ? operators to be safe --- src/utils/showMainTerminalHelperMessages.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/showMainTerminalHelperMessages.ts b/src/utils/showMainTerminalHelperMessages.ts index 3245fac4..2b8b1853 100644 --- a/src/utils/showMainTerminalHelperMessages.ts +++ b/src/utils/showMainTerminalHelperMessages.ts @@ -46,12 +46,12 @@ export default function showMainTerminalHelperMessages( } } - if (output.includes('Task failed')) { + if (output?.includes('Task failed')) { job?.setIsFailure(); jobProvider.refresh(job); } - if (output.includes(memoryMessage)) { + if (output?.includes(memoryMessage)) { vscode.window.showInformationMessage( `This may have failed from a lack of Docker memory. You can increase it via Docker Desktop > Preferences > Resources > Advanced > Memory` );