Skip to content
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

use semver standard library for version check #21

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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.