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

Update version to 4.0.0 #131

Merged
merged 1 commit into from
Feb 2, 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
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Update v3 tag
run: git tag -f v3
uses: actions/checkout@v4
- name: Update v4 tag
run: git tag -f v4
- name: Push changes
uses: ad-m/github-push-action@master
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
version: ["", "latest", "1.29.0"]
version: ["", "latest", "1.46.4"]
fail-fast: false
steps:
# Checkout and install prerequisites
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup NodeJS
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "16.x"
node-version: "20.x"

# Run action according to the input version
- name: Setup JFrog CLI
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Additionally, the Action incorporates the following features when utilizing JFro
## Usage

```yml
- uses: jfrog/setup-jfrog-cli@v3
- uses: jfrog/setup-jfrog-cli@v4
- run: jf --version
```

Expand Down Expand Up @@ -67,7 +67,7 @@ You can set the connection details to your JFrog Platform by using one of the fo
You can use these environment variables in your workflow as follows:

```yml
- uses: jfrog/setup-jfrog-cli@v3
- uses: jfrog/setup-jfrog-cli@v4
env:
# JFrog platform url (for example: https://acme.jfrog.io)
JF_URL: ${{ secrets.JF_URL }}
Expand Down Expand Up @@ -97,7 +97,7 @@ The secret should be exposed as an environment variable with the _JF*ENV*_ prefi
Here's how you do this:

```yml
- uses: jfrog/setup-jfrog-cli@v3
- uses: jfrog/setup-jfrog-cli@v4
env:
JF_ENV_1: ${{ secrets.JF_SECRET_ENV_1 }}
- run: |
Expand All @@ -111,7 +111,7 @@ as the _JF_ENV_1_ environment variable. That's it - the ping command will now pi
If you have multiple Config Tokens as secrets, you can use all of them in the workflow as follows:

