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

Force the cleanup script to use the tool cache #124

Merged
merged 2 commits into from
Jan 18, 2024
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
4 changes: 3 additions & 1 deletion lib/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ function cleanup() {
return __awaiter(this, void 0, void 0, function* () {
try {
core.startGroup('Cleanup JFrog CLI servers configuration');
yield utils_1.Utils.getAndAddCliToPath({});
if (!utils_1.Utils.addCachedCliToPath()) {
return;
}
yield utils_1.Utils.removeJFrogServers();
}
catch (error) {
Expand Down
20 changes: 18 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.Utils = void 0;
const core = __importStar(require("@actions/core"));
const exec_1 = require("@actions/exec");
const http_client_1 = require("@actions/http-client");
const toolCache = __importStar(require("@actions/tool-cache"));
const fs_1 = require("fs");
const os_1 = require("os");
const path_1 = require("path");
const semver_1 = require("semver");
const http_client_1 = require("@actions/http-client");
class Utils {
/**
* Retrieves server credentials for accessing JFrog's server
Expand Down Expand Up @@ -151,7 +151,7 @@ class Utils {
let version = core.getInput(Utils.CLI_VERSION_ARG);
let cliRemote = core.getInput(Utils.CLI_REMOTE_ARG);
let major = version.split('.')[0];
if (version === this.LATEST_CLI_VERSION) {
if (version === Utils.LATEST_CLI_VERSION) {
version = Utils.LATEST_RELEASE_VERSION;
major = '2';
}
Expand All @@ -174,6 +174,22 @@ class Utils {
yield this.cacheAndAddPath(downloadDir, version, jfrogFileName);
});
}
/**
* Fetch the JFrog CLI path from the tool cache and append it to the PATH environment variable. Employ this approach during the cleanup phase.
*/
static addCachedCliToPath() {
let version = core.getInput(Utils.CLI_VERSION_ARG);
if (version === Utils.LATEST_CLI_VERSION) {
version = Utils.LATEST_RELEASE_VERSION;
}
let jfrogCliPath = toolCache.find(Utils.getJfExecutableName(), version);
if (!jfrogCliPath) {
core.warning(`Could not find JFrog CLI version '${version}' in tool cache`);
return false;
}
core.addPath(jfrogCliPath);
return true;
}
/**
* Try to load the JFrog CLI executables from cache.
*
Expand Down
6 changes: 4 additions & 2 deletions src/cleanup.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import * as core from '@actions/core';
import { JfrogCredentials, Utils } from './utils';
import { Utils } from './utils';

async function cleanup() {
try {
core.startGroup('Cleanup JFrog CLI servers configuration');
await Utils.getAndAddCliToPath({} as JfrogCredentials);
if (!Utils.addCachedCliToPath()) {
return;
}
await Utils.removeJFrogServers();
} catch (error) {
core.setFailed((<any>error).message);
Expand Down
23 changes: 20 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as core from '@actions/core';
import { exec } from '@actions/exec';
import { HttpClient, HttpClientResponse } from '@actions/http-client';
import * as toolCache from '@actions/tool-cache';
import { chmodSync } from 'fs';
import { OutgoingHttpHeaders } from 'http';
import { arch, platform } from 'os';
import { join } from 'path';
import { lt } from 'semver';
import { HttpClient, HttpClientResponse } from '@actions/http-client';
import { OutgoingHttpHeaders } from 'http';

export class Utils {
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -154,7 +154,7 @@ export class Utils {
let version: string = core.getInput(Utils.CLI_VERSION_ARG);
let cliRemote: string = core.getInput(Utils.CLI_REMOTE_ARG);
let major: string = version.split('.')[0];
if (version === this.LATEST_CLI_VERSION) {
if (version === Utils.LATEST_CLI_VERSION) {
version = Utils.LATEST_RELEASE_VERSION;
major = '2';
} else if (lt(version, this.MIN_CLI_VERSION)) {
Expand All @@ -179,6 +179,23 @@ export class Utils {
await this.cacheAndAddPath(downloadDir, version, jfrogFileName);
}

/**
* Fetch the JFrog CLI path from the tool cache and append it to the PATH environment variable. Employ this approach during the cleanup phase.
*/
public static addCachedCliToPath(): boolean {
let version: string = core.getInput(Utils.CLI_VERSION_ARG);
if (version === Utils.LATEST_CLI_VERSION) {
version = Utils.LATEST_RELEASE_VERSION;
}
let jfrogCliPath: string = toolCache.find(Utils.getJfExecutableName(), version);
if (!jfrogCliPath) {
core.warning(`Could not find JFrog CLI version '${version}' in tool cache`);
return false;
}
core.addPath(jfrogCliPath);
return true;
}

/**
* Try to load the JFrog CLI executables from cache.
*
Expand Down
Loading