Skip to content

Commit

Permalink
Merge pull request #21 from letsila/trazafinirina/flu-33-use-deno-sem…
Browse files Browse the repository at this point in the history
…ver-in-checkupdate-for-version-comparison

use semver standard library for version check
  • Loading branch information
tsirysndr authored Jan 21, 2024
2 parents fd9b637 + da8996a commit ba17640
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 64 deletions.
45 changes: 45 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as semver from "https://deno.land/[email protected]/semver/mod.ts";
export { semver };
export {
magenta,
bold,
brightGreen,
brightMagenta,
cyan,
bold,
gray,
green,
magenta,
red,
brightGreen,
gray,
yellow,
} from "https://deno.land/[email protected]/fmt/colors.ts";
export { z } from "https://deno.land/x/[email protected]/mod.ts";
Expand All @@ -15,22 +17,22 @@ export { existsSync } from "https://deno.land/[email protected]/fs/exists.ts";
export { load } from "https://deno.land/[email protected]/dotenv/mod.ts";
export { Secret } from "https://deno.land/x/[email protected]/prompt/secret.ts";
export {
prompt,
Input,
Confirm,
Input,
prompt,
} from "https://deno.land/x/[email protected]/prompt/mod.ts";
import dir from "https://deno.land/x/[email protected]/mod.ts";
export { dir };
export { walkSync, walk } from "https://deno.land/[email protected]/fs/walk.ts";
export { walk, walkSync } from "https://deno.land/[email protected]/fs/walk.ts";
export type { WalkEntry } from "https://deno.land/[email protected]/fs/walk.ts";
export {
BlobReader,
BlobWriter,
TextReader,
TextWriter,
Uint8ArrayReader,
ZipReader,
ZipWriter,
Uint8ArrayReader,
} from "https://deno.land/x/[email protected]/index.js";
import introspect from "https://cdn.jsdelivr.net/gh/fluentci-io/daggerverse@main/deno-sdk/sdk/src/mod/introspect.ts";
export { introspect };
Expand Down
43 changes: 19 additions & 24 deletions src/cmd/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { VERSION } from "../consts.ts";
import { yellow, green } from "../../deps.ts";
import { green, semver, yellow } from "../../deps.ts";

/**
* Upgrades FluentCI by installing the latest version from the Deno registry.
Expand Down Expand Up @@ -28,36 +28,31 @@ async function upgrade() {
export default upgrade;

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

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

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

const latestVersion = semver.parse(releaseInfo.tag_name);
const currentVersion = semver.parse(VERSION);

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}
`,
);
}
} catch (e) {
console.log(`
${yellow('WARNING: ')} checking for udpate failed ${e}
`)
}
}

export const versionGreaterThan = (v1: string, v2: string): boolean => {
const numbers1 = v1.replace('v', '').split('.').map(Number)
const numbers2 = v2.replace('v', '').split('.').map(Number)

for (let i = 0; i < 3; i++) {
if (numbers1[i] > numbers2[i]) {
return true;
}
${yellow("WARNING: ")} checking for udpate failed ${e}
`);
}

return false;
}
32 changes: 0 additions & 32 deletions tests/upgrade.test.ts

This file was deleted.

0 comments on commit ba17640

Please sign in to comment.