-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/colliehub version tag #281
Changes from 10 commits
ba649ef
1c9f6b6
1c81a49
d44be57
db10b98
340cd25
3e19a4e
700299b
abb2340
87e916a
0179dbf
8e19133
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -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<ProcessResult>, | ||||||||
private readonly processRunner: IProcessRunner<ProcessResultWithOutput>, | ||||||||
private readonly quietRunner: QuietProcessRunner, | ||||||||
) {} | ||||||||
|
||||||||
|
@@ -20,10 +20,29 @@ 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<string> { | ||||||||
const result = await this.processRunner.run([ | ||||||||
"git", | ||||||||
"describe", | ||||||||
"--tags", | ||||||||
"--abbrev=0", | ||||||||
], { cwd: repoDir }); | ||||||||
return result.stdout.trim(); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
s: empty line before return |
||||||||
} | ||||||||
|
||||||||
async getTags(repoDir: string): Promise<string> { | ||||||||
const result = await this.processRunner.run([ | ||||||||
"git", | ||||||||
"tag", | ||||||||
], { cwd: repoDir }); | ||||||||
return result.stdout.trim(); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s: empty line before return. |
||||||||
} | ||||||||
|
||||||||
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. | ||||||||
* This method is using a QuietProcessRunner because we typcially don't want to output repo detection logic via | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
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 logger: Logger, | ||
private readonly config: CollieConfig, | ||
) {} | ||
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, | ||
|
@@ -40,7 +44,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 | ||
|
@@ -52,12 +56,29 @@ export class CollieHub { | |
".git", | ||
); | ||
const hasAlreadyCloned = await this.git.isRepo(hubCacheGitDir); | ||
let collieHubVersion = this.config.getProperty("colliehubVersion"); | ||
|
||
if (hasAlreadyCloned) { | ||
await this.git.pull(hubCacheDir); | ||
} else { | ||
if (!hasAlreadyCloned) { | ||
await this.git.clone(hubCacheDir, this.url); | ||
} | ||
if (!collieHubVersion) { | ||
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. d: this is strange. you throw an error here but directly catch it 3 lines later. In this case, if you dont need to stop something through multiple call-layers I suggest to just directly stop the execution in here by directly calling Deno.exit() instead of throwing an 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; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole runner setup is quite complex. But when looking close we already have a process runner with the required type. I wonder if something like
works too so we need one less runner?