From 31fadc78e399cf9b86c021d57e3c592ef813841f Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Fri, 14 Oct 2022 19:19:38 -0500 Subject: [PATCH 01/22] Change to 'Please select repo', that's what they should do --- src/job/Children.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/job/Children.ts b/src/job/Children.ts index 0028189b..a69aeece 100644 --- a/src/job/Children.ts +++ b/src/job/Children.ts @@ -149,7 +149,7 @@ export default class Children { ]; case JobError.NoConfigFilePathSelected: return [ - this.warningFactory.create('Error: No jobs found'), + this.warningFactory.create('Please select repo'), this.commandFactory.create('Select repo', 'localCiJobs.selectRepo'), this.commandFactory.create('Complain to me', COMPLAIN_COMMAND), ]; From 54a13e0df1e57dd63f2d59aff294260c358f8771 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Fri, 14 Oct 2022 19:31:12 -0500 Subject: [PATCH 02/22] Allow clicking a warning, like 'Please select repo' --- src/config/ConfigFile.ts | 6 +++--- src/constant/index.ts | 1 + src/job/Children.ts | 5 +++-- src/job/WarningFactory.ts | 9 ++++++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/config/ConfigFile.ts b/src/config/ConfigFile.ts index bf79f331..69d78546 100644 --- a/src/config/ConfigFile.ts +++ b/src/config/ConfigFile.ts @@ -56,15 +56,15 @@ export default class ConfigFile { return allConfigFilePaths[0].fsPath; } - const chooseRepoText = 'Choose repo'; + const selectRepoText = 'Select repo'; this.editorGateway.editor.window .showInformationMessage( 'Please select the repo to run Local CI on', { detail: 'There is no repo selected to run Local CI on' }, - chooseRepoText + selectRepoText ) .then((clicked) => { - if (clicked === chooseRepoText) { + if (clicked === selectRepoText) { this.editorGateway.editor.commands.executeCommand( 'localCiJobs.selectRepo' ); diff --git a/src/constant/index.ts b/src/constant/index.ts index 1a655846..00692761 100644 --- a/src/constant/index.ts +++ b/src/constant/index.ts @@ -41,6 +41,7 @@ export const DYNAMIC_CONFIG_PATH_IN_CONTAINER = path.join( export const HOST_TMP_DIRECTORY = '/tmp/local-ci'; export const RUN_JOB_COMMAND = 'local-ci.job.run'; export const CREATE_CONFIG_FILE_COMMAND = 'local-ci.create.config'; +export const SELECT_REPO_COMMAND = 'localCiJobs.selectRepo'; export const SHOW_LOG_FILE_COMMAND = 'local-ci.show.log-file'; export const LOG_FILE_SCHEME = 'local-ci-log'; export const CONTINUE_PIPELINE_STEP_NAME = 'Continue the pipeline'; diff --git a/src/job/Children.ts b/src/job/Children.ts index a69aeece..05a9b6b7 100644 --- a/src/job/Children.ts +++ b/src/job/Children.ts @@ -16,6 +16,7 @@ import { GET_LICENSE_COMMAND, JOB_TREE_VIEW_ID, PROCESS_TRY_AGAIN_COMMAND, + SELECT_REPO_COMMAND, } from 'constant'; type Logs = Record; @@ -149,8 +150,8 @@ export default class Children { ]; case JobError.NoConfigFilePathSelected: return [ - this.warningFactory.create('Please select repo'), - this.commandFactory.create('Select repo', 'localCiJobs.selectRepo'), + this.warningFactory.create('Please select repo', SELECT_REPO_COMMAND), + this.commandFactory.create('Select repo', SELECT_REPO_COMMAND), this.commandFactory.create('Complain to me', COMPLAIN_COMMAND), ]; case JobError.ProcessFile: diff --git a/src/job/WarningFactory.ts b/src/job/WarningFactory.ts index 2136153b..ce518501 100644 --- a/src/job/WarningFactory.ts +++ b/src/job/WarningFactory.ts @@ -8,13 +8,20 @@ export default class WarningFactory { @inject(Types.IEditorGateway) editorGateway!: EditorGateway; - create(label: string): vscode.TreeItem { + create(label: string, command?: string): vscode.TreeItem { const warning = new this.editorGateway.editor.TreeItem( label, this.editorGateway.editor.TreeItemCollapsibleState.None ); warning.tooltip = label; warning.iconPath = new this.editorGateway.editor.ThemeIcon('warning'); + if (command) { + warning.command = { + command, + title: label, + tooltip: label, + }; + } return warning; } From 5f11aa87cd049b140133501a23577fe2172df48f Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Fri, 14 Oct 2022 19:34:53 -0500 Subject: [PATCH 03/22] Replace a string literal with a const --- src/config/ConfigFile.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/config/ConfigFile.ts b/src/config/ConfigFile.ts index 69d78546..46144009 100644 --- a/src/config/ConfigFile.ts +++ b/src/config/ConfigFile.ts @@ -3,7 +3,11 @@ import type vscode from 'vscode'; import Types from 'common/Types'; import AllConfigFiles from './AllConfigFiles'; import EditorGateway from 'gateway/EditorGateway'; -import { CREATE_CONFIG_FILE_COMMAND, SELECTED_CONFIG_PATH } from 'constant'; +import { + CREATE_CONFIG_FILE_COMMAND, + SELECTED_CONFIG_PATH, + SELECT_REPO_COMMAND, +} from 'constant'; @injectable() export default class ConfigFile { @@ -66,7 +70,7 @@ export default class ConfigFile { .then((clicked) => { if (clicked === selectRepoText) { this.editorGateway.editor.commands.executeCommand( - 'localCiJobs.selectRepo' + SELECT_REPO_COMMAND ); } }); From c7b120aea480a54bb27438b7673c50dde26d4e62 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Fri, 14 Oct 2022 19:46:21 -0500 Subject: [PATCH 04/22] Compose the class WarningCommandFactory from WarningFactory --- src/common/BaseIoc.ts | 2 ++ src/job/Children.ts | 9 ++++++++- src/job/WarningCommandFactory.ts | 20 ++++++++++++++++++++ src/job/WarningFactory.ts | 9 +-------- 4 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 src/job/WarningCommandFactory.ts diff --git a/src/common/BaseIoc.ts b/src/common/BaseIoc.ts index d3dcd79a..68930d45 100644 --- a/src/common/BaseIoc.ts +++ b/src/common/BaseIoc.ts @@ -43,6 +43,7 @@ import SelectRepo from 'command/SelectRepo'; import Spawn from 'common/Spawn'; import TryProcessAgain from 'command/TryProcessAgain'; import UncommittedFile from 'containerization/UncommittedFile'; +import WarningCommandFactory from 'job/WarningCommandFactory'; import WarningFactory from 'job/WarningFactory'; import Workspace from 'common/Workspace'; @@ -106,6 +107,7 @@ export default class BaseIoc { this.container.bind(Spawn).toSelf(); this.container.bind(TryProcessAgain).toSelf(); this.container.bind(UncommittedFile).toSelf(); + this.container.bind(WarningCommandFactory).toSelf(); this.container.bind(WarningFactory).toSelf(); this.container.bind(Workspace).toSelf(); diff --git a/src/job/Children.ts b/src/job/Children.ts index 05a9b6b7..8613f7fd 100644 --- a/src/job/Children.ts +++ b/src/job/Children.ts @@ -8,6 +8,7 @@ import CommandFactory from './ComandFactory'; import JobFactory from './JobFactory'; import JobTreeItem from './JobTreeItem'; import WarningFactory from './WarningFactory'; +import WarningCommandFactory from './WarningCommandFactory'; import type EditorGateway from 'gateway/EditorGateway'; import { COMPLAIN_COMMAND, @@ -36,6 +37,9 @@ export default class Children { @inject(LogFactory) logFactory!: LogFactory; + @inject(WarningCommandFactory) + warningCommandFactory!: WarningCommandFactory; + @inject(WarningFactory) warningFactory!: WarningFactory; @@ -150,7 +154,10 @@ export default class Children { ]; case JobError.NoConfigFilePathSelected: return [ - this.warningFactory.create('Please select repo', SELECT_REPO_COMMAND), + this.warningCommandFactory.create( + 'Please select repo', + SELECT_REPO_COMMAND + ), this.commandFactory.create('Select repo', SELECT_REPO_COMMAND), this.commandFactory.create('Complain to me', COMPLAIN_COMMAND), ]; diff --git a/src/job/WarningCommandFactory.ts b/src/job/WarningCommandFactory.ts new file mode 100644 index 00000000..03e08aca --- /dev/null +++ b/src/job/WarningCommandFactory.ts @@ -0,0 +1,20 @@ +import { inject, injectable } from 'inversify'; +import type vscode from 'vscode'; +import WarningFactory from './WarningFactory'; + +@injectable() +export default class WarningCommandFactory { + @inject(WarningFactory) + warningFactory!: WarningFactory; + + create(label: string, command: string): vscode.TreeItem { + const warning = this.warningFactory.create(label); + warning.command = { + command, + title: label, + tooltip: label, + }; + + return warning; + } +} diff --git a/src/job/WarningFactory.ts b/src/job/WarningFactory.ts index ce518501..2136153b 100644 --- a/src/job/WarningFactory.ts +++ b/src/job/WarningFactory.ts @@ -8,20 +8,13 @@ export default class WarningFactory { @inject(Types.IEditorGateway) editorGateway!: EditorGateway; - create(label: string, command?: string): vscode.TreeItem { + create(label: string): vscode.TreeItem { const warning = new this.editorGateway.editor.TreeItem( label, this.editorGateway.editor.TreeItemCollapsibleState.None ); warning.tooltip = label; warning.iconPath = new this.editorGateway.editor.ThemeIcon('warning'); - if (command) { - warning.command = { - command, - title: label, - tooltip: label, - }; - } return warning; } From 6e28da3cc7c60d6fda41ee79e48bfc9e8379487e Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Fri, 14 Oct 2022 19:47:45 -0500 Subject: [PATCH 05/22] Simplify how this returns the WarningCommand --- src/job/WarningCommandFactory.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/job/WarningCommandFactory.ts b/src/job/WarningCommandFactory.ts index 03e08aca..e8f78d9d 100644 --- a/src/job/WarningCommandFactory.ts +++ b/src/job/WarningCommandFactory.ts @@ -8,13 +8,13 @@ export default class WarningCommandFactory { warningFactory!: WarningFactory; create(label: string, command: string): vscode.TreeItem { - const warning = this.warningFactory.create(label); - warning.command = { - command, - title: label, - tooltip: label, + return { + ...this.warningFactory.create(label), + command: { + command, + title: label, + tooltip: label, + }, }; - - return warning; } } From 98fe3fc19a3fb8a53b2bd3668fa8e0c82ad2e10a Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Fri, 14 Oct 2022 20:16:37 -0500 Subject: [PATCH 06/22] Bump the binary version to the latest: v0.1.22272 --- node/binary.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/binary.js b/node/binary.js index cf0677f3..a87ef1eb 100644 --- a/node/binary.js +++ b/node/binary.js @@ -3,7 +3,7 @@ const { Binary } = require('@cloudflare/binary-install'); const { type, arch } = require('os'); const path = require('path'); -const binaryVersion = '0.1.22150'; +const binaryVersion = '0.1.22272'; const intelMacBinaryVersion = '0.1.17087'; const supportedPlatforms = [ From 037f2d35d59080dc313608c565b55f37d2f42c7e Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sat, 15 Oct 2022 15:41:14 -0500 Subject: [PATCH 07/22] Get the additional env vars from the user's local, not Docker As it is now, it depends on a checkout step. But there can be a custom checkout step, or a restore_workspace. --- src/config/Config.ts | 10 +++++++-- src/job/JobRunner.ts | 3 ++- src/process/ProcessFile.ts | 42 ++++++++++++++++++++++++++------------ src/script/addEnvVars.sh | 9 ++++---- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/config/Config.ts b/src/config/Config.ts index 3767342a..2f93758f 100644 --- a/src/config/Config.ts +++ b/src/config/Config.ts @@ -12,6 +12,7 @@ import ProcessFile from 'process/ProcessFile'; import ReporterGateway from 'gateway/ReporterGateway'; import Spawn from 'common/Spawn'; import Types from 'common/Types'; +import getRepoPath from 'common/getRepoPath'; @injectable() export default class Config { @@ -55,7 +56,11 @@ export default class Config { this.childProcessGateway.cp, this.spawn.getOptions() ); - this.processFile.write(processedConfig, processFilePath); + this.processFile.write( + processedConfig, + processFilePath, + getRepoPath(configFilePath) + ); const dynamicConfigFilePath = getDynamicConfigPath(configFilePath); if (this.fsGateway.fs.existsSync(dynamicConfigFilePath)) { @@ -70,7 +75,8 @@ export default class Config { this.childProcessGateway.cp, this.spawn.getOptions() ), - dynamicConfigFilePath + dynamicConfigFilePath, + getRepoPath(configFilePath) ); } } catch (e) { diff --git a/src/job/JobRunner.ts b/src/job/JobRunner.ts index e269270e..151523fa 100644 --- a/src/job/JobRunner.ts +++ b/src/job/JobRunner.ts @@ -36,6 +36,7 @@ import { dockerExecRunningContainer, getRunningContainerFunction, } from 'script'; +import getRepoPath from 'common/getRepoPath'; @injectable() export default class JobRunner { @@ -87,7 +88,7 @@ export default class JobRunner { } const configFilePath = await this.configFile.getPath(context); - const repoPath = path.dirname(path.dirname(configFilePath)); + const repoPath = getRepoPath(configFilePath); const terminal = this.editorGateway.editor.window.createTerminal({ name: getTerminalName(jobName), message: `Running the CircleCI® job ${jobName}…`, diff --git a/src/process/ProcessFile.ts b/src/process/ProcessFile.ts index 4d9b55a9..82e48e5d 100644 --- a/src/process/ProcessFile.ts +++ b/src/process/ProcessFile.ts @@ -15,12 +15,20 @@ import { DYNAMIC_CONFIG_PATH_IN_CONTAINER, } from 'constant'; import { addEnvVars } from 'script'; +import ChildProcessGateway from 'gateway/ChildProcessGateway'; +import Spawn from 'common/Spawn'; @injectable() export default class ProcessFile { + @inject(Types.IChildProcessGateway) + childProcessGateway!: ChildProcessGateway; + @inject(Types.IFsGateway) fsGateway!: FsGateway; + @inject(Spawn) + spawn!: Spawn; + /** * Overwrites parts of the process.yml file. * @@ -28,9 +36,9 @@ export default class ProcessFile { * this copies the files inside the container to the volume shared with the local machine. * This way, they can persist between jobs. * Likewise, on attach_workspace, it copies from the volume. - * The processedConfig was already compiled by the CircleCI® CLI binary. + * The processedConfig was already compiled by the CircleCI CLI binary. */ - write(processedConfig: string, processFilePath: string) { + write(processedConfig: string, processFilePath: string, repoPath: string) { const config = getConfig(processedConfig); if (!config) { @@ -134,21 +142,13 @@ export default class ProcessFile { return step; }); - // If a 'checkout' step exists, insert env vars right after it. - if (newSteps?.includes('checkout')) { - newSteps?.splice( - newSteps?.indexOf('checkout') + 1, - 0, - this.getEnvVarStep() - ); - } - return { ...accumulator, [jobName]: { ...configJobs[jobName], steps: [ this.getEnsureVolumeIsWritableStep(), + this.getEnvVarStep(repoPath), ...(newSteps ?? []), ], }, @@ -225,11 +225,27 @@ export default class ProcessFile { }; } - private getEnvVarStep() { + private getEnvVarStep(repoPath: string) { + let command; + try { + const exportVars = this.childProcessGateway.cp + .execSync(addEnvVars, { + ...this.spawn.getOptions(repoPath), + timeout: 2000, + }) + .toString(); + + command = `echo '${exportVars}' >> $BASH_ENV`; + } catch (error) { + command = `There was an error setting the variables: ${ + (error as ErrorWithMessage).message + }`; + } + return { run: { name: 'Set more environment variables', - command: addEnvVars, + command, }, }; } diff --git a/src/script/addEnvVars.sh b/src/script/addEnvVars.sh index f1c9706f..08a7930b 100644 --- a/src/script/addEnvVars.sh +++ b/src/script/addEnvVars.sh @@ -1,8 +1,7 @@ #!/bin/sh # shellcheck disable=SC2016 -{ -echo 'export CIRCLE_SHA1=$(git rev-parse HEAD)' -echo 'export CIRCLE_BRANCH=$(git rev-parse --abbrev-ref HEAD)' -echo 'export CIRCLE_PROJECT_REPONAME=$(basename $(git remote get-url origin))' -} >> "$BASH_ENV" +echo "export CIRCLE_SHA1=$(git rev-parse HEAD)" +echo "export CIRCLE_BRANCH=$(git rev-parse --abbrev-ref HEAD)" +echo "export CIRCLE_PROJECT_REPONAME=$(basename "$(git remote get-url origin)")" +echo "export CIRCLE_REPOSITORY_URL=$(git remote get-url origin)" From 21260a66a54c765315f9bf04f310a220e6064016 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sat, 15 Oct 2022 22:34:39 -0500 Subject: [PATCH 08/22] Add a button 'Start Docker', instead of simply asking if Docker is running --- src/common/EnvPath.ts | 4 ++-- src/common/Registrar.ts | 3 +++ src/common/RegistrarFactory.ts | 3 +++ src/constant/index.ts | 1 + src/job/Children.ts | 5 +++-- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/common/EnvPath.ts b/src/common/EnvPath.ts index 177b59ad..5e0c9984 100644 --- a/src/common/EnvPath.ts +++ b/src/common/EnvPath.ts @@ -19,7 +19,7 @@ export default class EnvPath { * Must be whole, i.e. the left side must be the beginning of the string or :, and the right side must be the end of the string or : * Case-insensitive, because Mac is. */ - get(): string { + get() { const path = this.processGateway.process.env.PATH || ''; return this.isMac() && !/(?<=^|:)\/usr\/local\/bin(?=$|:)/i.test(path) @@ -27,7 +27,7 @@ export default class EnvPath { : path; } - isMac(): boolean { + isMac() { return this.osGateway.os.type() === 'Darwin'; } } diff --git a/src/common/Registrar.ts b/src/common/Registrar.ts index e99cae93..4acd9821 100644 --- a/src/common/Registrar.ts +++ b/src/common/Registrar.ts @@ -24,6 +24,7 @@ import ReRunJob from 'command/ReRunJob'; import RunJob from 'command/RunJob'; import RunWalkthroughJob from 'command/RunWalkthroughJob'; import ShowLogFile from 'command/ShowLogFile'; +import StartDocker from 'command/StartDocker'; import TryProcessAgain from '../command/TryProcessAgain'; import { @@ -59,6 +60,7 @@ export default class Registrar { private runWalkthroughJob: RunWalkthroughJob, private selectRepo: SelectRepo, private showLogFile: ShowLogFile, + private startDocker: StartDocker, private tryProcessAgain: TryProcessAgain ) {} @@ -80,6 +82,7 @@ export default class Registrar { this.runWalkthroughJob, this.selectRepo, this.showLogFile, + this.startDocker, this.tryProcessAgain, ].map((command: Command) => { return this.editorGateway.editor.commands.registerCommand( diff --git a/src/common/RegistrarFactory.ts b/src/common/RegistrarFactory.ts index 3bd50ea8..a22a28fe 100644 --- a/src/common/RegistrarFactory.ts +++ b/src/common/RegistrarFactory.ts @@ -25,6 +25,7 @@ import Refresh from '../command/Refresh'; import RefreshLicenseTree from 'command/RefreshLicenseTree'; import SelectRepo from 'command/SelectRepo'; import ShowLogFile from 'command/ShowLogFile'; +import StartDocker from 'command/StartDocker'; import TryProcessAgain from '../command/TryProcessAgain'; @injectable() @@ -50,6 +51,7 @@ export default class RegistrarFactory { @inject(RunWalkthroughJob) private runWalkthroughJob: RunWalkthroughJob, @inject(SelectRepo) private selectRepo: SelectRepo, @inject(ShowLogFile) private showLogFile: ShowLogFile, + @inject(StartDocker) private startDocker: StartDocker, @inject(TryProcessAgain) private tryProcessAgain: TryProcessAgain, @inject(Types.IEditorGateway) private editorGateway: EditorGateway ) {} @@ -84,6 +86,7 @@ export default class RegistrarFactory { this.runWalkthroughJob, this.selectRepo, this.showLogFile, + this.startDocker, this.tryProcessAgain ); } diff --git a/src/constant/index.ts b/src/constant/index.ts index 00692761..593dad7c 100644 --- a/src/constant/index.ts +++ b/src/constant/index.ts @@ -42,6 +42,7 @@ export const HOST_TMP_DIRECTORY = '/tmp/local-ci'; export const RUN_JOB_COMMAND = 'local-ci.job.run'; export const CREATE_CONFIG_FILE_COMMAND = 'local-ci.create.config'; export const SELECT_REPO_COMMAND = 'localCiJobs.selectRepo'; +export const START_DOCKER_COMMAND = 'local-ci.docker.start'; export const SHOW_LOG_FILE_COMMAND = 'local-ci.show.log-file'; export const LOG_FILE_SCHEME = 'local-ci-log'; export const CONTINUE_PIPELINE_STEP_NAME = 'Continue the pipeline'; diff --git a/src/job/Children.ts b/src/job/Children.ts index 8613f7fd..2d302d34 100644 --- a/src/job/Children.ts +++ b/src/job/Children.ts @@ -18,6 +18,7 @@ import { JOB_TREE_VIEW_ID, PROCESS_TRY_AGAIN_COMMAND, SELECT_REPO_COMMAND, + START_DOCKER_COMMAND, } from 'constant'; type Logs = Record; @@ -128,8 +129,8 @@ export default class Children { switch (errorType) { case JobError.DockerNotRunning: return [ - this.warningFactory.create('Error: is Docker running?'), - new this.editorGateway.editor.TreeItem(errorMessage ?? ''), + this.warningFactory.create(`Docker isn't running`), + this.commandFactory.create('Start Docker', START_DOCKER_COMMAND), this.commandFactory.create( 'Try Again', `${JOB_TREE_VIEW_ID}.refresh` From ac406143bfe43167abe67cdef1fe56d2fa7babfb Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sat, 15 Oct 2022 23:43:19 -0500 Subject: [PATCH 09/22] Add a 'Start Docker' command to do this for users --- src/command/StartDocker.ts | 50 ++++++++++++++++++++++++++++++++++++++ src/job/Children.ts | 5 +++- src/job/ComandFactory.ts | 14 ++--------- src/job/CommandTreeItem.ts | 29 ++++++++++++++++++++++ 4 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 src/command/StartDocker.ts create mode 100644 src/job/CommandTreeItem.ts diff --git a/src/command/StartDocker.ts b/src/command/StartDocker.ts new file mode 100644 index 00000000..222f056f --- /dev/null +++ b/src/command/StartDocker.ts @@ -0,0 +1,50 @@ +import { inject, injectable } from 'inversify'; +import type vscode from 'vscode'; +import type { Command } from './index'; +import { START_DOCKER_COMMAND } from 'constant'; +import Types from 'common/Types'; +import ChildProcessGateway from 'gateway/ChildProcessGateway'; +import CommandTreeItem from 'job/CommandTreeItem'; +import Spawn from 'common/Spawn'; +import EnvPath from 'common/EnvPath'; +import EditorGateway from 'gateway/EditorGateway'; +import JobProvider from 'job/JobProvider'; + +@injectable() +export default class StartDocker implements Command { + @inject(Types.IChildProcessGateway) + childProcessGateway!: ChildProcessGateway; + + @inject(Types.IEditorGateway) + editorGateway!: EditorGateway; + + @inject(EnvPath) + envPath!: EnvPath; + + @inject(Spawn) + spawn!: Spawn; + + commandName: string; + + constructor() { + this.commandName = START_DOCKER_COMMAND; + } + + getCallback(context: vscode.ExtensionContext, jobProvider: JobProvider) { + return async (commandTreeItem: CommandTreeItem) => { + commandTreeItem.setIsRunning(); + jobProvider.refresh(commandTreeItem); + + this.childProcessGateway.cp.spawn( + '/bin/sh', + [ + '-c', + this.envPath.isMac() + ? 'open -a Docker' + : 'systemctl --user start docker-desktop', + ], + this.spawn.getOptions() + ); + }; + } +} diff --git a/src/job/Children.ts b/src/job/Children.ts index 2d302d34..1ff10f61 100644 --- a/src/job/Children.ts +++ b/src/job/Children.ts @@ -129,7 +129,10 @@ export default class Children { switch (errorType) { case JobError.DockerNotRunning: return [ - this.warningFactory.create(`Docker isn't running`), + this.warningCommandFactory.create( + `Please start Docker`, + START_DOCKER_COMMAND + ), this.commandFactory.create('Start Docker', START_DOCKER_COMMAND), this.commandFactory.create( 'Try Again', diff --git a/src/job/ComandFactory.ts b/src/job/ComandFactory.ts index 7c7ea048..6506107f 100644 --- a/src/job/ComandFactory.ts +++ b/src/job/ComandFactory.ts @@ -1,6 +1,7 @@ import { inject, injectable } from 'inversify'; import EditorGateway from 'gateway/EditorGateway'; import Types from 'common/Types'; +import CommandTreeItem from './CommandTreeItem'; @injectable() export default class CommandFactory { @@ -8,17 +9,6 @@ export default class CommandFactory { editorGateway!: EditorGateway; create(label: string, command: string) { - const newCommand = new this.editorGateway.editor.TreeItem(label); - - newCommand.collapsibleState = - this.editorGateway.editor.TreeItemCollapsibleState.None; - newCommand.tooltip = label; - newCommand.command = { - command, - title: label, - tooltip: label, - }; - - return newCommand; + return new CommandTreeItem(this.editorGateway, label, command); } } diff --git a/src/job/CommandTreeItem.ts b/src/job/CommandTreeItem.ts new file mode 100644 index 00000000..e76173fb --- /dev/null +++ b/src/job/CommandTreeItem.ts @@ -0,0 +1,29 @@ +import EditorGateway from 'gateway/EditorGateway'; +import type vscode from 'vscode'; + +export default class CommandTreeItem implements vscode.TreeItem { + collapsibleState: vscode.TreeItemCollapsibleState; + command: vscode.Command; + iconPath?: vscode.ThemeIcon; + tooltip: string; + + constructor( + private editorGateway: EditorGateway, + public label: string, + commandName: string + ) { + this.collapsibleState = + this.editorGateway.editor.TreeItemCollapsibleState.None; + this.tooltip = label; + this.command = { + command: commandName, + title: label, + tooltip: label, + arguments: [this], + }; + } + + setIsRunning() { + this.iconPath = new this.editorGateway.editor.ThemeIcon('sync~spin'); + } +} From 979ffb84593680ef9bb8f3dc835680856cb0277e Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sat, 15 Oct 2022 23:53:29 -0500 Subject: [PATCH 10/22] Change template literals to single quotes --- src/job/Children.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/job/Children.ts b/src/job/Children.ts index 1ff10f61..764e941f 100644 --- a/src/job/Children.ts +++ b/src/job/Children.ts @@ -130,7 +130,7 @@ export default class Children { case JobError.DockerNotRunning: return [ this.warningCommandFactory.create( - `Please start Docker`, + 'Please start Docker', START_DOCKER_COMMAND ), this.commandFactory.create('Start Docker', START_DOCKER_COMMAND), From b7b88685c2654d743b2a5b1aecd65de92f74ee98 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sat, 15 Oct 2022 23:55:21 -0500 Subject: [PATCH 11/22] Remove index from import --- src/command/Complain.ts | 2 +- src/command/EnterLicense.ts | 2 +- src/command/EnterToken.ts | 2 +- src/command/ExitAllJobs.ts | 2 +- src/command/ExitJob.ts | 2 +- src/command/GetLicense.ts | 2 +- src/command/Help.ts | 2 +- src/command/ReRunJob.ts | 2 +- src/command/Refresh.ts | 2 +- src/command/RefreshLicenseTree.ts | 2 +- src/command/RunJob.ts | 2 +- src/command/SelectRepo.ts | 2 +- src/command/ShowLogFile.ts | 2 +- src/command/StartDocker.ts | 2 +- src/command/TryProcessAgain.ts | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/command/Complain.ts b/src/command/Complain.ts index ce88a420..dec59ee1 100644 --- a/src/command/Complain.ts +++ b/src/command/Complain.ts @@ -1,5 +1,5 @@ import { inject, injectable } from 'inversify'; -import type { Command } from './index'; +import type { Command } from '.'; import Types from 'common/Types'; import EditorGateway from 'gateway/EditorGateway'; import { COMPLAIN_COMMAND, COMPLAIN_URL } from 'constant'; diff --git a/src/command/EnterLicense.ts b/src/command/EnterLicense.ts index 337f81f4..b02ad41b 100644 --- a/src/command/EnterLicense.ts +++ b/src/command/EnterLicense.ts @@ -1,6 +1,6 @@ import { inject, injectable } from 'inversify'; import type vscode from 'vscode'; -import type { Command } from './index'; +import type { Command } from '.'; import JobProvider from 'job/JobProvider'; import LicenseInput from 'license/LicenseInput'; import LicenseProvider from 'license/LicenseProvider'; diff --git a/src/command/EnterToken.ts b/src/command/EnterToken.ts index e3fb6b28..189bbeca 100644 --- a/src/command/EnterToken.ts +++ b/src/command/EnterToken.ts @@ -1,6 +1,6 @@ import { inject, injectable } from 'inversify'; import type vscode from 'vscode'; -import type { Command } from './index'; +import type { Command } from '.'; import { getBinaryPath } from '../../node/binary'; import EditorGateway from 'gateway/EditorGateway'; import Types from 'common/Types'; diff --git a/src/command/ExitAllJobs.ts b/src/command/ExitAllJobs.ts index 53c34825..8c45300c 100644 --- a/src/command/ExitAllJobs.ts +++ b/src/command/ExitAllJobs.ts @@ -1,6 +1,6 @@ import { inject, injectable } from 'inversify'; import type vscode from 'vscode'; -import type { Command } from './index'; +import type { Command } from '.'; import Types from 'common/Types'; import CommittedImages from 'containerization/CommittedImages'; import EditorGateway from 'gateway/EditorGateway'; diff --git a/src/command/ExitJob.ts b/src/command/ExitJob.ts index a8e172e3..3f9b4429 100644 --- a/src/command/ExitJob.ts +++ b/src/command/ExitJob.ts @@ -1,6 +1,6 @@ import { inject, injectable } from 'inversify'; import type vscode from 'vscode'; -import type { Command } from './index'; +import type { Command } from '.'; import JobFactory from 'job/JobFactory'; import JobProvider from 'job/JobProvider'; import JobRunner from 'job/JobRunner'; diff --git a/src/command/GetLicense.ts b/src/command/GetLicense.ts index d527c085..e7b79f4d 100644 --- a/src/command/GetLicense.ts +++ b/src/command/GetLicense.ts @@ -1,5 +1,5 @@ import { inject, injectable } from 'inversify'; -import type { Command } from './index'; +import type { Command } from '.'; import Types from 'common/Types'; import EditorGateway from 'gateway/EditorGateway'; import { GET_LICENSE_COMMAND, GET_LICENSE_KEY_URL } from 'constant'; diff --git a/src/command/Help.ts b/src/command/Help.ts index a53d1985..d920694e 100644 --- a/src/command/Help.ts +++ b/src/command/Help.ts @@ -1,5 +1,5 @@ import { inject, injectable } from 'inversify'; -import type { Command } from './index'; +import type { Command } from '.'; import Types from 'common/Types'; import EditorGateway from 'gateway/EditorGateway'; import ReporterGateway from 'gateway/ReporterGateway'; diff --git a/src/command/ReRunJob.ts b/src/command/ReRunJob.ts index ca5f2fda..814eb01b 100644 --- a/src/command/ReRunJob.ts +++ b/src/command/ReRunJob.ts @@ -1,6 +1,6 @@ import { inject, injectable } from 'inversify'; import type vscode from 'vscode'; -import type { Command } from './index'; +import type { Command } from '.'; import Types from 'common/Types'; import EditorGateway from 'gateway/EditorGateway'; import JobProvider from 'job/JobProvider'; diff --git a/src/command/Refresh.ts b/src/command/Refresh.ts index b4c295be..99877144 100644 --- a/src/command/Refresh.ts +++ b/src/command/Refresh.ts @@ -1,6 +1,6 @@ import { injectable } from 'inversify'; import type vscode from 'vscode'; -import type { Command } from './index'; +import type { Command } from '.'; import JobProvider from 'job/JobProvider'; import { JOB_TREE_VIEW_ID } from 'constant'; diff --git a/src/command/RefreshLicenseTree.ts b/src/command/RefreshLicenseTree.ts index d2b63b4f..2b5c01d2 100644 --- a/src/command/RefreshLicenseTree.ts +++ b/src/command/RefreshLicenseTree.ts @@ -1,6 +1,6 @@ import { inject, injectable } from 'inversify'; import type vscode from 'vscode'; -import type { Command } from './index'; +import type { Command } from '.'; import EditorGateway from 'gateway/EditorGateway'; import JobProvider from 'job/JobProvider'; import LicenseProvider from 'license/LicenseProvider'; diff --git a/src/command/RunJob.ts b/src/command/RunJob.ts index c4f541de..5a7fe137 100644 --- a/src/command/RunJob.ts +++ b/src/command/RunJob.ts @@ -1,6 +1,6 @@ import { inject, injectable } from 'inversify'; import type vscode from 'vscode'; -import type { Command } from './index'; +import type { Command } from '.'; import Types from 'common/Types'; import EditorGateway from 'gateway/EditorGateway'; import JobProvider from 'job/JobProvider'; diff --git a/src/command/SelectRepo.ts b/src/command/SelectRepo.ts index 9f38306b..2c065327 100644 --- a/src/command/SelectRepo.ts +++ b/src/command/SelectRepo.ts @@ -1,6 +1,6 @@ import { inject, injectable } from 'inversify'; import type vscode from 'vscode'; -import type { Command } from './index'; +import type { Command } from '.'; import Types from 'common/Types'; import AllConfigFiles from 'config/AllConfigFiles'; import CommittedImages from 'containerization/CommittedImages'; diff --git a/src/command/ShowLogFile.ts b/src/command/ShowLogFile.ts index 237cdd3d..92df6cbd 100644 --- a/src/command/ShowLogFile.ts +++ b/src/command/ShowLogFile.ts @@ -1,5 +1,5 @@ import { inject, injectable } from 'inversify'; -import type { Command } from './index'; +import type { Command } from '.'; import LogFile from 'log/LogFile'; import { SHOW_LOG_FILE_COMMAND } from 'constant'; diff --git a/src/command/StartDocker.ts b/src/command/StartDocker.ts index 222f056f..d888b2ad 100644 --- a/src/command/StartDocker.ts +++ b/src/command/StartDocker.ts @@ -1,6 +1,6 @@ import { inject, injectable } from 'inversify'; import type vscode from 'vscode'; -import type { Command } from './index'; +import type { Command } from '.'; import { START_DOCKER_COMMAND } from 'constant'; import Types from 'common/Types'; import ChildProcessGateway from 'gateway/ChildProcessGateway'; diff --git a/src/command/TryProcessAgain.ts b/src/command/TryProcessAgain.ts index 8f682173..6824b04a 100644 --- a/src/command/TryProcessAgain.ts +++ b/src/command/TryProcessAgain.ts @@ -1,5 +1,5 @@ import { inject, injectable } from 'inversify'; -import type { Command } from './index'; +import type { Command } from '.'; import type vscode from 'vscode'; import ConfigFile from 'config/ConfigFile'; import FsGateway from 'gateway/FsGateway'; From 80f728d8b9108c91dedc9cbb86c9ce39f8d1bf9b Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sat, 15 Oct 2022 23:59:19 -0500 Subject: [PATCH 12/22] Capitalize 'Start' in 'Please Start Docker' --- src/job/Children.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/job/Children.ts b/src/job/Children.ts index 764e941f..92ad89c9 100644 --- a/src/job/Children.ts +++ b/src/job/Children.ts @@ -130,7 +130,7 @@ export default class Children { case JobError.DockerNotRunning: return [ this.warningCommandFactory.create( - 'Please start Docker', + 'Please Start Docker', START_DOCKER_COMMAND ), this.commandFactory.create('Start Docker', START_DOCKER_COMMAND), From 717239f35bdbc2c81fe836e3217ba8bf660e7426 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 17 Oct 2022 00:09:31 -0500 Subject: [PATCH 13/22] Extract the env var method into a class that can be injected --- src/common/AppIoc.ts | 2 + src/common/Types.ts | 1 + src/process/ProcessFile.ts | 32 ++---------- src/process/test/ProcessFile.spec.ts | 4 +- src/test-tool/expected/dynamic-config.yml | 13 +++-- src/test-tool/expected/with-cache.yml | 62 ++++++++++++++++++++--- src/test-tool/helper/AppTestHarness.ts | 2 + 7 files changed, 73 insertions(+), 43 deletions(-) diff --git a/src/common/AppIoc.ts b/src/common/AppIoc.ts index 18ddfddd..43250d12 100644 --- a/src/common/AppIoc.ts +++ b/src/common/AppIoc.ts @@ -2,6 +2,7 @@ import 'reflect-metadata'; import BaseIoc from 'common/BaseIoc'; import ChildProcessGateway from 'gateway/ChildProcessGateway'; import EditorGateway from 'gateway/EditorGateway'; +import EnvVar from 'process/EnvVar'; import FsGateway from 'gateway/FsGateway'; import HttpGateway from 'gateway/HttpGateway'; import OsGateway from 'gateway/OsGateway'; @@ -16,6 +17,7 @@ iocContainer .to(ChildProcessGateway) .inSingletonScope(); iocContainer.bind(Types.IEditorGateway).to(EditorGateway).inSingletonScope(); +iocContainer.bind(Types.IEnvVar).to(EnvVar).inSingletonScope(); iocContainer.bind(Types.IFsGateway).to(FsGateway).inSingletonScope(); iocContainer.bind(Types.IHttpGateway).to(HttpGateway).inSingletonScope(); iocContainer.bind(Types.IOsGateway).to(OsGateway).inSingletonScope(); diff --git a/src/common/Types.ts b/src/common/Types.ts index 38d7de5f..e08f58a3 100644 --- a/src/common/Types.ts +++ b/src/common/Types.ts @@ -1,6 +1,7 @@ export default { IChildProcessGateway: Symbol.for('IChildProcessGateway'), IEditorGateway: Symbol.for('IEditorGateway'), + IEnvVar: Symbol.for('IEnvVar'), IFsGateway: Symbol.for('IFsGateway'), IHttpGateway: Symbol.for('IHttpGateway'), IOsGateway: Symbol.for('IOsGateway'), diff --git a/src/process/ProcessFile.ts b/src/process/ProcessFile.ts index 82e48e5d..202ef7d5 100644 --- a/src/process/ProcessFile.ts +++ b/src/process/ProcessFile.ts @@ -14,15 +14,18 @@ import { DYNAMIC_CONFIG_PARAMETERS_FILE_NAME, DYNAMIC_CONFIG_PATH_IN_CONTAINER, } from 'constant'; -import { addEnvVars } from 'script'; import ChildProcessGateway from 'gateway/ChildProcessGateway'; import Spawn from 'common/Spawn'; +import EnvVar from './EnvVar'; @injectable() export default class ProcessFile { @inject(Types.IChildProcessGateway) childProcessGateway!: ChildProcessGateway; + @inject(Types.IEnvVar) + envVar!: EnvVar; + @inject(Types.IFsGateway) fsGateway!: FsGateway; @@ -148,7 +151,7 @@ export default class ProcessFile { ...configJobs[jobName], steps: [ this.getEnsureVolumeIsWritableStep(), - this.getEnvVarStep(repoPath), + this.envVar.getStep(repoPath), ...(newSteps ?? []), ], }, @@ -224,29 +227,4 @@ export default class ProcessFile { }, }; } - - private getEnvVarStep(repoPath: string) { - let command; - try { - const exportVars = this.childProcessGateway.cp - .execSync(addEnvVars, { - ...this.spawn.getOptions(repoPath), - timeout: 2000, - }) - .toString(); - - command = `echo '${exportVars}' >> $BASH_ENV`; - } catch (error) { - command = `There was an error setting the variables: ${ - (error as ErrorWithMessage).message - }`; - } - - return { - run: { - name: 'Set more environment variables', - command, - }, - }; - } } diff --git a/src/process/test/ProcessFile.spec.ts b/src/process/test/ProcessFile.spec.ts index dd4560a2..9d820329 100644 --- a/src/process/test/ProcessFile.spec.ts +++ b/src/process/test/ProcessFile.spec.ts @@ -21,7 +21,7 @@ describe('ProcessFile', () => { const processFile = testHarness.container.get(ProcessFile); const writeFileSpy = jest.fn(); fsGateway.fs.writeFileSync = writeFileSpy; - processFile.write(withCacheFixture, '/foo/baz/'); + processFile.write(withCacheFixture, '/foo/baz/', '/your/repo/'); expect(writeFileSpy).toHaveBeenCalledTimes(1); expect(normalize(writeFileSpy.mock.lastCall[1])).toEqual( @@ -33,7 +33,7 @@ describe('ProcessFile', () => { const processFile = testHarness.container.get(ProcessFile); const writeFileSpy = jest.fn(); fsGateway.fs.writeFileSync = writeFileSpy; - processFile.write(dyanamicConfigFixture, '/foo/baz/'); + processFile.write(dyanamicConfigFixture, '/foo/baz/', '/your/repo/'); expect(writeFileSpy).toHaveBeenCalledTimes(1); expect(normalize(writeFileSpy.mock.lastCall[1])).toEqual( diff --git a/src/test-tool/expected/dynamic-config.yml b/src/test-tool/expected/dynamic-config.yml index 38a315e3..92c41794 100644 --- a/src/test-tool/expected/dynamic-config.yml +++ b/src/test-tool/expected/dynamic-config.yml @@ -11,15 +11,14 @@ jobs: then sudo chown $(whoami) /tmp/local-ci fi - - checkout - run: name: Set more environment variables - command: > - { - echo 'export CIRCLE_SHA1=$(git rev-parse HEAD)' - echo 'export CIRCLE_BRANCH=$(git rev-parse --abbrev-ref HEAD)' - echo 'export CIRCLE_PROJECT_REPONAME=$(basename $(git remote get-url origin))' - } >> "$BASH_ENV" + command: |- + echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + echo "export CIRCLE_BRANCH=develop" + echo "export CIRCLE_PROJECT_REPONAME=local-ci" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" + - checkout - run: name: Create config command: echo "Creating the dynamic config here" diff --git a/src/test-tool/expected/with-cache.yml b/src/test-tool/expected/with-cache.yml index f03c58a3..176deafb 100644 --- a/src/test-tool/expected/with-cache.yml +++ b/src/test-tool/expected/with-cache.yml @@ -14,15 +14,14 @@ jobs: then sudo chown $(whoami) /tmp/local-ci fi - - checkout - run: name: Set more environment variables - command: > - { - echo 'export CIRCLE_SHA1=$(git rev-parse HEAD)' - echo 'export CIRCLE_BRANCH=$(git rev-parse --abbrev-ref HEAD)' - echo 'export CIRCLE_PROJECT_REPONAME=$(basename $(git remote get-url origin))' - } >> "$BASH_ENV" + command: |- + echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + echo "export CIRCLE_BRANCH=develop" + echo "export CIRCLE_PROJECT_REPONAME=local-ci" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" + - checkout - run: name: Restore cache command: > @@ -91,6 +90,13 @@ jobs: then sudo chown $(whoami) /tmp/local-ci fi + - run: + name: Set more environment variables + command: |- + echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + echo "export CIRCLE_BRANCH=develop" + echo "export CIRCLE_PROJECT_REPONAME=local-ci" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" - run: name: Attach workspace command: |- @@ -130,6 +136,13 @@ jobs: then sudo chown $(whoami) /tmp/local-ci fi + - run: + name: Set more environment variables + command: |- + echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + echo "export CIRCLE_BRANCH=develop" + echo "export CIRCLE_PROJECT_REPONAME=local-ci" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" - run: name: Attach workspace command: |- @@ -155,6 +168,13 @@ jobs: then sudo chown $(whoami) /tmp/local-ci fi + - run: + name: Set more environment variables + command: |- + echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + echo "export CIRCLE_BRANCH=develop" + echo "export CIRCLE_PROJECT_REPONAME=local-ci" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" - run: name: Attach workspace command: |- @@ -180,6 +200,13 @@ jobs: then sudo chown $(whoami) /tmp/local-ci fi + - run: + name: Set more environment variables + command: |- + echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + echo "export CIRCLE_BRANCH=develop" + echo "export CIRCLE_PROJECT_REPONAME=local-ci" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" - run: name: Attach workspace command: |- @@ -232,6 +259,13 @@ jobs: then sudo chown $(whoami) /tmp/local-ci fi + - run: + name: Set more environment variables + command: |- + echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + echo "export CIRCLE_BRANCH=develop" + echo "export CIRCLE_PROJECT_REPONAME=local-ci" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" - run: name: Attach workspace command: |- @@ -260,6 +294,13 @@ jobs: then sudo chown $(whoami) /tmp/local-ci fi + - run: + name: Set more environment variables + command: |- + echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + echo "export CIRCLE_BRANCH=develop" + echo "export CIRCLE_PROJECT_REPONAME=local-ci" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" - run: name: Attach workspace command: |- @@ -285,6 +326,13 @@ jobs: then sudo chown $(whoami) /tmp/local-ci fi + - run: + name: Set more environment variables + command: |- + echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + echo "export CIRCLE_BRANCH=develop" + echo "export CIRCLE_PROJECT_REPONAME=local-ci" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" - run: name: Attach workspace command: |- diff --git a/src/test-tool/helper/AppTestHarness.ts b/src/test-tool/helper/AppTestHarness.ts index 53cf17e9..133812ab 100644 --- a/src/test-tool/helper/AppTestHarness.ts +++ b/src/test-tool/helper/AppTestHarness.ts @@ -8,6 +8,7 @@ import FakeHttpGateway from 'gateway/FakeHttpGateway'; import FakeOsGateway from 'gateway/FakeOsGateway'; import FakeProcessGateway from 'gateway/FakeProcessGateway'; import FakeReporterGateway from 'gateway/FakeReporterGateway'; +import FakeEnvVar from 'process/FakeEnvVar'; export default class AppTestHarness { container!: Container; @@ -25,6 +26,7 @@ export default class AppTestHarness { .bind(Types.IChildProcessGateway) .to(FakeChildProcessGateway) .inSingletonScope(); + this.container.bind(Types.IEnvVar).to(FakeEnvVar).inSingletonScope(); this.container .bind(Types.IEditorGateway) .to(FakeEditorGateway) From c35a9d804811fe40bce5eab7135baf8e7b8170c6 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 17 Oct 2022 00:10:02 -0500 Subject: [PATCH 14/22] Add the EnvVar class I forgot to stage --- src/process/EnvVar.ts | 39 +++++++++++++++++++++++++++++++++++++++ src/process/FakeEnvVar.ts | 16 ++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/process/EnvVar.ts create mode 100644 src/process/FakeEnvVar.ts diff --git a/src/process/EnvVar.ts b/src/process/EnvVar.ts new file mode 100644 index 00000000..63c27c02 --- /dev/null +++ b/src/process/EnvVar.ts @@ -0,0 +1,39 @@ +import { injectable, inject } from 'inversify'; +import Types from 'common/Types'; +import { addEnvVars } from 'script'; +import ChildProcessGateway from 'gateway/ChildProcessGateway'; +import Spawn from 'common/Spawn'; + +@injectable() +export default class EnvVar { + @inject(Types.IChildProcessGateway) + childProcessGateway!: ChildProcessGateway; + + @inject(Spawn) + spawn!: Spawn; + + getStep(repoPath: string) { + let command; + try { + const exportVars = this.childProcessGateway.cp + .execSync(addEnvVars, { + ...this.spawn.getOptions(repoPath), + timeout: 2000, + }) + .toString(); + + command = `echo '${exportVars}' >> $BASH_ENV`; + } catch (error) { + command = `echo "There was an error setting the variables: ${ + (error as ErrorWithMessage).message + }"`; + } + + return { + run: { + name: 'Set more environment variables command', + command, + }, + }; + } +} diff --git a/src/process/FakeEnvVar.ts b/src/process/FakeEnvVar.ts new file mode 100644 index 00000000..f0b492f3 --- /dev/null +++ b/src/process/FakeEnvVar.ts @@ -0,0 +1,16 @@ +import { injectable } from 'inversify'; + +@injectable() +export default class FakeEnvVar { + getStep() { + return { + run: { + name: 'Set more environment variables', + command: `echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + echo "export CIRCLE_BRANCH=develop" + echo "export CIRCLE_PROJECT_REPONAME=local-ci" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git"`, + }, + }; + } +} From c27579d8bce60e6d38ab03c5943905d4d9d8c08c Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 17 Oct 2022 00:28:55 -0500 Subject: [PATCH 15/22] Remove needless childProcessGateway property --- src/config/Config.ts | 2 +- src/job/Children.ts | 2 +- src/job/JobRunner.ts | 2 +- src/process/ProcessFile.ts | 4 ---- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/config/Config.ts b/src/config/Config.ts index 2f93758f..32cc216d 100644 --- a/src/config/Config.ts +++ b/src/config/Config.ts @@ -8,11 +8,11 @@ import getDynamicConfigParametersPath from './getDynamicConfigParametersPath'; import getDynamicConfigPath from './getDynamicConfigPath'; import getProcessedConfig from './getProcessedConfig'; import getProcessFilePath from 'process/getProcessFilePath'; +import getRepoPath from 'common/getRepoPath'; import ProcessFile from 'process/ProcessFile'; import ReporterGateway from 'gateway/ReporterGateway'; import Spawn from 'common/Spawn'; import Types from 'common/Types'; -import getRepoPath from 'common/getRepoPath'; @injectable() export default class Config { diff --git a/src/job/Children.ts b/src/job/Children.ts index 8613f7fd..5a5fde9f 100644 --- a/src/job/Children.ts +++ b/src/job/Children.ts @@ -89,7 +89,7 @@ export default class Children { return [ ...this.getLogTreeItems( logs, - 'getJobName' in parentElement ? parentElement.getJobName() : '' + 'getJobName' in parentElement ? parentElement?.getJobName() : '' ), ...this.getJobTreeItems(children, logs, runningJob, jobDependencies), ]; diff --git a/src/job/JobRunner.ts b/src/job/JobRunner.ts index 151523fa..a03e5acb 100644 --- a/src/job/JobRunner.ts +++ b/src/job/JobRunner.ts @@ -17,6 +17,7 @@ import getImageFromJob from 'containerization/getImageFromJob'; import getLogFilePath from 'log/getLogFilePath'; import getLocalVolumePath from 'containerization/getLocalVolumePath'; import getProcessFilePath from 'process/getProcessFilePath'; +import getRepoPath from 'common/getRepoPath'; import getTerminalName from 'terminal/getTerminalName'; import JobFactory from 'job/JobFactory'; import JobListener from './JobListener'; @@ -36,7 +37,6 @@ import { dockerExecRunningContainer, getRunningContainerFunction, } from 'script'; -import getRepoPath from 'common/getRepoPath'; @injectable() export default class JobRunner { diff --git a/src/process/ProcessFile.ts b/src/process/ProcessFile.ts index 202ef7d5..4d65676e 100644 --- a/src/process/ProcessFile.ts +++ b/src/process/ProcessFile.ts @@ -14,15 +14,11 @@ import { DYNAMIC_CONFIG_PARAMETERS_FILE_NAME, DYNAMIC_CONFIG_PATH_IN_CONTAINER, } from 'constant'; -import ChildProcessGateway from 'gateway/ChildProcessGateway'; import Spawn from 'common/Spawn'; import EnvVar from './EnvVar'; @injectable() export default class ProcessFile { - @inject(Types.IChildProcessGateway) - childProcessGateway!: ChildProcessGateway; - @inject(Types.IEnvVar) envVar!: EnvVar; From 85eb1ed2cd3ab2d4c8610e89cfd48e150f563338 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 17 Oct 2022 00:30:02 -0500 Subject: [PATCH 16/22] Remove needless spawn property --- src/process/ProcessFile.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/process/ProcessFile.ts b/src/process/ProcessFile.ts index 4d65676e..177e697b 100644 --- a/src/process/ProcessFile.ts +++ b/src/process/ProcessFile.ts @@ -14,7 +14,6 @@ import { DYNAMIC_CONFIG_PARAMETERS_FILE_NAME, DYNAMIC_CONFIG_PATH_IN_CONTAINER, } from 'constant'; -import Spawn from 'common/Spawn'; import EnvVar from './EnvVar'; @injectable() @@ -25,9 +24,6 @@ export default class ProcessFile { @inject(Types.IFsGateway) fsGateway!: FsGateway; - @inject(Spawn) - spawn!: Spawn; - /** * Overwrites parts of the process.yml file. * From 5aad98f9563ce828b805ae03fef6567801e15239 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 17 Oct 2022 00:45:12 -0500 Subject: [PATCH 17/22] Update the unit test expected .yml files --- src/process/FakeEnvVar.ts | 4 +- src/test-tool/expected/dynamic-config.yml | 6 +-- src/test-tool/expected/with-cache.yml | 48 +++++++++++------------ 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/process/FakeEnvVar.ts b/src/process/FakeEnvVar.ts index f0b492f3..444e5504 100644 --- a/src/process/FakeEnvVar.ts +++ b/src/process/FakeEnvVar.ts @@ -6,10 +6,10 @@ export default class FakeEnvVar { return { run: { name: 'Set more environment variables', - command: `echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + command: `echo 'echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" echo "export CIRCLE_BRANCH=develop" echo "export CIRCLE_PROJECT_REPONAME=local-ci" - echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git"`, + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git"' >> $BASH_ENV`, }, }; } diff --git a/src/test-tool/expected/dynamic-config.yml b/src/test-tool/expected/dynamic-config.yml index 92c41794..f8da6b84 100644 --- a/src/test-tool/expected/dynamic-config.yml +++ b/src/test-tool/expected/dynamic-config.yml @@ -13,11 +13,11 @@ jobs: fi - run: name: Set more environment variables - command: |- - echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + command: >- + echo 'echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" echo "export CIRCLE_BRANCH=develop" echo "export CIRCLE_PROJECT_REPONAME=local-ci" - echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git"' >> $BASH_ENV - checkout - run: name: Create config diff --git a/src/test-tool/expected/with-cache.yml b/src/test-tool/expected/with-cache.yml index 176deafb..6b571496 100644 --- a/src/test-tool/expected/with-cache.yml +++ b/src/test-tool/expected/with-cache.yml @@ -16,11 +16,11 @@ jobs: fi - run: name: Set more environment variables - command: |- - echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + command: >- + echo 'echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" echo "export CIRCLE_BRANCH=develop" echo "export CIRCLE_PROJECT_REPONAME=local-ci" - echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git"' >> $BASH_ENV - checkout - run: name: Restore cache @@ -92,11 +92,11 @@ jobs: fi - run: name: Set more environment variables - command: |- - echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + command: >- + echo 'echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" echo "export CIRCLE_BRANCH=develop" echo "export CIRCLE_PROJECT_REPONAME=local-ci" - echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git"' >> $BASH_ENV - run: name: Attach workspace command: |- @@ -138,11 +138,11 @@ jobs: fi - run: name: Set more environment variables - command: |- - echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + command: >- + echo 'echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" echo "export CIRCLE_BRANCH=develop" echo "export CIRCLE_PROJECT_REPONAME=local-ci" - echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git"' >> $BASH_ENV - run: name: Attach workspace command: |- @@ -170,11 +170,11 @@ jobs: fi - run: name: Set more environment variables - command: |- - echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + command: >- + echo 'echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" echo "export CIRCLE_BRANCH=develop" echo "export CIRCLE_PROJECT_REPONAME=local-ci" - echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git"' >> $BASH_ENV - run: name: Attach workspace command: |- @@ -202,11 +202,11 @@ jobs: fi - run: name: Set more environment variables - command: |- - echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + command: >- + echo 'echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" echo "export CIRCLE_BRANCH=develop" echo "export CIRCLE_PROJECT_REPONAME=local-ci" - echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git"' >> $BASH_ENV - run: name: Attach workspace command: |- @@ -261,11 +261,11 @@ jobs: fi - run: name: Set more environment variables - command: |- - echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + command: >- + echo 'echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" echo "export CIRCLE_BRANCH=develop" echo "export CIRCLE_PROJECT_REPONAME=local-ci" - echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git"' >> $BASH_ENV - run: name: Attach workspace command: |- @@ -296,11 +296,11 @@ jobs: fi - run: name: Set more environment variables - command: |- - echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + command: >- + echo 'echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" echo "export CIRCLE_BRANCH=develop" echo "export CIRCLE_PROJECT_REPONAME=local-ci" - echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git"' >> $BASH_ENV - run: name: Attach workspace command: |- @@ -328,11 +328,11 @@ jobs: fi - run: name: Set more environment variables - command: |- - echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" + command: >- + echo 'echo "export CIRCLE_SHA1=037f2d35d59080dc313608c565b55f37d2f42c7e" echo "export CIRCLE_BRANCH=develop" echo "export CIRCLE_PROJECT_REPONAME=local-ci" - echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git" + echo "export CIRCLE_REPOSITORY_URL=git@github.com:getlocalci/local-ci.git"' >> $BASH_ENV - run: name: Attach workspace command: |- From b4782091e77317c75a8baea8f2a56e0a95033ba0 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 17 Oct 2022 00:59:48 -0500 Subject: [PATCH 18/22] Remove needless editorGateway --- src/command/StartDocker.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/command/StartDocker.ts b/src/command/StartDocker.ts index d888b2ad..dc997027 100644 --- a/src/command/StartDocker.ts +++ b/src/command/StartDocker.ts @@ -7,7 +7,6 @@ import ChildProcessGateway from 'gateway/ChildProcessGateway'; import CommandTreeItem from 'job/CommandTreeItem'; import Spawn from 'common/Spawn'; import EnvPath from 'common/EnvPath'; -import EditorGateway from 'gateway/EditorGateway'; import JobProvider from 'job/JobProvider'; @injectable() @@ -15,9 +14,6 @@ export default class StartDocker implements Command { @inject(Types.IChildProcessGateway) childProcessGateway!: ChildProcessGateway; - @inject(Types.IEditorGateway) - editorGateway!: EditorGateway; - @inject(EnvPath) envPath!: EnvPath; From 03157bfc271e7b78b3fc5c36fa7455cc64f965b4 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 17 Oct 2022 01:03:21 -0500 Subject: [PATCH 19/22] Add the start Docker command to the expected commands --- src/common/test/LocalCi.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/test/LocalCi.spec.ts b/src/common/test/LocalCi.spec.ts index b56c3472..be3ae6c1 100644 --- a/src/common/test/LocalCi.spec.ts +++ b/src/common/test/LocalCi.spec.ts @@ -36,6 +36,7 @@ describe('LocalCi', () => { 'local-ci.runWalkthroughJob', 'localCiJobs.selectRepo', 'local-ci.show.log-file', + 'local-ci.docker.start', 'local-ci.process-error.try-again', ]; From d25140c662ed097e166fba114422dad61ab93abc Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 17 Oct 2022 01:06:18 -0500 Subject: [PATCH 20/22] Remove a needless async keyword --- src/command/StartDocker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/StartDocker.ts b/src/command/StartDocker.ts index dc997027..eac2e4f4 100644 --- a/src/command/StartDocker.ts +++ b/src/command/StartDocker.ts @@ -27,7 +27,7 @@ export default class StartDocker implements Command { } getCallback(context: vscode.ExtensionContext, jobProvider: JobProvider) { - return async (commandTreeItem: CommandTreeItem) => { + return (commandTreeItem: CommandTreeItem) => { commandTreeItem.setIsRunning(); jobProvider.refresh(commandTreeItem); From dd74c0c2a9ad9acf32ba3ddfd5b51f96f67bfca9 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 17 Oct 2022 01:15:36 -0500 Subject: [PATCH 21/22] Bump the version to 2.0.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 07c088a9..24bd520d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "local-ci", - "version": "1.9.8", + "version": "2.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "local-ci", - "version": "1.9.8", + "version": "2.0.0", "hasInstallScript": true, "license": "GPL-2.0-or-later", "os": [ diff --git a/package.json b/package.json index 3630bf7b..923ac0b5 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.9.8", + "version": "2.0.0", "publisher": "LocalCI", "contributors": [ "Ryan Kienstra" From ab7845885f6dccf312d63ad1d422b0c2e1ba6439 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 17 Oct 2022 01:18:40 -0500 Subject: [PATCH 22/22] Add a CHANGELOG entry for 2.0.0 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e505a2a..aa66070e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## 2.0.0 - 17 October 2022 +- Add a button 'Start Docker'. [#214](https://github.com/getlocalci/local-ci/pull/214) +- Bump the binary version to the latest: v0.1.22272. [#212](https://github.com/getlocalci/local-ci/pull/212) +- Make the additional env vars more robust. [#213](https://github.com/getlocalci/local-ci/pull/213) +- Allow clicking a warning, like 'Please select repo'. [#211](https://github.com/getlocalci/local-ci/pull/211) + ## 1.9.8 - 10 October 2022 - Reload after certain failures, like if Docker isn't running. [#208](https://github.com/getlocalci/local-ci/pull/208)