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

MM-4259 feat: install: export installed package to file, local-install: accept list of package to skip #95

Merged
merged 8 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 additions & 0 deletions bin/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ yargs
"Print JSON-formatted dependency graph of packages to be installed without actually installing them",
default: false,
})
.option("export-package-names", {
louisnow marked this conversation as resolved.
Show resolved Hide resolved
type: "string",
description: "export installed packages to a file",
default: "",
})
.option("azure", {
alias: "az",
type: "boolean",
Expand All @@ -71,6 +76,7 @@ yargs
timeZone: argv["tz"],
preview: argv["p"],
azure: argv["az"],
exportPackageNameFilePath: argv["export-package-names"],
};
if (argv.global) {
return installGlobal(argv.package, argv.registry, argv.namespace, argv.cluster, options).then(
Expand Down
26 changes: 23 additions & 3 deletions bin/local-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,28 @@ async function run(
extraArgs,
channel,
snapshotInstall,
skipVersionCheck
skipVersionCheck,
skipPackages
) {
const packagesMap = getAllPackagesMap();
const installedPackages = await getInstalledPackages();

const packagesToInstall = getPackagesToInstall(
const initPackagesToInstall = getPackagesToInstall(
packageName,
packagesMap,
installedPackages,
skipVersionCheck,
snapshotInstall
);
const skipPackagesArray = Array.from(
JSON.parse(skipPackages)
.map((item) => item.split(","))
.flat()
);
const packagesToInstall = Array.from(initPackagesToInstall).filter(
(item) => !skipPackagesArray.includes(item.name)
);
console.log("Packages skipped install: " + skipPackagesArray);
console.log(
"Packages to install: " +
Array.from(packagesToInstall)
Expand Down Expand Up @@ -313,9 +323,19 @@ const channel = process.argv[7];
// It respects bypassSafetyCheck, and added a -snapshot suffix to the version
const snapshotInstallString = process.argv[8];
const skipVersionCheckString = process.argv[9];
const skipPackages = process.argv[10];

const bypassSafetyCheck = bypassSafetyCheckString === "true";
const snapshotInstall = snapshotInstallString === "true";
const skipVersionCheck = skipVersionCheckString === "true";

run(packageName, azureArtifacts, bypassSafetyCheck, extraArgs, channel, snapshotInstall, skipVersionCheck);
run(
packageName,
azureArtifacts,
bypassSafetyCheck,
extraArgs,
channel,
snapshotInstall,
skipVersionCheck,
skipPackages
);
17 changes: 15 additions & 2 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const K8sInstaller = require("./k8s").K8sInstaller;
const S3 = require("./s3").S3;
const listDirs = require("./utils").listDirs;
const deleteDir = require("./utils").deleteDir;
const appendToFileSync = require("./utils").appendToFileSync;
const fs = require("fs");
const { DashboardInstaller } = require("./dashboard");
const { constants } = require("./constants");
Expand Down Expand Up @@ -84,7 +85,7 @@ const packageDetailsFromPath = function (path) {
* @param {string} namespace
* @param {boolean} save
* @param {boolean} cluster
* @param {{force:boolean,cronString:string,timeZone,preview:boolean,azure:boolean}} options
* @param {{force:boolean,cronString:string,timeZone,preview:boolean,azure:boolean,exportPackageNameFilePath:string}} options
* @param {string} dirPath
*/
const install = function (packageName, registry, namespace, save, cluster, options, dirPath = process.cwd()) {
Expand Down Expand Up @@ -163,6 +164,7 @@ const install = function (packageName, registry, namespace, save, cluster, optio
return k8sInstaller
.install(cluster)
.then((_) => {
installed.push(packageDetailsFromPath(innerDir));
return dashboardInstaller.install();
})
.then(() => {
Expand Down Expand Up @@ -197,6 +199,9 @@ const install = function (packageName, registry, namespace, save, cluster, optio

return k8sInstaller
.install(cluster)
.then((_) => {
installed.push(packageDetailsFromPath(dir));
})
.then((_) => {
return dashboardInstaller.install();
})
Expand All @@ -217,7 +222,7 @@ const install = function (packageName, registry, namespace, save, cluster, optio
}

if (options.preview) {
installed.push(packageDetailsFromPath("."));
installed.push(packageDetailsFromPath(dirPath));
return Promise.resolve(); // Skip installation
}

Expand All @@ -233,6 +238,7 @@ const install = function (packageName, registry, namespace, save, cluster, optio
return k8sInstaller
.install(cluster)
.then((_) => {
installed.push(packageDetailsFromPath(dirPath));
return dashboardInstaller.install();
})
.then(() => {
Expand All @@ -248,6 +254,13 @@ const install = function (packageName, registry, namespace, save, cluster, optio
if (options.preview) {
console.log(JSON.stringify(installed, null, 2));
}
if (options.exportPackageNameFilePath !== "") {
var packageSet = new Set();
installed.forEach(function (data) {
packageSet.add(data.name);
});
appendToFileSync(options.exportPackageNameFilePath, Array.from(packageSet).join(","));
}
const parsedPackage = npa(parentPackageName);
return parsedPackage.name;
});
Expand Down
15 changes: 15 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Promise = require("bluebird");
const fs = require("fs").promises;
const path = require("path");
const { rimraf } = require("rimraf");
const fsSync = require("fs");

/**
* Recursively walk through the folder and return all file paths
Expand Down Expand Up @@ -53,6 +54,20 @@ async function deleteDir(dir) {

exports.deleteDir = deleteDir;

/**
* Append content to file
* @param {string} filePath
* @param {string} content
* @returns {Promise<void>}
*/
function appendToFileSync(filePath, content) {
const dirPath = path.dirname(filePath);
fsSync.mkdirSync(dirPath, { recursive: true });
fsSync.appendFileSync(filePath, content);
}

exports.appendToFileSync = appendToFileSync;

/**
* Generate arguments
* @param {[string]} args
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "argopm",
"version": "0.10.19",
"version": "0.10.20",
"description": "Argo package manager",
"main": "./lib/index.js",
"scripts": {
Expand Down
35 changes: 35 additions & 0 deletions tests/base.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const { uninstall } = require("../lib/index");
const { install, installGlobal } = require("../lib/install.js");
const { getPackageName, MOCK_PACKAGE_PATH, REGISTRY } = require("./test-utils");
const { k8s } = require("../lib/k8s.js");
const fs = require("fs");
const os = require("os");
const path = require("path");

describe.skip("simulate package install", () => {
const namespace = "default";
Expand All @@ -25,3 +29,34 @@ describe.skip("simulate package install", () => {
expect(result).toBeTruthy();
});
});

describe("verify export-package-names", () => {
test("verify content", async () => {
const namespace = "default";
const cluster = false;

const currentTime = Date.now();
const tempDir = os.tmpdir();
const filePath = path.join(tempDir, `${currentTime}.txt`);

const result = await install(
".",
REGISTRY,
namespace,
false,
cluster,
{ preview: true, exportPackageNameFilePath: filePath },
MOCK_PACKAGE_PATH
)
.then(() => {
return true;
})
.catch((err) => {
console.error(err);
throw err;
});
expect(result).toBeTruthy();
const data = fs.readFileSync(filePath, "utf8");
expect(data).toEqual("@atlan/mock-package-delete-me");
});
});
Loading