From 48d7925d2c5cc5045aa90f855f398b061dcf64ee Mon Sep 17 00:00:00 2001 From: Tal Arian Date: Tue, 1 Feb 2022 12:40:40 +0200 Subject: [PATCH] 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 --- .github/workflows/test.yml | 14 +++++++++++++- README.md | 17 +++++++++++++---- action.yml | 2 +- lib/utils.js | 16 ++++++++++++---- src/utils.ts | 15 +++++++++++---- test/main.spec.ts | 4 ++-- 6 files changed, 52 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 09214421b..9fa3831a4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -32,3 +43,4 @@ jobs: run: npm i - name: Unit tests run: npm t + diff --git a/README.md b/README.md index 283233f8c..2282486d7 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` @@ -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: | @@ -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. | | --- | diff --git a/action.yml b/action.yml index 572fd8af0..669512031 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/lib/utils.js b/lib/utils.js index c4091d3c2..c69384232 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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(); @@ -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); @@ -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() { @@ -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); } } @@ -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'; diff --git a/src/utils.ts b/src/utils.ts index a1bc6bdb6..24b1ff4a1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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 { 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(); @@ -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); @@ -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; } @@ -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); } } diff --git a/test/main.spec.ts b/test/main.spec.ts index 86406db58..49fabcfdd 100644 --- a/test/main.spec.ts +++ b/test/main.spec.ts @@ -39,7 +39,7 @@ describe('JFrog CLI action Tests', () => { test.each(cases)('CLI Url for %s-%s', (platform, arch, fileName, expectedUrl) => { myOs.platform.mockImplementation(() => 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); }); }); @@ -63,7 +63,7 @@ describe('JFrog CLI action Tests', () => { test.each(cases)('CLI Url for %s-%s', (platform, arch, fileName, expectedUrl) => { myOs.platform.mockImplementation(() => 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); }); });