Skip to content

Commit

Permalink
Merge pull request #22 from fluentci-io/feat/skip-upgrade
Browse files Browse the repository at this point in the history
skip `upgrade` if already on the latest version
  • Loading branch information
tsirysndr authored Jan 21, 2024
2 parents ba17640 + b394208 commit 8d7209b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fluentci # Run the pipeline
fluentci --help

Usage: fluentci [pipeline] [jobs...]
Version: 0.10.8
Version: 0.10.9

Description:

Expand Down
32 changes: 23 additions & 9 deletions src/cmd/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { VERSION } from "../consts.ts";
import { green, semver, yellow } from "../../deps.ts";
import { gray, green, semver, yellow } from "../../deps.ts";

/**
* Upgrades FluentCI by installing the latest version from the Deno registry.
* @returns {Promise<void>}
*/
async function upgrade() {
const newVersionAvailable = await checkForUpdate({ checkUpdate: true });
if (!newVersionAvailable) {
console.log(
`${green(
"Congrats!"
)} You are already on the latest version of fluentci ${gray(
"(which is " + VERSION + ")"
)}`
);
return;
}

const command = new Deno.Command("deno", {
args: [
"install",
Expand All @@ -25,17 +37,15 @@ async function upgrade() {
console.log(new TextDecoder().decode(stderr));
}

export default upgrade;

export async function checkForUpdate(options: { checkUpdate: boolean }) {
const { checkUpdate } = options;
if (!checkUpdate) {
return;
return false;
}

try {
const result = await fetch(
"https://api.github.com/repos/fluentci-io/fluentci/releases/latest",
"https://api.github.com/repos/fluentci-io/fluentci/releases/latest"
);
const releaseInfo = await result.json();

Expand All @@ -44,15 +54,19 @@ export async function checkForUpdate(options: { checkUpdate: boolean }) {

if (semver.gt(latestVersion, currentVersion)) {
console.log(
`${
green("A new release of fluentci is available:")
} ${VERSION}${releaseInfo.tag_name} \nTo upgrade: run fluentci upgrade\n${releaseInfo.url}
`,
`${green("A new release of fluentci is available:")} ${VERSION}${
releaseInfo.tag_name
} \nTo upgrade: run fluentci upgrade\n${releaseInfo.url}
`
);
return true;
}
} catch (e) {
console.log(`
${yellow("WARNING: ")} checking for udpate failed ${e}
`);
}
return false;
}

export default upgrade;
2 changes: 1 addition & 1 deletion src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dir } from "../deps.ts";

export const VERSION = "0.10.8";
export const VERSION = "0.10.9";

export const BASE_URL = "https://api.fluentci.io/v1";

Expand Down

0 comments on commit 8d7209b

Please sign in to comment.