+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cache/getRestoreCacheCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { restoreCache } from 'script';
export default function getRestoreCacheCommand(
restoreCacheStep: FullStep,
saveCacheSteps: (SaveCache | undefined)[]
): string | undefined {
): string {
const originalSaveCacheStep = saveCacheSteps.find(
(saveCacheStep) =>
(!!restoreCacheStep?.restore_cache?.key &&
Expand Down
30 changes: 15 additions & 15 deletions src/cache/getSaveCacheCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ import * as path from 'path';
import convertToBash from './convertToBash';
import { CONTAINER_STORAGE_DIRECTORY } from 'constant';

export default function getSaveCacheCommand(
step: FullStep
): string | undefined {
return step?.save_cache?.paths.reduce((accumulator, directory) => {
const destination = path.join(
CONTAINER_STORAGE_DIRECTORY,
convertToBash(step?.save_cache?.key ?? '')
);
const destinationWhenCopied = path.join(
destination,
path.basename(directory)
);
export default function getSaveCacheCommand(step: FullStep): string {
return (
step?.save_cache?.paths.reduce((accumulator, directory) => {
const destination = path.join(
CONTAINER_STORAGE_DIRECTORY,
convertToBash(step?.save_cache?.key ?? '')
);
const destinationWhenCopied = path.join(
destination,
path.basename(directory)
);

// BusyBox doesn't allow cp -n.
return `${accumulator} if [ -d ${destinationWhenCopied} ]
// BusyBox doesn't allow cp -n.
return `${accumulator} if [ -d ${destinationWhenCopied} ]
then
echo "${directory} is already cached, skipping"
elif [ ! -d ${directory} ]
Expand All @@ -27,5 +26,6 @@ export default function getSaveCacheCommand(
mkdir -p ${destination}
cp -rn ${directory} ${destinationWhenCopied} || cp -ru ${directory} ${destinationWhenCopied}
fi \n`;
}, '');
}, '') ?? ''
);
}
2 changes: 2 additions & 0 deletions src/common/AppIoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import OsGateway from 'gateway/OsGateway';
import ProcessGateway from 'gateway/ProcessGateway';
import ReporterGateway from 'gateway/ReporterGateway';
import Types from 'common/Types';
import Volume from 'containerization/Volume';

export const iocContainer = new BaseIoc().buildBaseTemplate();

Expand All @@ -26,3 +27,4 @@ iocContainer
.bind(Types.IReporterGateway)
.to(ReporterGateway)
.inSingletonScope();
iocContainer.bind(Types.IVolume).to(Volume).inSingletonScope();
2 changes: 2 additions & 0 deletions src/common/BaseIoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import LogFactory from 'log/LogFactory';
import LogFile from 'log/LogFile';
import LogProviderFactory from 'log/LogProviderFactory';
import ParsedConfig from 'config/ParsedConfig';
import Persistence from 'process/Persistence';
import PipelineParameter from 'config/PipelineParameter';
import ProcessFile from 'process/ProcessFile';
import Refresh from 'command/Refresh';
Expand Down Expand Up @@ -94,6 +95,7 @@ export default class BaseIoc {
this.container.bind(LicenseProviderFactory).toSelf();
this.container.bind(LogProviderFactory).toSelf();
this.container.bind(ParsedConfig).toSelf();
this.container.bind(Persistence).toSelf();
this.container.bind(PipelineParameter).toSelf();
this.container.bind(ProcessFile).toSelf();
this.container.bind(Refresh).toSelf();
Expand Down
1 change: 1 addition & 0 deletions src/common/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export default {
IOsGateway: Symbol.for('IOsGateway'),
IProcessGateway: Symbol.for('IProcessGateway'),
IReporterGateway: Symbol.for('IReporterGateway'),
IVolume: Symbol.for('IVolume'),
};
12 changes: 4 additions & 8 deletions src/config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import EditorGateway from 'gateway/EditorGateway';
import FsGateway from 'gateway/FsGateway';
import getDynamicConfigParametersPath from './getDynamicConfigParametersPath';
import getDynamicConfigPath from './getDynamicConfigPath';
import getDynamicConfigProcessFilePath from 'process/getDynamicConfigProcessFilePath';
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';
Expand Down Expand Up @@ -56,11 +56,7 @@ export default class Config {
this.childProcessGateway.cp,
this.spawn.getOptions()
);
this.processFile.write(
processedConfig,
processFilePath,
getRepoPath(configFilePath)
);
this.processFile.write(processedConfig, processFilePath, configFilePath);

const dynamicConfigFilePath = getDynamicConfigPath(configFilePath);
if (this.fsGateway.fs.existsSync(dynamicConfigFilePath)) {
Expand All @@ -75,8 +71,8 @@ export default class Config {
this.childProcessGateway.cp,
this.spawn.getOptions()
),
dynamicConfigFilePath,
getRepoPath(configFilePath)
getDynamicConfigProcessFilePath(configFilePath),
configFilePath
);
}
} catch (e) {
Expand Down
6 changes: 6 additions & 0 deletions src/containerization/FakeVolume.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { injectable } from 'inversify';

@injectable()
export default class FakeVolume {
isEmpty = () => false;
}
26 changes: 26 additions & 0 deletions src/containerization/Volume.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { inject, injectable } from 'inversify';
import Types from 'common/Types';
import ConfigFile from '../config/ConfigFile';
import FsGateway from 'gateway/FsGateway';
import getLocalVolumePath from 'containerization/getLocalVolumePath';
import { DYNAMIC_CONFIG_FILE_NAME } from 'constant';

@injectable()
export default class Volume {
@inject(Types.IFsGateway)
fsGateway!: FsGateway;

@inject(ConfigFile)
configFile!: ConfigFile;

isEmpty(configFilePath: string): boolean {
const localConfigFile = getLocalVolumePath(configFilePath);
if (!this.fsGateway.fs.existsSync(localConfigFile)) {
return true;
}

return !this.fsGateway.fs.readdirSync(localConfigFile).some((file) => {
return file !== DYNAMIC_CONFIG_FILE_NAME;
});
}
}
24 changes: 17 additions & 7 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ interface SaveCache {
paths: Array<string>;
}

interface Checkout {
path: string;
}

// See https://circleci.com/docs/2.0/configuration-reference/
interface FullStep {
checkout?: Record<string, unknown> | string;
checkout?: Checkout;
attach_workspace?: {
at: string;
};
Expand Down Expand Up @@ -34,8 +38,12 @@ interface FullStep {

type Step = FullStep | string | 'checkout';

interface Docker {
[key: string]: string;
}

interface Job {
docker?: Array<Record<string, string>>;
docker?: Docker[];
steps?: Step[];
working_directory?: string;
machine?: { image?: string };
Expand All @@ -56,17 +64,19 @@ interface Jobs {
[key: string]: Job;
}

interface CiConfigWithJobs {
interface WorkflowJobs {
jobs: {[key: string]: {[key: string]: unknown} | string }[];
}

interface CiConfigWithWorkflows {
orbs?: { [key: string]: Orb };
jobs?: Jobs;
workflows: {
[key: string]: {
jobs: (Record<string, Record<string, unknown>>|string)[];
}
[key: string]: WorkflowJobs;
}
}

type CiConfig = CiConfigWithJobs | undefined;
type CiConfig = CiConfigWithWorkflows | undefined;

interface ConfigFileQuickPick {
label: string;
Expand Down
5 changes: 3 additions & 2 deletions src/job/JobRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import FinalTerminal from 'terminal/FinalTerminal';
import FsGateway from 'gateway/FsGateway';
import getCheckoutJobs from './getCheckoutJobs';
import getDebuggingTerminalName from 'terminal/getDebuggingTerminalName';
import getDynamicConfigPath from 'config/getDynamicConfigPath';
import getDynamicConfigProcessFilePath from 'process/getDynamicConfigProcessFilePath';
import getFinalDebuggingTerminalName from 'terminal/getFinalTerminalName';
import getImageFromJob from 'containerization/getImageFromJob';
import getLogFilePath from 'log/getLogFilePath';
Expand Down Expand Up @@ -104,7 +104,8 @@ export default class JobRunner {
const processFilePath = getProcessFilePath(configFilePath);
const parsedProcessFile = this.parsedConfig.get(processFilePath);

const dynamicConfigFilePath = getDynamicConfigPath(configFilePath);
const dynamicConfigFilePath =
getDynamicConfigProcessFilePath(configFilePath);
const parsedDynamicConfigFile = this.parsedConfig.get(
dynamicConfigFilePath
);
Expand Down
5 changes: 4 additions & 1 deletion src/job/getJobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export default function getJobs(
const jobConfig = Object.values(job).length
? Object.values(job)[0]
: null;
allJobs.set(jobName, jobConfig?.requires);

if (typeof jobConfig !== 'string') {
allJobs.set(jobName, jobConfig?.requires);
}
}
}
}
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载