Skip to content

Commit

Permalink
version-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Jul 3, 2024
1 parent 73d896b commit fb8adc3
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ jobs:
CI: true
NGS_CI_USER: ${{ secrets.NGS_CI_USER }}
run: |
deno task check-versions --module ${{ matrix.module }}
deno task check-dependencies --module ${{ matrix.module }}
deno task test-${{ matrix.module }}
# - name: Build nats.js
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ debug/
# deno project file
settings.json

deno.lock

# nyc test coverage
.nyc_output
coverage/
Expand Down
105 changes: 105 additions & 0 deletions bin/check-bundle-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env -S deno run -A
/*
* Copyright 2021-2024 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { parseArgs } from "jsr:@std/cli/parse-args";
import { join } from "jsr:@std/path";

async function load(fp: string): Promise<string> {
const src = await Deno.readTextFile(fp);
const { version } = JSON.parse(src);
return version;
}

const argv = parseArgs(
Deno.args,
{
alias: {
"m": ["module"],
"t": ["tag"],
},
string: ["module", "tag"],
},
);

const module = argv.module || null;

if (module === null) {
console.error(
`[ERROR] --module is required`,
);
Deno.exit(1);
}

let version: string;

if (module.startsWith("transport-")) {
let packageVersion: string = "";
const versionFile = await load(join(module, "src", "version.json"));
switch (module) {
case "transport-node":
packageVersion = await load(join(module, "package.json"));
break;
default:
packageVersion = await load(join(module, "deno.json"));
break;
}
if (!packageVersion) {
console.error(
`[ERROR] package version for module ${module} is missing a version`,
);
Deno.exit(1);
}
if (!versionFile) {
console.error(
`[ERROR] src/version.json file for module ${module} is missing a version`,
);
Deno.exit(1);
}
if (packageVersion !== versionFile) {
console.error(
`[ERROR] expected versions to match - package: ${packageVersion} src/version.json: ${versionFile}`,
);
Deno.exit(1);
}
version = versionFile;
} else {
const deno = await load(join(module, "deno.json"));
const node = await load(join(module, "package.json"));

if (deno !== node) {
console.error(
`[ERROR] expected versions to match - deno.json: ${deno} package.json: ${node}`,
);
Deno.exit(1);
}
version = deno;
}

if (argv.tag) {
let tag = argv.tag;
const prefix = `${argv.module}/`;
if (tag.startsWith(prefix)) {
tag = tag.substring(prefix.length);
}
if (tag !== version) {
console.error(
`[ERROR] expected tag version to match - bundle: ${version} tag: ${argv.tag}}`,
);
Deno.exit(1);
}
}

Deno.exit(0);
116 changes: 116 additions & 0 deletions bin/check-dep-versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env -S deno run -A
/*
* Copyright 2021-2024 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { parseArgs } from "jsr:@std/cli/parse-args";
import { join } from "jsr:@std/path";

async function load<T>(fp: string): Promise<T> {
const src = await Deno.readTextFile(fp);
return JSON.parse(src);
}

type denoImports = {
imports: Record<string, string>;
};

type nodeDependencies = {
dependencies: Record<string, string>;
};

const argv = parseArgs(
Deno.args,
{
alias: {
"m": ["module"],
"v": ["verbose"],
"f": ["fix"],
},
string: ["module"],
boolean: ["v", "f"],
},
);

const module = argv.module || null;

if (module === null) {
console.error(
`[ERROR] --module is required`,
);
Deno.exit(1);
}

const di = await load<denoImports>(join(module, "deno.json"));
const nd = await load<nodeDependencies>(join(module, "package.json"));

// drive the dependencies from the deno.json, as npm may contain additional ones
let failed = false;
let fixed = false;

for (const lib in di.imports) {
let deno = di.imports[lib];
const prefix = `jsr:${lib}@`;
if (deno.startsWith(prefix)) {
deno = deno.substring(prefix.length);
}

if (argv.f) {
if (nd.dependencies[lib] !== deno) {
console.log(
`changed in package.json ${lib} from ${
nd.dependencies[lib]
} to ${deno}`,
);
nd.dependencies[lib] = deno;
fixed = true;
}
continue;
}

if (argv.v === true) {
const node = nd.dependencies[lib];
console.log({ lib, deno, node });
}
if (!nd.dependencies[lib]) {
failed = true;
console.log(
`[ERROR] module ${module} package.json dependencies is missing: ${lib}`,
);
continue;
}
if (deno !== nd.dependencies[lib]) {
failed = true;
console.log(
`[ERROR] module ${module} package.json dependencies ${lib}: ${
nd.dependencies[lib]
} - but should be ${deno}`,
);
}
}

if (argv.f && fixed) {
await Deno.writeTextFile(
join(module, "package.json"),
JSON.stringify(nd, undefined, " "),
);
console.log(`[OK] module ${module} updated package.json`);
Deno.exit(0);
}

if (failed) {
Deno.exit(1);
}
console.log(`[OK] module ${module}`);
Deno.exit(0);
2 changes: 1 addition & 1 deletion core/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"tasks": {
"clean": "rm -rf ./lib ./cjs ./esm",
"test": "deno test -A --parallel --reload --quiet tests/ --import-map=./import_map.json"
"test": "deno test -A --parallel --reload --quiet tests/ --import-map=./import_map.json",
},
"imports": {
"@nats-io/nkeys": "jsr:@nats-io/[email protected]",
Expand Down
25 changes: 7 additions & 18 deletions core/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
{
"name": "@nats-io/nats-core",
"version": "3.0.0-16",
"files": [
"lib/",
"esm/"
],
"version": "3.0.0-17",
"files": ["lib/", "esm/"],
"types": "./lib/mod.d.js",
"exports": {
".": "./lib/mod.js",
"./internal": "./lib/internal_mod.js"
},
"exports": { ".": "./lib/mod.js", "./internal": "./lib/internal_mod.js" },
"license": "Apache-2.0",
"private": false,
"scripts": {
Expand All @@ -21,18 +15,13 @@
"prepack": "npm run build"
},
"keywords": [],
"author": {
"name": "The NATS Authors"
},
"author": { "name": "The NATS Authors" },
"description": "nats-core library - this library implements all the base functionality for NATS javascript clients",
"dependencies": {
"@nats-io/nkeys": "^1.2.0-4",
"@nats-io/nuid": "^2.0.1-2",
"@nats-io/nkeys": "1.2.0-4",
"@nats-io/nuid": "2.0.1-2",
"shx": "^0.3.4",
"typescript": "^5.4.5"
},
"devDependencies": {
"@types/node": "^20.11.30",
"typedoc": "^0.25.12"
}
"devDependencies": { "@types/node": "^20.11.30", "typedoc": "^0.25.12" }
}
11 changes: 9 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
},
"tasks": {
"clean": "rm -rf ./coverage/",
"test": "deno task clean && deno task test-core && deno task test-jetstream && deno task test-kv && deno task test-obj && deno task test-services && deno task test-unsafe",
"test": "deno task clean && deno task lint && deno task test-all",
"test-all": "deno task test-core && deno task test-jetstream && deno task test-kv && deno task test-obj && deno task test-services && deno task test-unsafe",
"test-unsafe": "deno test -A --parallel --reload --quiet --unsafely-ignore-certificate-errors --coverage=coverage core/unsafe_tests",
"test-core": "deno test -A --parallel --reload --quiet --coverage=coverage core/tests",
"test-jetstream": "deno test -A --parallel --reload --quiet --coverage=coverage jetstream/tests",
Expand All @@ -21,7 +22,13 @@
"lint-kv": "cd kv && deno lint",
"lint-obj": "cd obj && deno lint",
"lint-services": "cd services && deno lint",
"lint-test_helpers": "cd test_helpers && deno lint"
"lint-test_helpers": "cd test_helpers && deno lint",
"check-versions": "bin/check-bundle-version.ts",
"check-versions-all": "deno task check-versions-core && deno task check-versions-jetstream && deno task check-versions-kv",
"check-versions-core": "bin/check-bundle-version.ts --module core",
"check-versions-jetstream": "bin/check-bundle-version.ts --module jetstream",
"check-versions-kv": "bin/check-bundle-version.ts --module kv",
"check-dependencies": "bin/check-dep-versions.ts"
},
"fmt": {
"include": ["src/", "doc/", "bin/", "core/", "debug/", "jetstream/", "kv/", "obj/", "services/", "*.md"]
Expand Down
1 change: 1 addition & 0 deletions jetstream/import_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"imports": {
"@nats-io/nkeys": "jsr:@nats-io/[email protected]",
"@nats-io/nuid": "jsr:@nats-io/[email protected]",
"@nats-io/nats-core": "jsr:@nats-io/[email protected]",
"@nats-io/jetstream/internal": "./src/internal_mod.ts",
"test_helpers": "../test_helpers/mod.ts",
"@std/io": "jsr:@std/[email protected]"
Expand Down
33 changes: 33 additions & 0 deletions kv/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@nats-io/kv",
"version": "3.0.0-2",
"files": [
"lib/"
],
"types": "./lib/mod.d.js",
"exports": {
".": "./lib/mod.js",
"./internal": "./lib/internal_mod.js"
},
"license": "Apache-2.0",
"private": false,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "shx rm -Rf ./lib ./cjs ./esm && shx mkdir esm",
"pre-process": "npm run clean && deno run -A ../bin/cjs-fix-imports.ts -o ./cjs ./src",
"build-cjs": "npm run pre-process && tsc",
"build": "npm run build-cjs",
"prepack": "npm run build"
},
"keywords": [],
"author": {
"name": "The NATS Authors"
},
"description": "nats-core library - this library implements all the base functionality for NATS javascript clients",
"dependencies": {
"@nats-io/nats-core": "3.0.0-17",
"shx": "^0.3.4",
"typescript": "^5.4.5",
"@nats-io/jetstream": "3.0.0-3"
}
}
3 changes: 2 additions & 1 deletion transport-deno/src/deno_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import type {
} from "@nats-io/nats-core/internal";

import { writeAll } from "@std/io";
import data from "./version.json" with {type: "json"}

const VERSION = "1.25.0";
const VERSION = data.version;
const LANG = "nats.deno";

const ReadBufferSize = 1024 * 256;
Expand Down
3 changes: 3 additions & 0 deletions transport-deno/src/version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "3.0.0-5"
}

0 comments on commit fb8adc3

Please sign in to comment.