Skip to content

Commit

Permalink
Add support for JFrog cli version:latest (#59)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
talarian1 and yahavi authored Feb 1, 2022
1 parent 27c96c5 commit 48d7925
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 16 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
version: ['', 'latest', '2.11.1']
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup JFrog CLI
if: matrix.version != ''
uses: ./
with:
version: ${{ matrix.version }}
env:
JF_ARTIFACTORY_LOCAL: eyJ2ZXJzaW9uIjoxLCJ1cmwiOiJodHRwOi8vMTI3LjAuMC4xOjgwODEvYXJ0aWZhY3RvcnkvIiwidXNlciI6ImFkbWluIiwicGFzc3dvcmQiOiJBUEI3REVaUlBpSHFIRFRRb2tMa3g5aGh6S1QiLCJzZXJ2ZXJJZCI6ImxvY2FsIn0=
- name: Sanity # Check that the correct CLI downloaded and local server successfully configured
- name: Setup default JFrog CLI
if: matrix.version == ''
uses: ./
env:
JF_ARTIFACTORY_LOCAL: eyJ2ZXJzaW9uIjoxLCJ1cmwiOiJodHRwOi8vMTI3LjAuMC4xOjgwODEvYXJ0aWZhY3RvcnkvIiwidXNlciI6ImFkbWluIiwicGFzc3dvcmQiOiJBUEI3REVaUlBpSHFIRFRRb2tMa3g5aGh6S1QiLCJzZXJ2ZXJJZCI6ImxvY2FsIn0=
- name: Version # Check that the correct CLI version was downloaded
run: jfrog --version
- name: Sanity # Check local server successfully configured
run: jfrog c show local
- name: Check build URL
uses: wei/curl@master
Expand All @@ -32,3 +43,4 @@ jobs:
run: npm i
- name: Unit tests
run: npm t

17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This GitHub Action downloads, installs and configures JFrog CLI, so that it can

In addition, the Action includes the following features, when using JFrog CLI to work with Artifactory.
* 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).
* There's no need to add the *build name* and *build number* options and arguments to commands which accpet them.
* There's no need to add the *build name* and *build number* options and arguments to commands which accept them.
All build related operations will be automatically recorded with the *Workflow Name* as build name and *Run Number* as build number.

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

