From ba649ef0b9c7f759e04ae022a9c2ca168b1f75c2 Mon Sep 17 00:00:00 2001 From: florianow <64468897+florianow@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:28:56 +0100 Subject: [PATCH 01/11] feature: add tag --- src/api/git/GitCliFacade.ts | 7 +++++++ src/model/CollieHub.ts | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/api/git/GitCliFacade.ts b/src/api/git/GitCliFacade.ts index d740c526..c4926d1b 100644 --- a/src/api/git/GitCliFacade.ts +++ b/src/api/git/GitCliFacade.ts @@ -24,6 +24,13 @@ export class GitCliFacade { await this.processRunner.run(["git", "pull"], { cwd: repoDir }); } + async gitTag(repoDir: string) { + await this.processRunner.run(["git", "describe", "--tags", "--abbrev=0" ], { cwd: repoDir }); + } + + async checkout(repoDir: string, gitTag: string) { + await this.processRunner.run(["git", "checkout", gitTag], { cwd: repoDir }); + } /** * Checks if the given dir is a .git repo dir. * This method is using a QuietProcessRunner because we typcially don't want to output repo detection logic via diff --git a/src/model/CollieHub.ts b/src/model/CollieHub.ts index 2a754a2e..105a1779 100644 --- a/src/model/CollieHub.ts +++ b/src/model/CollieHub.ts @@ -10,7 +10,7 @@ export class CollieHub { private readonly hubCacheDirPath = [".collie", "hub"]; // hardcoding this is ok for now - readonly url = "https://github.com/meshcloud/collie-hub.git"; + readonly url = "https://github.com/meshcloud/collie-hub.git/"; public async importKitModule( id: string, @@ -54,7 +54,8 @@ export class CollieHub { const hasAlreadyCloned = await this.git.isRepo(hubCacheGitDir); if (hasAlreadyCloned) { - await this.git.pull(hubCacheDir); + await this.git.gitTag(hubCacheDir); + await this.git.checkout(hubCacheDir, this.git.gitTag((hubCacheGitDir))); } else { await this.git.clone(hubCacheDir, this.url); } From 1c9f6b6714c43f01e35729035eff3a7408c9541a Mon Sep 17 00:00:00 2001 From: Eraldo Grabovaj Date: Fri, 8 Mar 2024 15:58:20 +0100 Subject: [PATCH 02/11] feat: add checkout Tag --- src/api/git/GitCliFacade.ts | 13 +++++-------- src/model/CollieHub.ts | 3 +-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/api/git/GitCliFacade.ts b/src/api/git/GitCliFacade.ts index c4926d1b..ad0ca236 100644 --- a/src/api/git/GitCliFacade.ts +++ b/src/api/git/GitCliFacade.ts @@ -1,10 +1,10 @@ import { IProcessRunner } from "../../process/IProcessRunner.ts"; -import { ProcessResult } from "../../process/ProcessRunnerResult.ts"; +import { ProcessResultWithOutput } from "../../process/ProcessRunnerResult.ts"; import { QuietProcessRunner } from "../../process/QuietProcessRunner.ts"; export class GitCliFacade { constructor( - private readonly processRunner: IProcessRunner, + private readonly processRunner: IProcessRunner, private readonly quietRunner: QuietProcessRunner, ) {} @@ -24,12 +24,9 @@ export class GitCliFacade { await this.processRunner.run(["git", "pull"], { cwd: repoDir }); } - async gitTag(repoDir: string) { - await this.processRunner.run(["git", "describe", "--tags", "--abbrev=0" ], { cwd: repoDir }); - } - - async checkout(repoDir: string, gitTag: string) { - await this.processRunner.run(["git", "checkout", gitTag], { cwd: repoDir }); + async checkout(repoDir: string) { + const gitTagValue = await this.processRunner.run(["git", "describe", "--tags", "--abbrev=0"], { cwd: repoDir }); + await this.processRunner.run(["git", "checkout", gitTagValue.stdout.trim()], { cwd: repoDir }); } /** * Checks if the given dir is a .git repo dir. diff --git a/src/model/CollieHub.ts b/src/model/CollieHub.ts index 105a1779..36c82497 100644 --- a/src/model/CollieHub.ts +++ b/src/model/CollieHub.ts @@ -54,8 +54,7 @@ export class CollieHub { const hasAlreadyCloned = await this.git.isRepo(hubCacheGitDir); if (hasAlreadyCloned) { - await this.git.gitTag(hubCacheDir); - await this.git.checkout(hubCacheDir, this.git.gitTag((hubCacheGitDir))); + await this.git.checkout(hubCacheDir); } else { await this.git.clone(hubCacheDir, this.url); } From 1c81a49be53ca0d5fada0a72b4f8406021e0c01b Mon Sep 17 00:00:00 2001 From: florianow <64468897+florianow@users.noreply.github.com> Date: Fri, 8 Mar 2024 16:15:28 +0100 Subject: [PATCH 03/11] chore: remove trim --- src/api/git/GitCliFacade.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/api/git/GitCliFacade.ts b/src/api/git/GitCliFacade.ts index ad0ca236..07164c44 100644 --- a/src/api/git/GitCliFacade.ts +++ b/src/api/git/GitCliFacade.ts @@ -26,7 +26,8 @@ export class GitCliFacade { async checkout(repoDir: string) { const gitTagValue = await this.processRunner.run(["git", "describe", "--tags", "--abbrev=0"], { cwd: repoDir }); - await this.processRunner.run(["git", "checkout", gitTagValue.stdout.trim()], { cwd: repoDir }); + console.log(gitTagValue) + await this.processRunner.run(["git", "checkout", gitTagValue.stdout], { cwd: repoDir }); } /** * Checks if the given dir is a .git repo dir. From d44be5770f04bb9dc65800a273661c9022f0c435 Mon Sep 17 00:00:00 2001 From: Eraldo Grabovaj Date: Fri, 8 Mar 2024 16:22:44 +0100 Subject: [PATCH 04/11] feat: add checkout Tag --- src/api/git/GitCliFacade.ts | 9 +++++---- src/model/CollieHub.ts | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/api/git/GitCliFacade.ts b/src/api/git/GitCliFacade.ts index 07164c44..1802e08e 100644 --- a/src/api/git/GitCliFacade.ts +++ b/src/api/git/GitCliFacade.ts @@ -24,10 +24,11 @@ export class GitCliFacade { await this.processRunner.run(["git", "pull"], { cwd: repoDir }); } - async checkout(repoDir: string) { - const gitTagValue = await this.processRunner.run(["git", "describe", "--tags", "--abbrev=0"], { cwd: repoDir }); - console.log(gitTagValue) - await this.processRunner.run(["git", "checkout", gitTagValue.stdout], { cwd: repoDir }); + protected async getTag(repoDir: string): Promise { + return await this.processRunner.run(["git", "describe", "--tags", "--abbrev=0"], { cwd: repoDir }); } + + async checkout(repoDir: string, tagValue: string) { + await this.processRunner.run(["git", "checkout", tagValue], { cwd: repoDir }); } /** * Checks if the given dir is a .git repo dir. diff --git a/src/model/CollieHub.ts b/src/model/CollieHub.ts index 36c82497..a0556895 100644 --- a/src/model/CollieHub.ts +++ b/src/model/CollieHub.ts @@ -54,7 +54,8 @@ export class CollieHub { const hasAlreadyCloned = await this.git.isRepo(hubCacheGitDir); if (hasAlreadyCloned) { - await this.git.checkout(hubCacheDir); + const tagValue = this.git.getTag(hubCacheDir).stdout; + await this.git.checkout(hubCacheDir, tagValue); } else { await this.git.clone(hubCacheDir, this.url); } From db10b986e0823a3a96206f9af49bb141be015774 Mon Sep 17 00:00:00 2001 From: florianow <64468897+florianow@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:04:54 +0100 Subject: [PATCH 05/11] chore: adding latest version checkout --- src/api/CliApiFacadeFactory.ts | 2 +- src/api/git/GitCliFacade.ts | 5 +++-- src/model/CollieHub.ts | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/api/CliApiFacadeFactory.ts b/src/api/CliApiFacadeFactory.ts index 4b2b4fd7..93edd792 100644 --- a/src/api/CliApiFacadeFactory.ts +++ b/src/api/CliApiFacadeFactory.ts @@ -118,7 +118,7 @@ export class CliApiFacadeFactory { const detectorRunner = this.buildQuietLoggingProcessRunner(); const detector = new GitCliDetector(detectorRunner); - const processRunner = this.buildTransparentProcessRunner(detector); + const processRunner = this.buildQuietLoggingProcessRunner(); const resultHandler = new ProcessRunnerErrorResultHandler(detector); const quietRunner = new ResultHandlerProcessRunnerDecorator( diff --git a/src/api/git/GitCliFacade.ts b/src/api/git/GitCliFacade.ts index 1802e08e..95688fb4 100644 --- a/src/api/git/GitCliFacade.ts +++ b/src/api/git/GitCliFacade.ts @@ -24,8 +24,9 @@ export class GitCliFacade { await this.processRunner.run(["git", "pull"], { cwd: repoDir }); } - protected async getTag(repoDir: string): Promise { - return await this.processRunner.run(["git", "describe", "--tags", "--abbrev=0"], { cwd: repoDir }); } + getTag(repoDir: string): Promise { + return this.processRunner.run(["git", "describe", "--tags", "--abbrev=0"], { cwd: repoDir }); + } async checkout(repoDir: string, tagValue: string) { await this.processRunner.run(["git", "checkout", tagValue], { cwd: repoDir }); diff --git a/src/model/CollieHub.ts b/src/model/CollieHub.ts index a0556895..9bfa35cb 100644 --- a/src/model/CollieHub.ts +++ b/src/model/CollieHub.ts @@ -54,8 +54,8 @@ export class CollieHub { const hasAlreadyCloned = await this.git.isRepo(hubCacheGitDir); if (hasAlreadyCloned) { - const tagValue = this.git.getTag(hubCacheDir).stdout; - await this.git.checkout(hubCacheDir, tagValue); + const result = await this.git.getTag(hubCacheDir); + await this.git.checkout(hubCacheDir, result.stdout); } else { await this.git.clone(hubCacheDir, this.url); } From 340cd25cf7e27b77f692c73f89b1039eff4839e9 Mon Sep 17 00:00:00 2001 From: florianow <64468897+florianow@users.noreply.github.com> Date: Mon, 11 Mar 2024 17:12:05 +0100 Subject: [PATCH 06/11] chore: adding config for collie-hub version --- src/api/git/GitCliFacade.ts | 5 +++-- src/commands/compliance/import.command.ts | 7 ++++--- src/commands/config/get.command.ts | 4 ++-- src/commands/kit/import.command.ts | 7 ++++--- src/model/CollieConfig.ts | 7 ++++--- src/model/CollieHub.ts | 14 ++++++++------ 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/api/git/GitCliFacade.ts b/src/api/git/GitCliFacade.ts index 95688fb4..315c9a2a 100644 --- a/src/api/git/GitCliFacade.ts +++ b/src/api/git/GitCliFacade.ts @@ -24,8 +24,9 @@ export class GitCliFacade { await this.processRunner.run(["git", "pull"], { cwd: repoDir }); } - getTag(repoDir: string): Promise { - return this.processRunner.run(["git", "describe", "--tags", "--abbrev=0"], { cwd: repoDir }); + async getLatestTag(repoDir: string): Promise { + const result = await this.processRunner.run(["git", "describe", "--tags", "--abbrev=0"], { cwd: repoDir }); + return result.stdout.trim(); } async checkout(repoDir: string, tagValue: string) { diff --git a/src/commands/compliance/import.command.ts b/src/commands/compliance/import.command.ts index d88e6885..e5fdc013 100644 --- a/src/commands/compliance/import.command.ts +++ b/src/commands/compliance/import.command.ts @@ -5,6 +5,7 @@ import { GlobalCommandOptions } from "../GlobalCommandOptions.ts"; import { TopLevelCommand } from "../TopLevelCommand.ts"; import { CliApiFacadeFactory } from "../../api/CliApiFacadeFactory.ts"; import { CollieHub } from "../../model/CollieHub.ts"; +import { CollieConfig } from "../../model/CollieConfig.ts"; interface ImportOptions { clean?: boolean; @@ -31,8 +32,8 @@ export function registerImportCmd(program: TopLevelCommand) { const factory = new CliApiFacadeFactory(logger); const git = factory.buildGit(); - - const hub = new CollieHub(git, collie); + const config = new CollieConfig(collie, logger); + const hub = new CollieHub(git, collie, config); if (opts.clean) { logger.progress("cleaning local cache of collie hub"); @@ -40,7 +41,7 @@ export function registerImportCmd(program: TopLevelCommand) { } logger.progress("updating local cache of collie hub from " + hub.url); - const hubDir = await hub.updateHubClone(); + const hubDir = await hub.cloneLatestHub(); id = id || (await promptForComplianceFrameworkId(hubDir)); diff --git a/src/commands/config/get.command.ts b/src/commands/config/get.command.ts index 760e801e..f56b2d4f 100644 --- a/src/commands/config/get.command.ts +++ b/src/commands/config/get.command.ts @@ -1,6 +1,6 @@ import { GlobalCommandOptions } from "../GlobalCommandOptions.ts"; import { TopLevelCommand } from "../TopLevelCommand.ts"; -import { CollieConfig } from "../../model/CollieConfig.ts"; +import { CollieConfig, CollieConfigProperties } from "../../model/CollieConfig.ts"; import { Logger } from "../../cli/Logger.ts"; import { CollieRepository } from "../../model/CollieRepository.ts"; import { CLI } from "../../info.ts"; @@ -18,7 +18,7 @@ export function registerGetCmd(program: TopLevelCommand) { const repo = await CollieRepository.load(); const logger = new Logger(repo, opts); const config = new CollieConfig(repo, logger); - const value = config.getProperty(property); + const value = config.getProperty(property as keyof CollieConfigProperties); console.log(value); }, ); diff --git a/src/commands/kit/import.command.ts b/src/commands/kit/import.command.ts index 79884b52..c8bb0ad4 100644 --- a/src/commands/kit/import.command.ts +++ b/src/commands/kit/import.command.ts @@ -7,6 +7,7 @@ import { KitModuleRepository } from "../../kit/KitModuleRepository.ts"; import { ModelValidator } from "../../model/schemas/ModelValidator.ts"; import { InteractivePrompts } from "../../cli/InteractivePrompts.ts"; import { CollieHub } from "../../model/CollieHub.ts"; +import { CollieConfig } from "../../model/CollieConfig.ts"; interface ImportOptions { clean?: boolean; @@ -33,8 +34,8 @@ export function registerImportCmd(program: TopLevelCommand) { const factory = new CliApiFacadeFactory(logger); const git = factory.buildGit(); - - const hub = new CollieHub(git, collie); + const config = new CollieConfig(collie, logger); + const hub = new CollieHub(git, collie, config); if (opts.clean) { logger.progress("cleaning local cache of hub modules"); @@ -42,7 +43,7 @@ export function registerImportCmd(program: TopLevelCommand) { } logger.progress("updating local cache of hub modules from " + hub.url); - const hubDir = await hub.updateHubClone(); + const hubDir = await hub.cloneLatestHub(); id = id || (await promptForKitModuleId(logger, hubDir)); diff --git a/src/model/CollieConfig.ts b/src/model/CollieConfig.ts index 3d1b7779..19e28244 100644 --- a/src/model/CollieConfig.ts +++ b/src/model/CollieConfig.ts @@ -5,6 +5,7 @@ import { CollieRepository } from "./CollieRepository.ts"; export interface CollieConfigProperties { foundation?: string; + colliehubVersion?: string; } export class CollieConfig { @@ -19,8 +20,8 @@ export class CollieConfig { private configFilePath: string; private properties: CollieConfigProperties; - getProperty(property: string) { - const value = this.properties["foundation"]; + getProperty(property: keyof CollieConfigProperties) { + const value = this.properties[property]; if (value) { this.logger.verbose( () => `loaded ${property}="${value}" from ${this.configFilePath}`, @@ -30,7 +31,7 @@ export class CollieConfig { } async setProperty( - property: "foundation", + property: keyof CollieConfigProperties, value: string, ) { this.properties[property] = value; diff --git a/src/model/CollieHub.ts b/src/model/CollieHub.ts index 9bfa35cb..739e8655 100644 --- a/src/model/CollieHub.ts +++ b/src/model/CollieHub.ts @@ -1,11 +1,13 @@ import * as fs from "std/fs"; import { GitCliFacade } from "/api/git/GitCliFacade.ts"; import { CollieRepository } from "/model/CollieRepository.ts"; +import { CollieConfig } from "./CollieConfig.ts"; export class CollieHub { constructor( private readonly git: GitCliFacade, private readonly repo: CollieRepository, + private readonly config: CollieConfig ) {} private readonly hubCacheDirPath = [".collie", "hub"]; @@ -40,7 +42,7 @@ export class CollieHub { await fs.copy(srcDir, frameworkDestDir, { overwrite: overwrite }); } - async updateHubClone() { + async cloneLatestHub() { const hubCacheDir = this.repo.resolvePath(...this.hubCacheDirPath); // we do keep a git clone of the repo locally because copying on the local FS is much faster than downloading and @@ -53,12 +55,12 @@ export class CollieHub { ); const hasAlreadyCloned = await this.git.isRepo(hubCacheGitDir); - if (hasAlreadyCloned) { - const result = await this.git.getTag(hubCacheDir); - await this.git.checkout(hubCacheDir, result.stdout); - } else { + if (! hasAlreadyCloned) { await this.git.clone(hubCacheDir, this.url); - } + const latestTag = await this.git.getLatestTag(hubCacheDir); + await this.git.checkout(hubCacheDir, latestTag); + this.config.setProperty("colliehubVersion", latestTag); + } return hubCacheDir; } From 3e19a4e829c230df4efa9ab34c4a87c97f4f0456 Mon Sep 17 00:00:00 2001 From: florianow <64468897+florianow@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:47:50 +0100 Subject: [PATCH 07/11] chore: adding error habdling if tag not exist --- src/api/git/GitCliFacade.ts | 15 +++++++++++---- src/commands/compliance/import.command.ts | 2 +- src/commands/config/get.command.ts | 9 +++++++-- src/commands/kit/import.command.ts | 2 +- src/model/CollieHub.ts | 23 +++++++++++++++++++---- 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/api/git/GitCliFacade.ts b/src/api/git/GitCliFacade.ts index 315c9a2a..361f238e 100644 --- a/src/api/git/GitCliFacade.ts +++ b/src/api/git/GitCliFacade.ts @@ -24,13 +24,20 @@ export class GitCliFacade { await this.processRunner.run(["git", "pull"], { cwd: repoDir }); } - async getLatestTag(repoDir: string): Promise { - const result = await this.processRunner.run(["git", "describe", "--tags", "--abbrev=0"], { cwd: repoDir }); - return result.stdout.trim(); + async getLatestTag(repoDir: string): Promise { + const result = await this.processRunner.run([ + "git", + "describe", + "--tags", + "--abbrev=0", + ], { cwd: repoDir }); + return result.stdout.trim(); } async checkout(repoDir: string, tagValue: string) { - await this.processRunner.run(["git", "checkout", tagValue], { cwd: repoDir }); + await this.processRunner.run(["git", "checkout", tagValue], { + cwd: repoDir, + }); } /** * Checks if the given dir is a .git repo dir. diff --git a/src/commands/compliance/import.command.ts b/src/commands/compliance/import.command.ts index e5fdc013..52e23d25 100644 --- a/src/commands/compliance/import.command.ts +++ b/src/commands/compliance/import.command.ts @@ -33,7 +33,7 @@ export function registerImportCmd(program: TopLevelCommand) { const factory = new CliApiFacadeFactory(logger); const git = factory.buildGit(); const config = new CollieConfig(collie, logger); - const hub = new CollieHub(git, collie, config); + const hub = new CollieHub(git, collie, logger, config); if (opts.clean) { logger.progress("cleaning local cache of collie hub"); diff --git a/src/commands/config/get.command.ts b/src/commands/config/get.command.ts index f56b2d4f..96956d15 100644 --- a/src/commands/config/get.command.ts +++ b/src/commands/config/get.command.ts @@ -1,6 +1,9 @@ import { GlobalCommandOptions } from "../GlobalCommandOptions.ts"; import { TopLevelCommand } from "../TopLevelCommand.ts"; -import { CollieConfig, CollieConfigProperties } from "../../model/CollieConfig.ts"; +import { + CollieConfig, + CollieConfigProperties, +} from "../../model/CollieConfig.ts"; import { Logger } from "../../cli/Logger.ts"; import { CollieRepository } from "../../model/CollieRepository.ts"; import { CLI } from "../../info.ts"; @@ -18,7 +21,9 @@ export function registerGetCmd(program: TopLevelCommand) { const repo = await CollieRepository.load(); const logger = new Logger(repo, opts); const config = new CollieConfig(repo, logger); - const value = config.getProperty(property as keyof CollieConfigProperties); + const value = config.getProperty( + property as keyof CollieConfigProperties, + ); console.log(value); }, ); diff --git a/src/commands/kit/import.command.ts b/src/commands/kit/import.command.ts index c8bb0ad4..70e93ec6 100644 --- a/src/commands/kit/import.command.ts +++ b/src/commands/kit/import.command.ts @@ -35,7 +35,7 @@ export function registerImportCmd(program: TopLevelCommand) { const factory = new CliApiFacadeFactory(logger); const git = factory.buildGit(); const config = new CollieConfig(collie, logger); - const hub = new CollieHub(git, collie, config); + const hub = new CollieHub(git, collie, logger, config); if (opts.clean) { logger.progress("cleaning local cache of hub modules"); diff --git a/src/model/CollieHub.ts b/src/model/CollieHub.ts index 739e8655..9166747b 100644 --- a/src/model/CollieHub.ts +++ b/src/model/CollieHub.ts @@ -2,12 +2,14 @@ import * as fs from "std/fs"; import { GitCliFacade } from "/api/git/GitCliFacade.ts"; import { CollieRepository } from "/model/CollieRepository.ts"; import { CollieConfig } from "./CollieConfig.ts"; +import { Logger } from "../cli/Logger.ts"; export class CollieHub { constructor( private readonly git: GitCliFacade, private readonly repo: CollieRepository, - private readonly config: CollieConfig + private readonly logger: Logger, + private readonly config: CollieConfig, ) {} private readonly hubCacheDirPath = [".collie", "hub"]; @@ -54,13 +56,26 @@ export class CollieHub { ".git", ); const hasAlreadyCloned = await this.git.isRepo(hubCacheGitDir); + const collieHubVersion = this.config.getProperty("colliehubVersion"); - if (! hasAlreadyCloned) { + if (!hasAlreadyCloned && !collieHubVersion) { await this.git.clone(hubCacheDir, this.url); - const latestTag = await this.git.getLatestTag(hubCacheDir); + const latestTag = await this.git.getLatestTag(hubCacheDir); await this.git.checkout(hubCacheDir, latestTag); this.config.setProperty("colliehubVersion", latestTag); - } + } else if (collieHubVersion !== undefined) { + try { + await this.git.clone(hubCacheDir, this.url); + const latestTag = await this.git.getLatestTag(hubCacheDir); + if (latestTag !== collieHubVersion) { + throw new Error(`version tag ${collieHubVersion} not exist`); + } + } catch (error) { + this.logger.error(`${error}`); + Deno.exit(1); + } + await this.git.checkout(hubCacheDir, collieHubVersion); + } return hubCacheDir; } From 700299b2efe482a238b5454d32213e1eb37cc99f Mon Sep 17 00:00:00 2001 From: florianow <64468897+florianow@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:58:10 +0100 Subject: [PATCH 08/11] chore: remove collie.json from generated gitignore --- src/commands/init.command.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/commands/init.command.ts b/src/commands/init.command.ts index b1fb0e8f..d0fcf8d8 100644 --- a/src/commands/init.command.ts +++ b/src/commands/init.command.ts @@ -137,8 +137,7 @@ const gitignore = `# terraform/terragrunt caches .docs # collie caches -.collie -**.collie.json +.collie/hub **.meta.json `; From abb23405ecba8af82de0a1e613bb48e5d1262c8e Mon Sep 17 00:00:00 2001 From: florianow <64468897+florianow@users.noreply.github.com> Date: Tue, 12 Mar 2024 16:38:45 +0100 Subject: [PATCH 09/11] chore: spliting if condition --- src/model/CollieHub.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/model/CollieHub.ts b/src/model/CollieHub.ts index 9166747b..1f6d6e5a 100644 --- a/src/model/CollieHub.ts +++ b/src/model/CollieHub.ts @@ -58,14 +58,15 @@ export class CollieHub { const hasAlreadyCloned = await this.git.isRepo(hubCacheGitDir); const collieHubVersion = this.config.getProperty("colliehubVersion"); - if (!hasAlreadyCloned && !collieHubVersion) { + if (!hasAlreadyCloned) { await this.git.clone(hubCacheDir, this.url); + } + if (!collieHubVersion) { const latestTag = await this.git.getLatestTag(hubCacheDir); await this.git.checkout(hubCacheDir, latestTag); this.config.setProperty("colliehubVersion", latestTag); } else if (collieHubVersion !== undefined) { try { - await this.git.clone(hubCacheDir, this.url); const latestTag = await this.git.getLatestTag(hubCacheDir); if (latestTag !== collieHubVersion) { throw new Error(`version tag ${collieHubVersion} not exist`); From 87e916ac76a839ba9a421e7ec171fe89b4cfc68c Mon Sep 17 00:00:00 2001 From: florianow <64468897+florianow@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:40:09 +0100 Subject: [PATCH 10/11] chore: testing multiple versions --- src/api/git/GitCliFacade.ts | 12 ++++++++---- src/model/CollieHub.ts | 32 +++++++++++++++++--------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/api/git/GitCliFacade.ts b/src/api/git/GitCliFacade.ts index 361f238e..3dbee31e 100644 --- a/src/api/git/GitCliFacade.ts +++ b/src/api/git/GitCliFacade.ts @@ -20,10 +20,6 @@ export class GitCliFacade { await this.processRunner.run(["git", "clone", repoUrl, destDir]); } - async pull(repoDir: string) { - await this.processRunner.run(["git", "pull"], { cwd: repoDir }); - } - async getLatestTag(repoDir: string): Promise { const result = await this.processRunner.run([ "git", @@ -34,6 +30,14 @@ export class GitCliFacade { return result.stdout.trim(); } + async getTags(repoDir: string): Promise { + const result = await this.processRunner.run([ + "git", + "tag", + ], { cwd: repoDir }); + return result.stdout.trim(); + } + async checkout(repoDir: string, tagValue: string) { await this.processRunner.run(["git", "checkout", tagValue], { cwd: repoDir, diff --git a/src/model/CollieHub.ts b/src/model/CollieHub.ts index 1f6d6e5a..7968bf35 100644 --- a/src/model/CollieHub.ts +++ b/src/model/CollieHub.ts @@ -56,27 +56,29 @@ export class CollieHub { ".git", ); const hasAlreadyCloned = await this.git.isRepo(hubCacheGitDir); - const collieHubVersion = this.config.getProperty("colliehubVersion"); + let collieHubVersion = this.config.getProperty("colliehubVersion"); if (!hasAlreadyCloned) { await this.git.clone(hubCacheDir, this.url); - } + } if (!collieHubVersion) { - const latestTag = await this.git.getLatestTag(hubCacheDir); - await this.git.checkout(hubCacheDir, latestTag); - this.config.setProperty("colliehubVersion", latestTag); - } else if (collieHubVersion !== undefined) { - try { - const latestTag = await this.git.getLatestTag(hubCacheDir); - if (latestTag !== collieHubVersion) { - throw new Error(`version tag ${collieHubVersion} not exist`); - } - } catch (error) { - this.logger.error(`${error}`); - Deno.exit(1); - } + collieHubVersion = await this.git.getLatestTag(hubCacheDir); await this.git.checkout(hubCacheDir, collieHubVersion); + this.config.setProperty("colliehubVersion", collieHubVersion!); + } + try { + const allTags = await this.git.getTags(hubCacheGitDir); + if (!allTags.includes(collieHubVersion)) { + throw new Error( + `version tag does not exist, possible are: ${allTags.split("\n")}`, + ); + } + } catch (error) { + this.logger.error(`${error}`); + Deno.exit(1); } + //collie-hub version is set by the if block + await this.git.checkout(hubCacheDir, collieHubVersion!); return hubCacheDir; } From 0179dbfdff5ed8a04a339d170a8672ced2913a2a Mon Sep 17 00:00:00 2001 From: florianow <64468897+florianow@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:51:27 +0100 Subject: [PATCH 11/11] chore: rename cloneLatestHub to cloneHub --- src/commands/compliance/import.command.ts | 2 +- src/commands/kit/import.command.ts | 2 +- src/model/CollieHub.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/compliance/import.command.ts b/src/commands/compliance/import.command.ts index 52e23d25..175fa1f6 100644 --- a/src/commands/compliance/import.command.ts +++ b/src/commands/compliance/import.command.ts @@ -41,7 +41,7 @@ export function registerImportCmd(program: TopLevelCommand) { } logger.progress("updating local cache of collie hub from " + hub.url); - const hubDir = await hub.cloneLatestHub(); + const hubDir = await hub.cloneHub(); id = id || (await promptForComplianceFrameworkId(hubDir)); diff --git a/src/commands/kit/import.command.ts b/src/commands/kit/import.command.ts index 70e93ec6..bd64f37e 100644 --- a/src/commands/kit/import.command.ts +++ b/src/commands/kit/import.command.ts @@ -43,7 +43,7 @@ export function registerImportCmd(program: TopLevelCommand) { } logger.progress("updating local cache of hub modules from " + hub.url); - const hubDir = await hub.cloneLatestHub(); + const hubDir = await hub.cloneHub(); id = id || (await promptForKitModuleId(logger, hubDir)); diff --git a/src/model/CollieHub.ts b/src/model/CollieHub.ts index 7968bf35..57e52d3c 100644 --- a/src/model/CollieHub.ts +++ b/src/model/CollieHub.ts @@ -44,7 +44,7 @@ export class CollieHub { await fs.copy(srcDir, frameworkDestDir, { overwrite: overwrite }); } - async cloneLatestHub() { + async cloneHub() { const hubCacheDir = this.repo.resolvePath(...this.hubCacheDirPath); // we do keep a git clone of the repo locally because copying on the local FS is much faster than downloading and