Skip to content

Commit 48d7925

Browse files
talarian1yahavi
andauthored
Add support for JFrog cli version:latest (#59)
* Add support for JFrog cli version:latest * Update default version to 2.11.1 * Add default version test Co-authored-by: Yahav Itzhak <[email protected]>
1 parent 27c96c5 commit 48d7925

File tree

6 files changed

+52
-16
lines changed

6 files changed

+52
-16
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,26 @@ jobs:
77
strategy:
88
matrix:
99
os: [ubuntu-latest, windows-latest, macOS-latest]
10+
version: ['', 'latest', '2.11.1']
1011
fail-fast: false
1112
steps:
1213
- name: Checkout
1314
uses: actions/checkout@v2
1415
- name: Setup JFrog CLI
16+
if: matrix.version != ''
1517
uses: ./
18+
with:
19+
version: ${{ matrix.version }}
1620
env:
1721
JF_ARTIFACTORY_LOCAL: eyJ2ZXJzaW9uIjoxLCJ1cmwiOiJodHRwOi8vMTI3LjAuMC4xOjgwODEvYXJ0aWZhY3RvcnkvIiwidXNlciI6ImFkbWluIiwicGFzc3dvcmQiOiJBUEI3REVaUlBpSHFIRFRRb2tMa3g5aGh6S1QiLCJzZXJ2ZXJJZCI6ImxvY2FsIn0=
18-
- name: Sanity # Check that the correct CLI downloaded and local server successfully configured
22+
- name: Setup default JFrog CLI
23+
if: matrix.version == ''
24+
uses: ./
25+
env:
26+
JF_ARTIFACTORY_LOCAL: eyJ2ZXJzaW9uIjoxLCJ1cmwiOiJodHRwOi8vMTI3LjAuMC4xOjgwODEvYXJ0aWZhY3RvcnkvIiwidXNlciI6ImFkbWluIiwicGFzc3dvcmQiOiJBUEI3REVaUlBpSHFIRFRRb2tMa3g5aGh6S1QiLCJzZXJ2ZXJJZCI6ImxvY2FsIn0=
27+
- name: Version # Check that the correct CLI version was downloaded
28+
run: jfrog --version
29+
- name: Sanity # Check local server successfully configured
1930
run: jfrog c show local
2031
- name: Check build URL
2132
uses: wei/curl@master
@@ -32,3 +43,4 @@ jobs:
3243
run: npm i
3344
- name: Unit tests
3445
run: npm t
46+

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This GitHub Action downloads, installs and configures JFrog CLI, so that it can
66

77
In addition, the Action includes the following features, when using JFrog CLI to work with Artifactory.
88
* The connection details of the Artifactory servers used by JFrog CLI can be stored as secrets. Read more about it [here](#storing-artifactory-servers-details-as-secrets).
9-
* There's no need to add the *build name* and *build number* options and arguments to commands which accpet them.
9+
* There's no need to add the *build name* and *build number* options and arguments to commands which accept them.
1010
All build related operations will be automatically recorded with the *Workflow Name* as build name and *Run Number* as build number.
1111

1212
# Usage
@@ -50,11 +50,11 @@ If you have multiple Artifactory servers configured as secrets, you can use all
5050
JF_ARTIFACTORY_2: ${{ secrets.JF_ARTIFACTORY_SECRET_2 }}
5151
- run: |
5252
# Set the Artifactory server to use by providing the server ID (configured by the 'jfrog c add' command).
53-
jfrog rt use local-1
53+
jfrog c use local-1
5454
# Ping local-1
5555
jfrog rt ping
5656
# Now use the second sever configuration exposed to the Action.
57-
jfrog rt use local-2
57+
jfrog c use local-2
5858
# Ping local-2
5959
jfrog rt ping
6060
```
@@ -66,7 +66,7 @@ The Action automatically sets the following environment variables:
6666
*JFROG_CLI_BUILD_NAME* and *JFROG_CLI_BUILD_NUMBER* with the workflow name and run number respectively.
6767
You therefore don't need to specify the build name and build number on any of the build related JFrog CLI commands.
6868

69-
In the following example, all downloaded files are registered as depedencies of the build and all uploaded files
69+
In the following example, all downloaded files are registered as dependencies of the build and all uploaded files
7070
are registered as the build artifacts.
7171
```yml
7272
- run: |
@@ -83,6 +83,15 @@ By default the JFrog CLI version set in [action.yml](https://github.com/jfrog/se
8383
with:
8484
version: X.Y.Z
8585
```
86+
87+
It is also possible to set the latest JFrog CLI version by adding the *version* input as follows:
88+
89+
```yml
90+
- uses: jfrog/setup-jfrog-cli@v2
91+
with:
92+
version: latest
93+
```
94+
8695
| Important: Only JFrog CLI versions 1.29.0 or above are supported. |
8796
| --- |
8897

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: 'JFrog'
44
inputs:
55
version:
66
description: 'JFrog CLI Version'
7-
default: '2.3.0'
7+
default: '2.11.1'
88
required: false
99
runs:
1010
using: 'node12'

lib/utils.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ class Utils {
4040
static downloadCli() {
4141
return __awaiter(this, void 0, void 0, function* () {
4242
let version = core.getInput(Utils.CLI_VERSION_ARG);
43-
if (semver.lt(version, this.MIN_CLI_VERSION)) {
43+
let major = version.split('.')[0];
44+
if (version === this.LATEST_CLI_VERSION_ARG) {
45+
version = '[RELEASE]';
46+
major = '2';
47+
}
48+
else if (semver.lt(version, this.MIN_CLI_VERSION)) {
4449
throw new Error('Requested to download JFrog CLI version ' + version + ' but must be at least ' + this.MIN_CLI_VERSION);
4550
}
4651
let fileName = Utils.getCliExecutableName();
@@ -49,7 +54,7 @@ class Utils {
4954
core.addPath(cliDir);
5055
return path.join(cliDir, fileName);
5156
}
52-
let url = Utils.getCliUrl(version, fileName);
57+
let url = Utils.getCliUrl(major, version, fileName);
5358
core.debug('Downloading JFrog CLI from ' + url);
5459
let downloadDir = yield toolCache.downloadTool(url);
5560
cliDir = yield toolCache.cacheFile(downloadDir, fileName, fileName, version);
@@ -61,9 +66,8 @@ class Utils {
6166
return cliPath;
6267
});
6368
}
64-
static getCliUrl(version, fileName) {
69+
static getCliUrl(major, version, fileName) {
6570
let architecture = 'jfrog-cli-' + Utils.getArchitecture();
66-
let major = version.split('.')[0];
6771
return 'https://releases.jfrog.io/artifactory/jfrog-cli/v' + major + '/' + version + '/' + architecture + '/' + fileName;
6872
}
6973
static getServerTokens() {
@@ -140,6 +144,9 @@ class Utils {
140144
*/
141145
static useOldConfig() {
142146
let version = core.getInput(Utils.CLI_VERSION_ARG);
147+
if (version === this.LATEST_CLI_VERSION_ARG) {
148+
return false;
149+
}
143150
return semver.lt(version, this.NEW_CONFIG_CLI_VERSION);
144151
}
145152
}
@@ -150,3 +157,4 @@ Utils.SERVER_TOKEN_PREFIX = /^JF_ARTIFACTORY_.*$/;
150157
Utils.NEW_CONFIG_CLI_VERSION = '1.45.0';
151158
Utils.CLI_VERSION_ARG = 'version';
152159
Utils.MIN_CLI_VERSION = '1.29.0';
160+
Utils.LATEST_CLI_VERSION_ARG = 'latest';

src/utils.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ export class Utils {
1313
public static readonly NEW_CONFIG_CLI_VERSION: string = '1.45.0';
1414
public static readonly CLI_VERSION_ARG: string = 'version';
1515
public static readonly MIN_CLI_VERSION: string = '1.29.0';
16+
public static readonly LATEST_CLI_VERSION_ARG: string = 'latest';
1617

1718
public static async downloadCli(): Promise<string> {
1819
let version: string = core.getInput(Utils.CLI_VERSION_ARG);
19-
if (semver.lt(version, this.MIN_CLI_VERSION)) {
20+
let major: string = version.split('.')[0];
21+
if (version === this.LATEST_CLI_VERSION_ARG) {
22+
version = '[RELEASE]';
23+
major = '2';
24+
} else if (semver.lt(version, this.MIN_CLI_VERSION)) {
2025
throw new Error('Requested to download JFrog CLI version ' + version + ' but must be at least ' + this.MIN_CLI_VERSION);
2126
}
2227
let fileName: string = Utils.getCliExecutableName();
@@ -25,7 +30,7 @@ export class Utils {
2530
core.addPath(cliDir);
2631
return path.join(cliDir, fileName);
2732
}
28-
let url: string = Utils.getCliUrl(version, fileName);
33+
let url: string = Utils.getCliUrl(major, version, fileName);
2934
core.debug('Downloading JFrog CLI from ' + url);
3035
let downloadDir: string = await toolCache.downloadTool(url);
3136
cliDir = await toolCache.cacheFile(downloadDir, fileName, fileName, version);
@@ -37,9 +42,8 @@ export class Utils {
3742
return cliPath;
3843
}
3944

40-
public static getCliUrl(version: string, fileName: string): string {
45+
public static getCliUrl(major: string, version: string, fileName: string): string {
4146
let architecture: string = 'jfrog-cli-' + Utils.getArchitecture();
42-
let major: string = version.split('.')[0];
4347
return 'https://releases.jfrog.io/artifactory/jfrog-cli/v' + major + '/' + version + '/' + architecture + '/' + fileName;
4448
}
4549

@@ -121,6 +125,9 @@ export class Utils {
121125
*/
122126
private static useOldConfig(): boolean {
123127
let version: string = core.getInput(Utils.CLI_VERSION_ARG);
128+
if (version === this.LATEST_CLI_VERSION_ARG) {
129+
return false;
130+
}
124131
return semver.lt(version, this.NEW_CONFIG_CLI_VERSION);
125132
}
126133
}

test/main.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('JFrog CLI action Tests', () => {
3939
test.each(cases)('CLI Url for %s-%s', (platform, arch, fileName, expectedUrl) => {
4040
myOs.platform.mockImplementation(() => <NodeJS.Platform>platform);
4141
myOs.arch.mockImplementation(() => arch);
42-
let cliUrl: string = Utils.getCliUrl('1.2.3', fileName);
42+
let cliUrl: string = Utils.getCliUrl('1', '1.2.3', fileName);
4343
expect(cliUrl).toBe(expectedUrl);
4444
});
4545
});
@@ -63,7 +63,7 @@ describe('JFrog CLI action Tests', () => {
6363
test.each(cases)('CLI Url for %s-%s', (platform, arch, fileName, expectedUrl) => {
6464
myOs.platform.mockImplementation(() => <NodeJS.Platform>platform);
6565
myOs.arch.mockImplementation(() => arch);
66-
let cliUrl: string = Utils.getCliUrl('2.3.4', fileName);
66+
let cliUrl: string = Utils.getCliUrl('2', '2.3.4', fileName);
6767
expect(cliUrl).toBe(expectedUrl);
6868
});
6969
});

0 commit comments

Comments
 (0)