In the following example, all downloaded files are registered as depedencies of the build and all uploaded files
In the following example, all downloaded files are registered as dependencies of the build and all uploaded files
are registered as the build artifacts.
```yml
- run: |
Expand All @@ -83,6 +83,15 @@ By default the JFrog CLI version set in [action.yml](https://github.com/jfrog/se
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@v2
with:
version: latest
```

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

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ author: 'JFrog'
inputs:
version:
description: 'JFrog CLI Version'
default: '2.3.0'
default: '2.11.1'
required: false
runs:
using: 'node12'
Expand Down
16 changes: 12 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ class Utils {
static downloadCli() {
return __awaiter(this, void 0, void 0, function* () {
let version = core.getInput(Utils.CLI_VERSION_ARG);
if (semver.lt(version, this.MIN_CLI_VERSION)) {
let major = version.split('.')[0];
if (version === this.LATEST_CLI_VERSION_ARG) {
version = '[RELEASE]';
major = '2';
}
else if (semver.lt(version, this.MIN_CLI_VERSION)) {
throw new Error('Requested to download JFrog CLI version ' + version + ' but must be at least ' + this.MIN_CLI_VERSION);
}
let fileName = Utils.getCliExecutableName();
Expand All @@ -49,7 +54,7 @@ class Utils {
core.addPath(cliDir);
return path.join(cliDir, fileName);
}
let url = Utils.getCliUrl(version, fileName);
let url = Utils.getCliUrl(major, version, fileName);
core.debug('Downloading JFrog CLI from ' + url);
let downloadDir = yield toolCache.downloadTool(url);
cliDir = yield toolCache.cacheFile(downloadDir, fileName, fileName, version);
Expand All @@ -61,9 +66,8 @@ class Utils {
return cliPath;
});
}
static getCliUrl(version, fileName) {
static getCliUrl(major, version, fileName) {
let architecture = 'jfrog-cli-' + Utils.getArchitecture();
let major = version.split('.')[0];
return 'https://releases.jfrog.io/artifactory/jfrog-cli/v' + major + '/' + version + '/' + architecture + '/' + fileName;
}
static getServerTokens() {
Expand Down Expand Up @@ -140,6 +144,9 @@ class Utils {
*/
static useOldConfig() {
let version = core.getInput(Utils.CLI_VERSION_ARG);
if (version === this.LATEST_CLI_VERSION_ARG) {
return false;
}
return semver.lt(version, this.NEW_CONFIG_CLI_VERSION);
}
}
Expand All @@ -150,3 +157,4 @@ Utils.SERVER_TOKEN_PREFIX = /^JF_ARTIFACTORY_.*$/;
Utils.NEW_CONFIG_CLI_VERSION = '1.45.0';
Utils.CLI_VERSION_ARG = 'version';
Utils.MIN_CLI_VERSION = '1.29.0';
Utils.LATEST_CLI_VERSION_ARG = 'latest';
15 changes: 11 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ export class Utils {
public static readonly NEW_CONFIG_CLI_VERSION: string = '1.45.0';
public static readonly CLI_VERSION_ARG: string = 'version';
public static readonly MIN_CLI_VERSION: string = '1.29.0';
public static readonly LATEST_CLI_VERSION_ARG: string = 'latest';

public static async downloadCli(): Promise<string> {
let version: string = core.getInput(Utils.CLI_VERSION_ARG);
if (semver.lt(version, this.MIN_CLI_VERSION)) {
let major: string = version.split('.')[0];
if (version === this.LATEST_CLI_VERSION_ARG) {
version = '[RELEASE]';
major = '2';
} else if (semver.lt(version, this.MIN_CLI_VERSION)) {
throw new Error('Requested to download JFrog CLI version ' + version + ' but must be at least ' + this.MIN_CLI_VERSION);
}
let fileName: string = Utils.getCliExecutableName();
Expand All @@ -25,7 +30,7 @@ export class Utils {
core.addPath(cliDir);
return path.join(cliDir, fileName);
}
let url: string = Utils.getCliUrl(version, fileName);
let url: string = Utils.getCliUrl(major, version, fileName);
core.debug('Downloading JFrog CLI from ' + url);
let downloadDir: string = await toolCache.downloadTool(url);
cliDir = await toolCache.cacheFile(downloadDir, fileName, fileName, version);
Expand All @@ -37,9 +42,8 @@ export class Utils {
return cliPath;
}

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

Expand Down Expand Up @@ -121,6 +125,9 @@ export class Utils {
*/
private static useOldConfig(): boolean {
let version: string = core.getInput(Utils.CLI_VERSION_ARG);
if (version === this.LATEST_CLI_VERSION_ARG) {
return false;
}
return semver.lt(version, this.NEW_CONFIG_CLI_VERSION);
}
}
4 changes: 2 additions & 2 deletions test/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('JFrog CLI action Tests', () => {
test.each(cases)('CLI Url for %s-%s', (platform, arch, fileName, expectedUrl) => {
myOs.platform.mockImplementation(() => <NodeJS.Platform>platform);
myOs.arch.mockImplementation(() => arch);
let cliUrl: string = Utils.getCliUrl('1.2.3', fileName);
let cliUrl: string = Utils.getCliUrl('1', '1.2.3', fileName);
expect(cliUrl).toBe(expectedUrl);
});
});
Expand All @@ -63,7 +63,7 @@ describe('JFrog CLI action Tests', () => {
test.each(cases)('CLI Url for %s-%s', (platform, arch, fileName, expectedUrl) => {
myOs.platform.mockImplementation(() => <NodeJS.Platform>platform);
myOs.arch.mockImplementation(() => arch);
let cliUrl: string = Utils.getCliUrl('2.3.4', fileName);
let cliUrl: string = Utils.getCliUrl('2', '2.3.4', fileName);
expect(cliUrl).toBe(expectedUrl);
});
});
Expand Down

0 comments on commit 48d7925

Please sign in to comment.