From a495e0b30dcafce7ad27e9340a631d9c13701f91 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Wed, 4 Oct 2023 16:00:19 +0300 Subject: [PATCH 01/21] fix latest build Signed-off-by: Michael Sverdlov --- scan/cli.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scan/cli.go b/scan/cli.go index e9342f2b9..44f1c2d15 100644 --- a/scan/cli.go +++ b/scan/cli.go @@ -235,11 +235,11 @@ func CurationCmd(c *cli.Context) error { func createAuditCmd(c *cli.Context) (*audit.AuditCommand, error) { auditCmd := audit.NewGenericAuditCommand() - err := validateXrayContext(c) + serverDetails, err := createServerDetailsWithConfigOffer(c) if err != nil { return nil, err } - serverDetails, err := createServerDetailsWithConfigOffer(c) + err = validateXrayContext(c, serverDetails) if err != nil { return nil, err } @@ -282,11 +282,11 @@ func ScanCmd(c *cli.Context) error { if c.NArg() == 0 && !c.IsSet("spec") { return cliutils.PrintHelpAndReturnError("providing either a argument or the 'spec' option is mandatory", c) } - err := validateXrayContext(c) + serverDetails, err := createServerDetailsWithConfigOffer(c) if err != nil { return err } - serverDetails, err := createServerDetailsWithConfigOffer(c) + err = validateXrayContext(c, serverDetails) if err != nil { return err } @@ -344,12 +344,11 @@ func BuildScan(c *cli.Context) error { if err := buildConfiguration.ValidateBuildParams(); err != nil { return err } - serverDetails, err := createServerDetailsWithConfigOffer(c) if err != nil { return err } - err = validateXrayContext(c) + err = validateXrayContext(c, serverDetails) if err != nil { return err } @@ -378,11 +377,11 @@ func DockerScan(c *cli.Context, image string) error { if image == "" { return cli.ShowCommandHelp(c, "dockerscanhelp") } - err := validateXrayContext(c) + serverDetails, err := createServerDetailsWithConfigOffer(c) if err != nil { return err } - serverDetails, err := createServerDetailsWithConfigOffer(c) + err = validateXrayContext(c, serverDetails) if err != nil { return err } @@ -443,7 +442,10 @@ func shouldIncludeVulnerabilities(c *cli.Context) bool { return c.String("watches") == "" && !isProjectProvided(c) && c.String("repo-path") == "" } -func validateXrayContext(c *cli.Context) error { +func validateXrayContext(c *cli.Context, serverDetails *coreconfig.ServerDetails) error { + if serverDetails.XrayUrl == "" { + return errorutils.CheckErrorf("JFrog Xray URL should be provided to run this command") + } contextFlag := 0 if c.String("watches") != "" { contextFlag++ From ea9a62f2edea5ab3da9a11ad3c0456571e97de26 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Wed, 4 Oct 2023 16:34:54 +0300 Subject: [PATCH 02/21] fix latest build Signed-off-by: Michael Sverdlov --- scan/cli.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scan/cli.go b/scan/cli.go index 44f1c2d15..f9900fc44 100644 --- a/scan/cli.go +++ b/scan/cli.go @@ -444,7 +444,7 @@ func shouldIncludeVulnerabilities(c *cli.Context) bool { func validateXrayContext(c *cli.Context, serverDetails *coreconfig.ServerDetails) error { if serverDetails.XrayUrl == "" { - return errorutils.CheckErrorf("JFrog Xray URL should be provided to run this command") + return errorutils.CheckErrorf("JFrog Xray URL should be provided to run this command. Use the 'jf c add' command to set the Xray server details.") } contextFlag := 0 if c.String("watches") != "" { From 27ec8e86c248d68838f48a54d23c0c89b8edb65a Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Wed, 4 Oct 2023 16:43:24 +0300 Subject: [PATCH 03/21] fix latest build Signed-off-by: Michael Sverdlov --- scan/cli.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scan/cli.go b/scan/cli.go index f9900fc44..a53d499f8 100644 --- a/scan/cli.go +++ b/scan/cli.go @@ -444,7 +444,7 @@ func shouldIncludeVulnerabilities(c *cli.Context) bool { func validateXrayContext(c *cli.Context, serverDetails *coreconfig.ServerDetails) error { if serverDetails.XrayUrl == "" { - return errorutils.CheckErrorf("JFrog Xray URL should be provided to run this command. Use the 'jf c add' command to set the Xray server details.") + return errorutils.CheckErrorf("JFrog Xray URL must be provided in order run this command. Use the 'jf c add' command to set the Xray server details.") } contextFlag := 0 if c.String("watches") != "" { From ca3da284f30aef01535a0ff5bd5d7315e10bad91 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 15:36:49 +0300 Subject: [PATCH 04/21] fix latest build Signed-off-by: Michael Sverdlov --- .github/workflows/scriptTests.yml | 39 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/.github/workflows/scriptTests.yml b/.github/workflows/scriptTests.yml index feab0077b..4ffaf8912 100644 --- a/.github/workflows/scriptTests.yml +++ b/.github/workflows/scriptTests.yml @@ -39,6 +39,25 @@ jobs: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: ${{ runner.os }}-go- + - name: Check if package.json build files changed + id: npm-changed-files + uses: tj-actions/changed-files@v39 + with: + files: build/npm/*/package.json + + - name: Test install npm - v2 + working-directory: build/npm/v2 + run: | + npm install + bin/jfrog${{ matrix.suite.osSuffix }} --version + if: steps.npm-changed-files.outputs.any_changed == 'false' + + - name: Test install npm - v2-jf + working-directory: build/npm/v2-jf + run: | + npm install + bin/jf${{ matrix.suite.osSuffix }} --version + if: steps.npm-changed-files.outputs.any_changed == 'false' - name: Test install CLI - jf run: sh build/installcli/jf.sh && jf --version @@ -63,24 +82,4 @@ jobs: build/build.bat ./jf${{ matrix.suite.osSuffix }} --version if: ${{ matrix.suite.os == 'windows' }} - - - name: Check if package.json build files changed - id: npm-changed-files - uses: tj-actions/changed-files@v39 - with: - files: build/npm/*/package.json - - - name: Test install npm - v2 - working-directory: build/npm/v2 - run: | - npm install - bin/jfrog${{ matrix.suite.osSuffix }} --version - if: steps.npm-changed-files.outputs.any_changed == 'false' - - - name: Test install npm - v2-jf - working-directory: build/npm/v2-jf - run: | - npm install - bin/jf${{ matrix.suite.osSuffix }} --version - if: steps.npm-changed-files.outputs.any_changed == 'false' From f5bca0e0ab84da7babb923b836e8ed77c822ce31 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 15:42:08 +0300 Subject: [PATCH 05/21] fix latest build Signed-off-by: Michael Sverdlov --- .github/workflows/scriptTests.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scriptTests.yml b/.github/workflows/scriptTests.yml index 4ffaf8912..c282b3f26 100644 --- a/.github/workflows/scriptTests.yml +++ b/.github/workflows/scriptTests.yml @@ -56,11 +56,13 @@ jobs: working-directory: build/npm/v2-jf run: | npm install - bin/jf${{ matrix.suite.osSuffix }} --version + bin/jf --version if: steps.npm-changed-files.outputs.any_changed == 'false' - name: Test install CLI - jf - run: sh build/installcli/jf.sh && jf --version + run: | + sh build/installcli/jf.sh + jf --version - name: Test install CLI - jfrog run: sh build/installcli/jfrog.sh && jfrog --version From c26d9b13a0d998b8efe664a553a3154832de8fee Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 15:51:51 +0300 Subject: [PATCH 06/21] fix latest build Signed-off-by: Michael Sverdlov --- .github/workflows/scriptTests.yml | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/scriptTests.yml b/.github/workflows/scriptTests.yml index c282b3f26..b58ab12b1 100644 --- a/.github/workflows/scriptTests.yml +++ b/.github/workflows/scriptTests.yml @@ -39,6 +39,9 @@ jobs: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: ${{ runner.os }}-go- + + + - name: Check if package.json build files changed id: npm-changed-files uses: tj-actions/changed-files@v39 @@ -48,30 +51,40 @@ jobs: - name: Test install npm - v2 working-directory: build/npm/v2 run: | - npm install - bin/jfrog${{ matrix.suite.osSuffix }} --version + npm install --gq + jfrog --version + npm uninstall -gq jfrog-cli-v2 if: steps.npm-changed-files.outputs.any_changed == 'false' - name: Test install npm - v2-jf working-directory: build/npm/v2-jf run: | - npm install - bin/jf --version + npm install --gq + jf --version + npm uninstall -gq jfrog-cli-v2-jf if: steps.npm-changed-files.outputs.any_changed == 'false' + + - name: Test install CLI - jf run: | sh build/installcli/jf.sh jf --version - name: Test install CLI - jfrog - run: sh build/installcli/jfrog.sh && jfrog --version + run: | + sh build/installcli/jfrog.sh + jfrog --version - name: Test get CLI - jf - run: sh build/getcli/jf.sh && ./jf --version + run: | + sh build/getcli/jf.sh + ./jf --version - name: Test get CLI - jfrog - run: sh build/getcli/jfrog.sh && ./jfrog --version + run: | + sh build/getcli/jfrog.sh + ./jfrog --version - name: Test Build CLI - sh run: | From 97bca4f713142dd2d6153996fa539c16d0e2f28a Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 15:57:51 +0300 Subject: [PATCH 07/21] fix latest build Signed-off-by: Michael Sverdlov --- build/npm/v2-jf/package-lock.json | 1 - build/npm/v2/package-lock.json | 1 - 2 files changed, 2 deletions(-) diff --git a/build/npm/v2-jf/package-lock.json b/build/npm/v2-jf/package-lock.json index e3f6cfd3c..e108bcd28 100644 --- a/build/npm/v2-jf/package-lock.json +++ b/build/npm/v2-jf/package-lock.json @@ -2,5 +2,4 @@ "name": "jfrog-cli-v2-jf", "version": "2.49.2", "lockfileVersion": 2, - "requires": true } diff --git a/build/npm/v2/package-lock.json b/build/npm/v2/package-lock.json index f06edeb41..f7ba33a94 100644 --- a/build/npm/v2/package-lock.json +++ b/build/npm/v2/package-lock.json @@ -2,5 +2,4 @@ "name": "jfrog-cli-v2", "version": "2.49.2", "lockfileVersion": 2, - "requires": true } From a94e421f4b074ee54ed81a5ca6d671a090247c48 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 15:57:58 +0300 Subject: [PATCH 08/21] fix latest build Signed-off-by: Michael Sverdlov --- .github/workflows/scriptTests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scriptTests.yml b/.github/workflows/scriptTests.yml index b58ab12b1..4ba16ba46 100644 --- a/.github/workflows/scriptTests.yml +++ b/.github/workflows/scriptTests.yml @@ -51,7 +51,7 @@ jobs: - name: Test install npm - v2 working-directory: build/npm/v2 run: | - npm install --gq + npm install -gq jfrog --version npm uninstall -gq jfrog-cli-v2 if: steps.npm-changed-files.outputs.any_changed == 'false' @@ -59,7 +59,7 @@ jobs: - name: Test install npm - v2-jf working-directory: build/npm/v2-jf run: | - npm install --gq + npm install -gq jf --version npm uninstall -gq jfrog-cli-v2-jf if: steps.npm-changed-files.outputs.any_changed == 'false' From 72890cee2c3f341a33abf26b18fa1f8e34c0e57f Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 16:04:22 +0300 Subject: [PATCH 09/21] fix latest build Signed-off-by: Michael Sverdlov --- build/npm/v2/init.js | 168 +++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 96 deletions(-) diff --git a/build/npm/v2/init.js b/build/npm/v2/init.js index cf676168a..a07ace35b 100644 --- a/build/npm/v2/init.js +++ b/build/npm/v2/init.js @@ -1,91 +1,70 @@ validateNpmVersion(); -const {get} = require("https"); -const {request} = require("http"); -const {URL} = require("url"); -const {createWriteStream, chmodSync} = require("fs"); -const packageJson = require("./package.json"); -const fileName = getFileName(); -const filePath = "bin/" + fileName; -const version = packageJson.version; -const pkgName = "jfrog-cli-" + getArchitecture(); +var https = require('https'); +var http = require('http'); +var url = require('url'); +var fs = require('fs'); +var packageJson = require('./package.json'); +var fileName = getFileName(); +var filePath = "bin/" + fileName; +var version = packageJson.version; +var pkgName = "jfrog-cli-" + getArchitecture(); downloadCli(); function validateNpmVersion() { if (!isValidNpmVersion()) { - throw new Error( - "JFrog CLI can be installed using npm version 5.0.0 or above." - ); + throw new Error("JFrog CLI can be installed using npm version 5.0.0 or above."); } } function downloadWithProxy(myUrl) { - const proxyParts = new URL(process.env.https_proxy); - const myUrlParts = new URL(myUrl); + var proxyparts = url.parse(process.env.https_proxy); + var myUrlParts = url.parse(myUrl); - request({ - host: proxyParts.hostname, - port: proxyParts.port, - method: "CONNECT", - path: myUrlParts.hostname + ":443", - }) - .on("connect", function (res, socket, head) { - get( - { - host: myUrlParts.hostname, - socket: socket, - path: myUrlParts.path, - agent: false, - }, - function (res) { - if (res.statusCode === 301 || res.statusCode === 302) { - downloadWithProxy(res.headers.location); - } else if (res.statusCode === 200) { - writeToFile(res); - } else { - console.log( - "Unexpected status code " + - res.statusCode + - " during JFrog CLI download" - ); - } - } - ).on("error", function (err) { - console.error(err); - }); - }) - .end(); + http.request({ + host: proxyparts.hostname, + port: proxyparts.port, + method: 'CONNECT', + path: myUrlParts.hostname + ':443' + }).on('connect', function (res, socket, head) { + https.get({ + host: myUrlParts.hostname, + socket: socket, + path: myUrlParts.path, + agent: false + }, function (res) { + if (res.statusCode == 301 || res.statusCode == 302) { + downloadWithProxy(res.headers.location); + } else if (res.statusCode == 200) { + writeToFile(res); + } else { + console.log('Unexpected status code ' + res.statusCode + ' during JFrog CLI download'); + } + }).on('error', function (err) { + console.error(err); + }); + }).end(); } function download(url) { - get(url, function (res) { - if (res.statusCode === 301 || res.statusCode === 302) { + https.get(url, function (res) { + if (res.statusCode == 301 || res.statusCode == 302) { download(res.headers.location); - } else if (res.statusCode === 200) { + } else if (res.statusCode == 200) { writeToFile(res); } else { - console.log( - "Unexpected status code " + - res.statusCode + - " during JFrog CLI download" - ); + console.log('Unexpected status code ' + res.statusCode + ' during JFrog CLI download'); } - }).on("error", function (err) { + }).on('error', function (err) { console.error(err); }); } function downloadCli() { console.log("Downloading JFrog CLI " + version); - const startUrl = - "https://releases.jfrog.io/artifactory/jfrog-cli/v2/" + - version + - "/" + - pkgName + - "/" + - fileName; - // We detect outbound proxy by looking at the environment variable + var startUrl = 'https://releases.jfrog.io/artifactory/jfrog-cli/v2/' + version + '/' + pkgName + '/' + fileName; + // We detect outbount proxy by looking at the environment variable if (process.env.https_proxy && process.env.https_proxy.length > 0) { downloadWithProxy(startUrl); } else { @@ -94,63 +73,60 @@ function downloadCli() { } function isValidNpmVersion() { - const child_process = require("child_process"); - const npmVersionCmdOut = child_process.execSync("npm version -json"); - const npmVersion = JSON.parse(npmVersionCmdOut).npm; + var child_process = require('child_process'); + var npmVersionCmdOut = child_process.execSync("npm version -json"); + var npmVersion = JSON.parse(npmVersionCmdOut).npm; // Supported since version 5.0.0 return parseInt(npmVersion.charAt(0)) > 4; } function writeToFile(response) { - const file = createWriteStream(filePath); - response - .on("data", function (chunk) { - file.write(chunk); - }) - .on("end", function () { - file.end(); - if (!process.platform.startsWith("win")) { - chmodSync(filePath, 755); - } - }) - .on("error", function (err) { - console.error(err); + var file = fs.createWriteStream(filePath); + response.on('data', function (chunk) { + file.write(chunk); + }).on('end', function () { + file.end(); + if (!process.platform.startsWith("win")) { + fs.chmodSync(filePath, 0555); + } + }).on('error', function (err) { + console.error(err); }); } function getArchitecture() { const platform = process.platform; - if (platform.startsWith("win")) { + if (platform.startsWith('win')) { // Windows architecture: - return "windows-amd64"; + return 'windows-amd64'; } const arch = process.arch; - if (platform.includes("darwin")) { + if (platform.includes('darwin')) { // macOS architecture: - return arch === "arm64" ? "mac-arm64" : "mac-386"; + return arch === 'arm64' ? 'mac-arm64' : 'mac-386'; } // linux architecture: switch (arch) { - case "x64": - return "linux-amd64"; - case "arm64": - return "linux-arm64"; - case "arm": - return "linux-arm"; - case "s390x": - return "linux-s390x"; - case "ppc64": - return "linux-ppc64"; + case 'x64': + return 'linux-amd64'; + case 'arm64': + return 'linux-arm64'; + case 'arm': + return 'linux-arm'; + case 's390x': + return 'linux-s390x'; + case 'ppc64': + return 'linux-ppc64'; default: - return "linux-386"; + return 'linux-386'; } } function getFileName() { - let executable = "jfrog"; + var executable = "jfrog"; if (process.platform.startsWith("win")) { executable += ".exe"; } return executable; -} +} \ No newline at end of file From d72b9891b50729b78dabbb329a35100a9bcf3676 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 16:12:09 +0300 Subject: [PATCH 10/21] fix latest build Signed-off-by: Michael Sverdlov --- build/npm/v2-jf/package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/npm/v2-jf/package-lock.json b/build/npm/v2-jf/package-lock.json index e108bcd28..dc1f2b5ee 100644 --- a/build/npm/v2-jf/package-lock.json +++ b/build/npm/v2-jf/package-lock.json @@ -1,5 +1,5 @@ { "name": "jfrog-cli-v2-jf", "version": "2.49.2", - "lockfileVersion": 2, + "lockfileVersion": 1, } From 8f26863dd9a5fda78eb7b02dfb3a45d153899795 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 16:28:51 +0300 Subject: [PATCH 11/21] fix latest build Signed-off-by: Michael Sverdlov --- .github/workflows/scriptTests.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scriptTests.yml b/.github/workflows/scriptTests.yml index 4ba16ba46..6911c343c 100644 --- a/.github/workflows/scriptTests.yml +++ b/.github/workflows/scriptTests.yml @@ -51,7 +51,8 @@ jobs: - name: Test install npm - v2 working-directory: build/npm/v2 run: | - npm install -gq + npm install -g + ./bin/jfrog.exe --version jfrog --version npm uninstall -gq jfrog-cli-v2 if: steps.npm-changed-files.outputs.any_changed == 'false' @@ -59,7 +60,8 @@ jobs: - name: Test install npm - v2-jf working-directory: build/npm/v2-jf run: | - npm install -gq + npm install -g + ./bin/jf.exe --version jf --version npm uninstall -gq jfrog-cli-v2-jf if: steps.npm-changed-files.outputs.any_changed == 'false' From 1b1383077a045ade49356a6a4df8afab7ba002b1 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 16:37:27 +0300 Subject: [PATCH 12/21] fix latest build Signed-off-by: Michael Sverdlov --- build/npm/v2/package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/npm/v2/package-lock.json b/build/npm/v2/package-lock.json index f7ba33a94..11ea6d8f7 100644 --- a/build/npm/v2/package-lock.json +++ b/build/npm/v2/package-lock.json @@ -1,5 +1,5 @@ { "name": "jfrog-cli-v2", "version": "2.49.2", - "lockfileVersion": 2, + "lockfileVersion": 1, } From 65ef2ec785f875566255b4669dfdf9a3f3d2e25a Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 17:30:01 +0300 Subject: [PATCH 13/21] fix latest build Signed-off-by: Michael Sverdlov --- .gitignore | 2 -- build/npm/v2-jf/bin/{_ => jf} | 0 build/npm/v2/bin/{_ => jfrog} | 0 3 files changed, 2 deletions(-) rename build/npm/v2-jf/bin/{_ => jf} (100%) rename build/npm/v2/bin/{_ => jfrog} (100%) diff --git a/.gitignore b/.gitignore index dad3f8350..f37d74e14 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,7 @@ tmp out # JFrog executable -jf jf.exe -jfrog jfrog.exe # Vim diff --git a/build/npm/v2-jf/bin/_ b/build/npm/v2-jf/bin/jf similarity index 100% rename from build/npm/v2-jf/bin/_ rename to build/npm/v2-jf/bin/jf diff --git a/build/npm/v2/bin/_ b/build/npm/v2/bin/jfrog similarity index 100% rename from build/npm/v2/bin/_ rename to build/npm/v2/bin/jfrog From 120d5118998061e2d8e75f4976556fef1a0356ba Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 17:40:00 +0300 Subject: [PATCH 14/21] fix latest build Signed-off-by: Michael Sverdlov --- build/npm/v2-jf/init.js | 6 +- build/npm/v2-jf/package-lock.json | 2 +- build/npm/v2/bin/jfrog | 0 build/npm/v2/init.js | 168 +++++++++++++++++------------- build/npm/v2/package-lock.json | 2 +- 5 files changed, 101 insertions(+), 77 deletions(-) mode change 100644 => 100755 build/npm/v2/bin/jfrog diff --git a/build/npm/v2-jf/init.js b/build/npm/v2-jf/init.js index fcfa5405f..7f939af59 100644 --- a/build/npm/v2-jf/init.js +++ b/build/npm/v2-jf/init.js @@ -30,7 +30,7 @@ function downloadWithProxy(myUrl) { method: "CONNECT", path: myUrlParts.hostname + ":443", }) - .on("connect", function (res, socket, head) { + .on("connect", function (res, socket, _) { get( { host: myUrlParts.hostname, @@ -115,7 +115,7 @@ function writeToFile(response) { }) .on("error", function (err) { console.error(err); - }); + }); } function getArchitecture() { @@ -153,4 +153,4 @@ function getFileName() { executable += ".exe"; } return executable; -} +} \ No newline at end of file diff --git a/build/npm/v2-jf/package-lock.json b/build/npm/v2-jf/package-lock.json index dc1f2b5ee..e108bcd28 100644 --- a/build/npm/v2-jf/package-lock.json +++ b/build/npm/v2-jf/package-lock.json @@ -1,5 +1,5 @@ { "name": "jfrog-cli-v2-jf", "version": "2.49.2", - "lockfileVersion": 1, + "lockfileVersion": 2, } diff --git a/build/npm/v2/bin/jfrog b/build/npm/v2/bin/jfrog old mode 100644 new mode 100755 diff --git a/build/npm/v2/init.js b/build/npm/v2/init.js index a07ace35b..12dbb34bf 100644 --- a/build/npm/v2/init.js +++ b/build/npm/v2/init.js @@ -1,70 +1,91 @@ validateNpmVersion(); -var https = require('https'); -var http = require('http'); -var url = require('url'); -var fs = require('fs'); -var packageJson = require('./package.json'); -var fileName = getFileName(); -var filePath = "bin/" + fileName; -var version = packageJson.version; -var pkgName = "jfrog-cli-" + getArchitecture(); +const {get} = require("https"); +const {request} = require("http"); +const {URL} = require("url"); +const {createWriteStream, chmodSync} = require("fs"); +const packageJson = require("./package.json"); +const fileName = getFileName(); +const filePath = "bin/" + fileName; +const version = packageJson.version; +const pkgName = "jfrog-cli-" + getArchitecture(); downloadCli(); function validateNpmVersion() { if (!isValidNpmVersion()) { - throw new Error("JFrog CLI can be installed using npm version 5.0.0 or above."); + throw new Error( + "JFrog CLI can be installed using npm version 5.0.0 or above." + ); } } function downloadWithProxy(myUrl) { - var proxyparts = url.parse(process.env.https_proxy); - var myUrlParts = url.parse(myUrl); + const proxyParts = new URL(process.env.https_proxy); + const myUrlParts = new URL(myUrl); - http.request({ - host: proxyparts.hostname, - port: proxyparts.port, - method: 'CONNECT', - path: myUrlParts.hostname + ':443' - }).on('connect', function (res, socket, head) { - https.get({ - host: myUrlParts.hostname, - socket: socket, - path: myUrlParts.path, - agent: false - }, function (res) { - if (res.statusCode == 301 || res.statusCode == 302) { - downloadWithProxy(res.headers.location); - } else if (res.statusCode == 200) { - writeToFile(res); - } else { - console.log('Unexpected status code ' + res.statusCode + ' during JFrog CLI download'); - } - }).on('error', function (err) { - console.error(err); - }); - }).end(); + request({ + host: proxyParts.hostname, + port: proxyParts.port, + method: "CONNECT", + path: myUrlParts.hostname + ":443", + }) + .on("connect", function (res, socket, _) { + get( + { + host: myUrlParts.hostname, + socket: socket, + path: myUrlParts.path, + agent: false, + }, + function (res) { + if (res.statusCode === 301 || res.statusCode === 302) { + downloadWithProxy(res.headers.location); + } else if (res.statusCode === 200) { + writeToFile(res); + } else { + console.log( + "Unexpected status code " + + res.statusCode + + " during JFrog CLI download" + ); + } + } + ).on("error", function (err) { + console.error(err); + }); + }) + .end(); } function download(url) { - https.get(url, function (res) { - if (res.statusCode == 301 || res.statusCode == 302) { + get(url, function (res) { + if (res.statusCode === 301 || res.statusCode === 302) { download(res.headers.location); - } else if (res.statusCode == 200) { + } else if (res.statusCode === 200) { writeToFile(res); } else { - console.log('Unexpected status code ' + res.statusCode + ' during JFrog CLI download'); + console.log( + "Unexpected status code " + + res.statusCode + + " during JFrog CLI download" + ); } - }).on('error', function (err) { + }).on("error", function (err) { console.error(err); }); } function downloadCli() { console.log("Downloading JFrog CLI " + version); - var startUrl = 'https://releases.jfrog.io/artifactory/jfrog-cli/v2/' + version + '/' + pkgName + '/' + fileName; - // We detect outbount proxy by looking at the environment variable + const startUrl = + "https://releases.jfrog.io/artifactory/jfrog-cli/v2/" + + version + + "/" + + pkgName + + "/" + + fileName; + // We detect outbound proxy by looking at the environment variable if (process.env.https_proxy && process.env.https_proxy.length > 0) { downloadWithProxy(startUrl); } else { @@ -73,58 +94,61 @@ function downloadCli() { } function isValidNpmVersion() { - var child_process = require('child_process'); - var npmVersionCmdOut = child_process.execSync("npm version -json"); - var npmVersion = JSON.parse(npmVersionCmdOut).npm; + const child_process = require("child_process"); + const npmVersionCmdOut = child_process.execSync("npm version -json"); + const npmVersion = JSON.parse(npmVersionCmdOut).npm; // Supported since version 5.0.0 return parseInt(npmVersion.charAt(0)) > 4; } function writeToFile(response) { - var file = fs.createWriteStream(filePath); - response.on('data', function (chunk) { - file.write(chunk); - }).on('end', function () { - file.end(); - if (!process.platform.startsWith("win")) { - fs.chmodSync(filePath, 0555); - } - }).on('error', function (err) { - console.error(err); - }); + const file = createWriteStream(filePath); + response + .on("data", function (chunk) { + file.write(chunk); + }) + .on("end", function () { + file.end(); + if (!process.platform.startsWith("win")) { + chmodSync(filePath, 755); + } + }) + .on("error", function (err) { + console.error(err); + }); } function getArchitecture() { const platform = process.platform; - if (platform.startsWith('win')) { + if (platform.startsWith("win")) { // Windows architecture: - return 'windows-amd64'; + return "windows-amd64"; } const arch = process.arch; - if (platform.includes('darwin')) { + if (platform.includes("darwin")) { // macOS architecture: - return arch === 'arm64' ? 'mac-arm64' : 'mac-386'; + return arch === "arm64" ? "mac-arm64" : "mac-386"; } // linux architecture: switch (arch) { - case 'x64': - return 'linux-amd64'; - case 'arm64': - return 'linux-arm64'; - case 'arm': - return 'linux-arm'; - case 's390x': - return 'linux-s390x'; - case 'ppc64': - return 'linux-ppc64'; + case "x64": + return "linux-amd64"; + case "arm64": + return "linux-arm64"; + case "arm": + return "linux-arm"; + case "s390x": + return "linux-s390x"; + case "ppc64": + return "linux-ppc64"; default: - return 'linux-386'; + return "linux-386"; } } function getFileName() { - var executable = "jfrog"; + let executable = "jfrog"; if (process.platform.startsWith("win")) { executable += ".exe"; } diff --git a/build/npm/v2/package-lock.json b/build/npm/v2/package-lock.json index 11ea6d8f7..f7ba33a94 100644 --- a/build/npm/v2/package-lock.json +++ b/build/npm/v2/package-lock.json @@ -1,5 +1,5 @@ { "name": "jfrog-cli-v2", "version": "2.49.2", - "lockfileVersion": 1, + "lockfileVersion": 2, } From 20171ebb0f14c828b932f57baad4ae0a52ca1a97 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 18:01:30 +0300 Subject: [PATCH 15/21] fix latest build Signed-off-by: Michael Sverdlov --- .github/workflows/scriptTests.yml | 14 ++------------ build/npm/v2-jf/bin/jf | 0 build/npm/v2/init.js | 2 +- 3 files changed, 3 insertions(+), 13 deletions(-) mode change 100644 => 100755 build/npm/v2-jf/bin/jf diff --git a/.github/workflows/scriptTests.yml b/.github/workflows/scriptTests.yml index 6911c343c..f2b5770a7 100644 --- a/.github/workflows/scriptTests.yml +++ b/.github/workflows/scriptTests.yml @@ -40,21 +40,13 @@ jobs: key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: ${{ runner.os }}-go- - - - - name: Check if package.json build files changed - id: npm-changed-files - uses: tj-actions/changed-files@v39 - with: - files: build/npm/*/package.json - - name: Test install npm - v2 working-directory: build/npm/v2 run: | npm install -g ./bin/jfrog.exe --version jfrog --version - npm uninstall -gq jfrog-cli-v2 + npm uninstall -g jfrog-cli-v2 if: steps.npm-changed-files.outputs.any_changed == 'false' - name: Test install npm - v2-jf @@ -63,11 +55,9 @@ jobs: npm install -g ./bin/jf.exe --version jf --version - npm uninstall -gq jfrog-cli-v2-jf + npm uninstall -g jfrog-cli-v2-jf if: steps.npm-changed-files.outputs.any_changed == 'false' - - - name: Test install CLI - jf run: | sh build/installcli/jf.sh diff --git a/build/npm/v2-jf/bin/jf b/build/npm/v2-jf/bin/jf old mode 100644 new mode 100755 diff --git a/build/npm/v2/init.js b/build/npm/v2/init.js index 12dbb34bf..b94ea0c0e 100644 --- a/build/npm/v2/init.js +++ b/build/npm/v2/init.js @@ -110,7 +110,7 @@ function writeToFile(response) { .on("end", function () { file.end(); if (!process.platform.startsWith("win")) { - chmodSync(filePath, 755); + chmodSync(filePath, 0o555); } }) .on("error", function (err) { From edc0f3f328adc1a55cc8fda19fb3d76ce47ed149 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 18:06:24 +0300 Subject: [PATCH 16/21] fix latest build Signed-off-by: Michael Sverdlov --- .github/workflows/scriptTests.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/scriptTests.yml b/.github/workflows/scriptTests.yml index f2b5770a7..2a300e27c 100644 --- a/.github/workflows/scriptTests.yml +++ b/.github/workflows/scriptTests.yml @@ -44,19 +44,17 @@ jobs: working-directory: build/npm/v2 run: | npm install -g - ./bin/jfrog.exe --version + ./bin/jfrog${{ matrix.suite.osSuffix }} --version jfrog --version npm uninstall -g jfrog-cli-v2 - if: steps.npm-changed-files.outputs.any_changed == 'false' - name: Test install npm - v2-jf working-directory: build/npm/v2-jf run: | npm install -g - ./bin/jf.exe --version + ./bin/jf${{ matrix.suite.osSuffix }} --version jf --version npm uninstall -g jfrog-cli-v2-jf - if: steps.npm-changed-files.outputs.any_changed == 'false' - name: Test install CLI - jf run: | From 7912ec5ba470d5ad2b7ee4f43ff62edc0658f10d Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 18:22:16 +0300 Subject: [PATCH 17/21] fix latest build Signed-off-by: Michael Sverdlov --- .github/workflows/scriptTests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scriptTests.yml b/.github/workflows/scriptTests.yml index 2a300e27c..8d17e24cd 100644 --- a/.github/workflows/scriptTests.yml +++ b/.github/workflows/scriptTests.yml @@ -31,7 +31,7 @@ jobs: - name: Checkout code uses: actions/checkout@v3 with: - ref: ${{ github.event.pull_request.head.sha }} + ref: v2.48.0 - name: Go Cache uses: actions/cache@v3 From 5f103791cea66e1e066022ffe102b65abf755ab7 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 18:32:23 +0300 Subject: [PATCH 18/21] fix latest build Signed-off-by: Michael Sverdlov --- .github/workflows/scriptTests.yml | 31 ++++++++++++++----------------- .gitignore | 2 ++ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/scriptTests.yml b/.github/workflows/scriptTests.yml index 8d17e24cd..46c842d98 100644 --- a/.github/workflows/scriptTests.yml +++ b/.github/workflows/scriptTests.yml @@ -40,22 +40,6 @@ jobs: key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: ${{ runner.os }}-go- - - name: Test install npm - v2 - working-directory: build/npm/v2 - run: | - npm install -g - ./bin/jfrog${{ matrix.suite.osSuffix }} --version - jfrog --version - npm uninstall -g jfrog-cli-v2 - - - name: Test install npm - v2-jf - working-directory: build/npm/v2-jf - run: | - npm install -g - ./bin/jf${{ matrix.suite.osSuffix }} --version - jf --version - npm uninstall -g jfrog-cli-v2-jf - - name: Test install CLI - jf run: | sh build/installcli/jf.sh @@ -87,4 +71,17 @@ jobs: build/build.bat ./jf${{ matrix.suite.osSuffix }} --version if: ${{ matrix.suite.os == 'windows' }} - + + - name: Test install npm - v2 + working-directory: build/npm/v2 + run: | + npm install -g + ./bin/jfrog${{ matrix.suite.osSuffix }} --version + npm uninstall -g jfrog-cli-v2 + + - name: Test install npm - v2-jf + working-directory: build/npm/v2-jf + run: | + npm install -g + ./bin/jf${{ matrix.suite.osSuffix }} --version + npm uninstall -g jfrog-cli-v2-jf diff --git a/.gitignore b/.gitignore index f37d74e14..dad3f8350 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,9 @@ tmp out # JFrog executable +jf jf.exe +jfrog jfrog.exe # Vim From 2be4af96e9b5eb6abb0c094ac73bc92a8e6f7bbe Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 18:33:34 +0300 Subject: [PATCH 19/21] fix latest build Signed-off-by: Michael Sverdlov --- .github/workflows/scriptTests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scriptTests.yml b/.github/workflows/scriptTests.yml index 46c842d98..b66b35689 100644 --- a/.github/workflows/scriptTests.yml +++ b/.github/workflows/scriptTests.yml @@ -31,7 +31,7 @@ jobs: - name: Checkout code uses: actions/checkout@v3 with: - ref: v2.48.0 + ref: ${{ github.event.pull_request.head.sha }} - name: Go Cache uses: actions/cache@v3 From 65f3c1ac90dcdbad7f5747a75d211060b2ead3cb Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 18:35:47 +0300 Subject: [PATCH 20/21] fix latest build Signed-off-by: Michael Sverdlov --- .github/workflows/scriptTests.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/scriptTests.yml b/.github/workflows/scriptTests.yml index b66b35689..5dc361d8e 100644 --- a/.github/workflows/scriptTests.yml +++ b/.github/workflows/scriptTests.yml @@ -75,13 +75,11 @@ jobs: - name: Test install npm - v2 working-directory: build/npm/v2 run: | - npm install -g + npm install ./bin/jfrog${{ matrix.suite.osSuffix }} --version - npm uninstall -g jfrog-cli-v2 - name: Test install npm - v2-jf working-directory: build/npm/v2-jf run: | - npm install -g - ./bin/jf${{ matrix.suite.osSuffix }} --version - npm uninstall -g jfrog-cli-v2-jf + npm install + ./bin/jf${{ matrix.suite.osSuffix }} --version From 0c74c8c03700f0f1af4f5b275ec0fee2f09b52a8 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 5 Oct 2023 18:38:49 +0300 Subject: [PATCH 21/21] fix latest build Signed-off-by: Michael Sverdlov --- build/npm/v2-jf/init.js | 2 +- build/npm/v2/init.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/npm/v2-jf/init.js b/build/npm/v2-jf/init.js index 7f939af59..4f79dfa4b 100644 --- a/build/npm/v2-jf/init.js +++ b/build/npm/v2-jf/init.js @@ -110,7 +110,7 @@ function writeToFile(response) { .on("end", function () { file.end(); if (!process.platform.startsWith("win")) { - chmodSync(filePath, 755); + chmodSync(filePath, '755'); } }) .on("error", function (err) { diff --git a/build/npm/v2/init.js b/build/npm/v2/init.js index b94ea0c0e..1f919b3da 100644 --- a/build/npm/v2/init.js +++ b/build/npm/v2/init.js @@ -110,7 +110,7 @@ function writeToFile(response) { .on("end", function () { file.end(); if (!process.platform.startsWith("win")) { - chmodSync(filePath, 0o555); + chmodSync(filePath, '755'); } }) .on("error", function (err) {