```yml
- uses: jfrog/setup-jfrog-cli@v3
- uses: jfrog/setup-jfrog-cli@v4
env:
JF_ENV_1: ${{ secrets.JF_SECRET_ENV_1 }}
JF_ENV_2: ${{ secrets.JF_SECRET_ENV_2 }}
Expand Down Expand Up @@ -188,7 +188,7 @@ To utilize the OIDC protocol, follow these steps:
Example step utilizing OpenID Connect:

```yml
- uses: jfrog/setup-jfrog-cli@v3
- uses: jfrog/setup-jfrog-cli@v4
env:
JF_URL: ${{ secrets.JF_URL }}
with:
Expand Down Expand Up @@ -218,20 +218,20 @@ are registered as the build artifacts.
By default, the JFrog CLI version set in [action.yml](https://github.com/jfrog/setup-jfrog-cli/blob/master/action.yml) is used. To set a specific version, add the _version_ input as follows:

```yml
- uses: jfrog/setup-jfrog-cli@v3
- uses: jfrog/setup-jfrog-cli@v4
with:
version: X.Y.Z
```

It is also possible to set the latest JFrog CLI version by adding the _version_ input as follows:

```yml
- uses: jfrog/setup-jfrog-cli@v3
- uses: jfrog/setup-jfrog-cli@v4
with:
version: latest
```

| Important: Only JFrog CLI versions 1.29.0 or above are supported. |
| Important: Only JFrog CLI versions 1.46.4 or above are supported. |
| ----------------------------------------------------------------- |

## Downloading JFrog CLI from Artifactory
Expand All @@ -244,7 +244,7 @@ Here's how you do this:
2. Set _download-repository_ input to jfrog-cli-remote:

```yml
- uses: jfrog/setup-jfrog-cli@v3
- uses: jfrog/setup-jfrog-cli@v4
env:
# JFrog platform url (for example: https://acme.jfrog.io)
JF_URL: ${{ secrets.JF_URL }}
Expand Down
43 changes: 3 additions & 40 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,10 @@ class Utils {
// Get Config Tokens created on your local machine using JFrog CLI.
// The Tokens configured with JF_ENV_ environment variables.
static getConfigTokens() {
let configTokens = new Set(Object.keys(process.env)
return new Set(Object.keys(process.env)
.filter((envKey) => envKey.match(Utils.CONFIG_TOKEN_PREFIX))
.filter((envKey) => process.env[envKey])
.map((envKey) => { var _a; return ((_a = process.env[envKey]) === null || _a === void 0 ? void 0 : _a.trim()) || ''; }));
let legacyConfigTokens = new Set(Object.keys(process.env)
.filter((envKey) => envKey.match(Utils.CONFIG_TOKEN_LEGACY_PREFIX))
.filter((envKey) => process.env[envKey])
.map((envKey) => { var _a; return ((_a = process.env[envKey]) === null || _a === void 0 ? void 0 : _a.trim()) || ''; }));
if (legacyConfigTokens.size > 0) {
core.warning('The "JF_ARTIFACTORY_" prefix for environment variables is deprecated and is expected to be removed in v3. ' +
'Please use the "JF_ENV_" prefix instead. The environment variables value should not be changed.');
}
legacyConfigTokens.forEach((configToken) => configTokens.add(configToken));
return configTokens;
}
/**
* Get separate env config for the URL and connection details and return args to add to the config add command
Expand Down Expand Up @@ -283,13 +273,6 @@ class Utils {
static configJFrogServers(jfrogCredentials) {
return __awaiter(this, void 0, void 0, function* () {
let cliConfigCmd = ['config'];
let useOldConfig = Utils.useOldConfig();
if (useOldConfig) {
// Add 'rt' prefix to the beginning of the config command
cliConfigCmd.unshift('rt');
let version = core.getInput(Utils.CLI_VERSION_ARG);
core.warning('JFrog CLI ' + version + ' on Setup JFrog CLI GitHub Action is deprecated. Please use version 1.46.4 or above.');
}
for (let configToken of Utils.getConfigTokens()) {
yield Utils.runCli(cliConfigCmd.concat('import', configToken));
}
Expand All @@ -301,12 +284,7 @@ class Utils {
}
static removeJFrogServers() {
return __awaiter(this, void 0, void 0, function* () {
if (Utils.useOldConfig()) {
yield Utils.runCli(['rt', 'c', 'clear', '--interactive=false']);
}
else {
yield Utils.runCli(['c', 'rm', '--quiet']);
}
yield Utils.runCli(['c', 'rm', '--quiet']);
});
}
static getArchitecture() {
Expand Down Expand Up @@ -391,17 +369,6 @@ class Utils {
}
return;
}
/**
* Return true if should use 'jfrog rt c' instead of 'jfrog c'.
* @returns true if should use 'jfrog rt c' instead of 'jfrog c'.
*/
static useOldConfig() {
let version = core.getInput(Utils.CLI_VERSION_ARG);
if (version === this.LATEST_CLI_VERSION) {
return false;
}
return (0, semver_1.lt)(version, this.NEW_CONFIG_CLI_VERSION);
}
}
exports.Utils = Utils;
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand All @@ -411,14 +378,10 @@ Utils.DEFAULT_DOWNLOAD_DETAILS = {
artifactoryUrl: 'https://releases.jfrog.io/artifactory',
repository: 'jfrog-cli',
};
// The old JF_ARTIFACTORY_* prefix for Config Tokens
Utils.CONFIG_TOKEN_LEGACY_PREFIX = /^JF_ARTIFACTORY_.*$/;
// The JF_ENV_* prefix for Config Tokens
Utils.CONFIG_TOKEN_PREFIX = /^JF_ENV_.*$/;
// Since 1.45.0, 'jfrog rt c' command changed to 'jfrog c add'
Utils.NEW_CONFIG_CLI_VERSION = '1.45.0';
// Minimum JFrog CLI version supported
Utils.MIN_CLI_VERSION = '1.29.0';
Utils.MIN_CLI_VERSION = '1.46.4';
// The value in "version" argument to set to get the latest JFrog CLI version
Utils.LATEST_CLI_VERSION = 'latest';
// The value in the download URL to set to get the latest version
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@jfrog/setup-jfrog-cli",
"version": "3.5.3",
"version": "4.0.0",
"private": true,
"description": "Setup JFrog CLI in GitHub Actions",
"main": "lib/main.js",
"engines": {
"npm": ">=8.0.0",
"node": ">=16.0.0"
"npm": ">=10.0.0",
"node": ">=20.0.0"
},
"scripts": {
"build": "tsc",
Expand Down
50 changes: 3 additions & 47 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ export class Utils {
repository: 'jfrog-cli',
} as DownloadDetails;

// The old JF_ARTIFACTORY_* prefix for Config Tokens
private static readonly CONFIG_TOKEN_LEGACY_PREFIX: RegExp = /^JF_ARTIFACTORY_.*$/;
// The JF_ENV_* prefix for Config Tokens
private static readonly CONFIG_TOKEN_PREFIX: RegExp = /^JF_ENV_.*$/;
// Since 1.45.0, 'jfrog rt c' command changed to 'jfrog c add'
private static readonly NEW_CONFIG_CLI_VERSION: string = '1.45.0';
// Minimum JFrog CLI version supported
private static readonly MIN_CLI_VERSION: string = '1.29.0';
private static readonly MIN_CLI_VERSION: string = '1.46.4';
// The value in "version" argument to set to get the latest JFrog CLI version
private static readonly LATEST_CLI_VERSION: string = 'latest';
// The value in the download URL to set to get the latest version
Expand Down Expand Up @@ -230,29 +226,12 @@ export class Utils {
// Get Config Tokens created on your local machine using JFrog CLI.
// The Tokens configured with JF_ENV_ environment variables.
public static getConfigTokens(): Set<string> {
let configTokens: Set<string> = new Set(
return new Set(
Object.keys(process.env)
.filter((envKey) => envKey.match(Utils.CONFIG_TOKEN_PREFIX))
.filter((envKey) => process.env[envKey])
.map((envKey) => process.env[envKey]?.trim() || ''),
);

let legacyConfigTokens: Set<string> = new Set(
Object.keys(process.env)
.filter((envKey) => envKey.match(Utils.CONFIG_TOKEN_LEGACY_PREFIX))
.filter((envKey) => process.env[envKey])
.map((envKey) => process.env[envKey]?.trim() || ''),
);

if (legacyConfigTokens.size > 0) {
core.warning(
'The "JF_ARTIFACTORY_" prefix for environment variables is deprecated and is expected to be removed in v3. ' +
'Please use the "JF_ENV_" prefix instead. The environment variables value should not be changed.',
);
}

legacyConfigTokens.forEach((configToken) => configTokens.add(configToken));
return configTokens;
}

/**
Expand Down Expand Up @@ -311,13 +290,6 @@ export class Utils {

public static async configJFrogServers(jfrogCredentials: JfrogCredentials) {
let cliConfigCmd: string[] = ['config'];
let useOldConfig: boolean = Utils.useOldConfig();
if (useOldConfig) {
// Add 'rt' prefix to the beginning of the config command
cliConfigCmd.unshift('rt');
let version: string = core.getInput(Utils.CLI_VERSION_ARG);
core.warning('JFrog CLI ' + version + ' on Setup JFrog CLI GitHub Action is deprecated. Please use version 1.46.4 or above.');
}
for (let configToken of Utils.getConfigTokens()) {
await Utils.runCli(cliConfigCmd.concat('import', configToken));
}
Expand All @@ -329,11 +301,7 @@ export class Utils {
}

public static async removeJFrogServers() {
if (Utils.useOldConfig()) {
await Utils.runCli(['rt', 'c', 'clear', '--interactive=false']);
} else {
await Utils.runCli(['c', 'rm', '--quiet']);
}
await Utils.runCli(['c', 'rm', '--quiet']);
}

public static getArchitecture() {
Expand Down Expand Up @@ -425,18 +393,6 @@ export class Utils {
}
return;
}

/**
* Return true if should use 'jfrog rt c' instead of 'jfrog c'.
* @returns true if should use 'jfrog rt c' instead of 'jfrog c'.
*/
private static useOldConfig(): boolean {
let version: string = core.getInput(Utils.CLI_VERSION_ARG);
if (version === this.LATEST_CLI_VERSION) {
return false;
}
return lt(version, this.NEW_CONFIG_CLI_VERSION);
}
}

export interface DownloadDetails {
Expand Down
28 changes: 1 addition & 27 deletions test/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,7 @@ const V2_CONFIG_TOKEN: string = `eyJ2ZXJzaW9uIjoyLCJ1cmwiOiJodHRwOi8vMTI3LjAuMC4
zNsQzdqSXkzSmdudC1WQSIsInNlcnZlcklkIjoibG9jYWwifQ==`;

beforeEach(() => {
[
'JF_ARTIFACTORY_1',
'JF_ARTIFACTORY_2',
'ARTIFACTORY_JF_1',
'JF_ENV_1',
'JF_ENV_2',
'ENV_JF_1',
'JF_ENV_LOCAL',
'JF_USER',
'JF_PASSWORD',
'JF_ACCESS_TOKEN',
].forEach((envKey) => {
['JF_ENV_1', 'JF_ENV_2', 'ENV_JF_1', 'JF_ENV_LOCAL', 'JF_USER', 'JF_PASSWORD', 'JF_ACCESS_TOKEN'].forEach((envKey) => {
delete process.env[envKey];
});
});
Expand All @@ -58,21 +47,6 @@ test('Get Config Tokens', async () => {
expect(configTokens).toStrictEqual(new Set(['DUMMY_CONFIG_TOKEN_1', 'DUMMY_CONFIG_TOKEN_2']));
});

test('Get legacy Config Tokens', async () => {
process.env['ARTIFACTORY_JF_1'] = 'ILLEGAL_CONFIG_TOKEN';
expect(Utils.getConfigTokens().size).toBe(0);

process.env['JF_ARTIFACTORY_1'] = 'DUMMY_CONFIG_TOKEN_1';
expect(Utils.getConfigTokens()).toStrictEqual(new Set(['DUMMY_CONFIG_TOKEN_1']));

process.env['JF_ARTIFACTORY_2'] = 'DUMMY_CONFIG_TOKEN_2';
expect(Utils.getConfigTokens()).toStrictEqual(new Set(['DUMMY_CONFIG_TOKEN_1', 'DUMMY_CONFIG_TOKEN_2']));

process.env['JF_ENV_1'] = 'DUMMY_CONFIG_TOKEN_1';
process.env['JF_ENV_2'] = 'DUMMY_CONFIG_TOKEN_3';
expect(Utils.getConfigTokens()).toStrictEqual(new Set(['DUMMY_CONFIG_TOKEN_1', 'DUMMY_CONFIG_TOKEN_2', 'DUMMY_CONFIG_TOKEN_3']));
});

describe('Collect credentials from environment variables test', () => {
let cases: string[][] = [
// [JF_URL, JF_ACCESS_TOKEN, JF_USER, JF_PASSWORD]
Expand Down
Loading