diff --git a/.github/workflows/npm.yaml b/.github/workflows/npm.yaml index 27f73fc31e..b2fa32c3c0 100644 --- a/.github/workflows/npm.yaml +++ b/.github/workflows/npm.yaml @@ -19,6 +19,7 @@ jobs: registry-url: https://registry.npmjs.org/ - run: | npm install -g + export RELEASE_VERSION=$(node index.js get-latest) npm run prepare devspace --version npm uninstall -g devspace @@ -41,6 +42,8 @@ jobs: registry-url: https://registry.npmjs.org/ - run: | npm install -g + $releaseVersion = node index.js get-latest + $env:RELEASE_VERSION = $releaseVersion npm run prepare devspace --version npm uninstall -g devspace diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9981a63cb0..f9f5ea75d8 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -30,6 +30,10 @@ jobs: with: node-version: 12 registry-url: https://registry.npmjs.org/ + - id: get_version + run: | + RELEASE_VERSION=$(echo $GITHUB_REF | sed -nE 's!refs/tags/!!p') + echo "::set-output name=release_version::$RELEASE_VERSION" - name: Cache node modules uses: actions/cache@v1 with: @@ -39,6 +43,7 @@ jobs: ${{ runner.os }}-node- - name: Build UI env: + VERSION: ${{ steps.get_version.outputs.release_version }} NPM_CONFIG_GLOBALCONFIG: "dist/npm/config/npmrc" NPM_REGISTRY_TOKEN: ${{ secrets.NPM_DEVSPACE_REGISTRY_TOKEN }} CI: "false" @@ -57,6 +62,10 @@ jobs: uses: actions/setup-go@v1 with: go-version: 1.17 + - id: get_version + run: | + RELEASE_VERSION=$(echo $GITHUB_REF | sed -nE 's!refs/tags/!!p') + echo "::set-output name=release_version::$RELEASE_VERSION" - name: install-go-bindata run: go get -u github.com/go-bindata/go-bindata/... env: @@ -72,6 +81,7 @@ jobs: - name: Compile binaries run: ./hack/build-all.bash env: + VERSION: ${{ steps.get_version.outputs.release_version }} GOPATH: /Users/runner/work/devspace/go ENCRYPTION_KEY: ${{ secrets.ENCRYPTION_KEY }} ANALYTICS_TOKEN: ${{ secrets.ANALYTICS_TOKEN }} @@ -92,12 +102,17 @@ jobs: with: node-version: 12 registry-url: https://registry.npmjs.org/ + - id: get_version + run: | + RELEASE_VERSION=$(echo $GITHUB_REF | sed -nE 's!refs/tags/!!p') + echo "::set-output name=release_version::$RELEASE_VERSION" - run: | npm ci export NPM_TAG=$(node index.js get-tag) npm publish --tag $NPM_TAG working-directory: ./dist/npm env: + RELEASE_VERSION: ${{ steps.get_version.outputs.release_version }} NODE_AUTH_TOKEN: ${{ secrets.NPMJS_TOKEN }} publish-next-image: if: github.ref == 'refs/heads/master' @@ -133,4 +148,4 @@ jobs: repository: devspacesh/devspace username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - build_args: RELEASE_VERSION=${{ steps.get_version.outputs.release_version }} + build_args: RELEASE_VERSION=${{ steps.get_version.outputs.release_version }} \ No newline at end of file diff --git a/dist/npm/bin/devspace b/dist/npm/bin/devspace index 01896cc826..0b21f29a4e 100644 --- a/dist/npm/bin/devspace +++ b/dist/npm/bin/devspace @@ -35,6 +35,9 @@ if [ ! -f "$BINARY" ] || [ "$STAT" -lt 10000 ]; then echo "Running: node $BASEDIR/$INDEX_FILE finish-install $BINDIR" /usr/bin/env node "$BASEDIR/$INDEX_FILE" finish-install $BINDIR; + if [ $? -ne 0 ]; then + exit 1 + fi CMD_BIN=$(command -v cmd.exe) diff --git a/dist/npm/index.js b/dist/npm/index.js index aa854bee00..fd1b3f1b69 100644 --- a/dist/npm/index.js +++ b/dist/npm/index.js @@ -8,7 +8,7 @@ const inquirer = require('inquirer'); const findProcess = require('find-process'); const downloadPathTemplate = - "https://github.com/loft-sh/devspace/releases/download/v{{version}}/devspace-{{platform}}-{{arch}}"; + "https://github.com/loft-sh/devspace/releases/download/{{version}}/devspace-{{platform}}-{{arch}}"; const ARCH_MAPPING = { ia32: "386", x64: "amd64", @@ -25,11 +25,11 @@ const PLATFORM_MAPPING = { }; if ( - !(process.platform in PLATFORM_MAPPING) || - !(process.arch in ARCH_MAPPING) + !(process.platform in PLATFORM_MAPPING) || + !(process.arch in ARCH_MAPPING) ) { console.error( - "Installation is not supported for this platform (" + + "Installation is not supported for this platform (" + process.platform + ") or architecture (" + process.arch + @@ -66,13 +66,13 @@ const getLatestVersion = function(callback, includePreReleases) { const releasesURL = "https://github.com/loft-sh/devspace/releases"; request({ uri: releasesURL, headers: requestHeaders }, function( - err, - res, - releasePage + err, + res, + releasePage ) { if (res.statusCode !== 200) { console.error( - "Error requesting URL " + + "Error requesting URL " + releasesURL + " (Status Code: " + res.statusCode + @@ -81,16 +81,16 @@ const getLatestVersion = function(callback, includePreReleases) { console.error(err); process.exit(1); } - let versionRegex = - /^.*?\/loft-sh\/devspace\/releases\/download\/v([^\/-]*)\/devspace-.*$/s; + let versionRegex = + /^.*?\/loft-sh\/devspace\/releases\/download\/([^\/-]*)\/devspace-.*$/s; if (includePreReleases) { - versionRegex = - /^.*?\/loft-sh\/devspace\/releases\/download\/v([^\/]*)\/devspace-.*$/s; + versionRegex = + /^.*?\/loft-sh\/devspace\/releases\/download\/([^\/]*)\/devspace-.*$/s; } - + const latestVersion = releasePage.replace(versionRegex, - "$1" + "$1" ); if (releasePage !== latestVersion && latestVersion) { @@ -103,27 +103,31 @@ const getLatestVersion = function(callback, includePreReleases) { }; if (action === "update-version") { - getLatestVersion(function(latestVersion) { - packageJson.version = latestVersion; + packageJson.version = "" + process.env.RELEASE_VERSION; - fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 4)); + fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 4)); + process.exit(0); + return; +} +if (action === "get-latest") { + getLatestVersion(function(latestVersion) { + process.stdout.write(latestVersion); process.exit(0); - }, true); + }); return; } if (action === "get-tag") { - getLatestVersion(function(latestVersion) { - let tagRegex = /^.*-([a-z]*)(\.)?([0-9]*)?$/i - let tag = "latest" - - if (latestVersion.match(tagRegex)) { - tag = latestVersion.replace(tagRegex, "$1") - } - process.stdout.write(tag); - process.exit(0); - }, true); + let latestVersion = "" + process.env.RELEASE_VERSION; + let tagRegex = /^.*-([a-z]*)(\.)?([0-9]*)?$/i + let tag = "latest" + + if (latestVersion.match(tagRegex)) { + tag = latestVersion.replace(tagRegex, "$1") + } + process.stdout.write(tag); + process.exit(0); return; } @@ -134,15 +138,15 @@ if (action === "get-tag") { */ function rimraf(dir_path) { if (fs.existsSync(dir_path)) { - fs.readdirSync(dir_path).forEach(function(entry) { - let entry_path = path.join(dir_path, entry); - if (fs.lstatSync(entry_path).isDirectory()) { - rimraf(entry_path); - } else { - fs.unlinkSync(entry_path); - } - }); - fs.rmdirSync(dir_path); + fs.readdirSync(dir_path).forEach(function(entry) { + let entry_path = path.join(dir_path, entry); + if (fs.lstatSync(entry_path).isDirectory()) { + rimraf(entry_path); + } else { + fs.unlinkSync(entry_path); + } + }); + fs.rmdirSync(dir_path); } } @@ -175,7 +179,7 @@ let continueProcess = function(askRemoveGlobalFolder) { if (process.argv.length > 3 && fs.existsSync(normalizePath(process.argv[3]))) { globalDir = normalizePath(process.argv[3]); dotBinDir = normalizePath(path.join(globalDir, "..", "..", ".bin")); - + if (fs.existsSync(normalizePath(path.join(dotBinDir, "devspace")))) { globalDir = normalizePath(dotBinDir); } @@ -210,7 +214,7 @@ let continueProcess = function(askRemoveGlobalFolder) { } } } catch(e) {} - + if (globalDir === null) { if (platform === PLATFORM_MAPPING.win32) { console.error("Error finding binary installation directory"); @@ -218,11 +222,11 @@ let continueProcess = function(askRemoveGlobalFolder) { } globalDir = fallbackGlobalDir; } - + try { fs.mkdirSync(globalDir, { recursive: true }); } catch(e) {} - + let binaryPath = path.join(globalDir, binaryName); if (process.argv.length > 3 && fs.existsSync(normalizePath(process.argv[3]))) { let binaryDir = normalizePath(process.argv[3]); @@ -247,14 +251,14 @@ let continueProcess = function(askRemoveGlobalFolder) { fs.unlinkSync(binaryPath.replace(/\.exe$/i, "")); } catch (e) {} } - + // Remove bin/devspace.ps1 file because it can cause issues try { fs.unlinkSync(binaryPath.replace(/\.exe$/i, ".ps1")); } catch (e) {} } } - + if (action === "install") { removeScripts(false); @@ -285,7 +289,7 @@ let continueProcess = function(askRemoveGlobalFolder) { try { fs.unlinkSync(binaryPath.replace(/\.exe$/i, ".cmd")); } catch (e) {} - + removeScripts(true); if (askRemoveGlobalFolder && process.stdout.isTTY) { @@ -299,19 +303,19 @@ let continueProcess = function(askRemoveGlobalFolder) { }; inquirer - .prompt([ - { - type: "list", - name: "checkRemoveGlobalFolder", - message: "Do you want to remove the global DevSpace config folder ~/.devspace?", - choices: ["no", "yes"], - }, - ]) - .then(answers => { - if (answers.checkRemoveGlobalFolder === "yes") { - removeGlobalFolder(); - } - }); + .prompt([ + { + type: "list", + name: "checkRemoveGlobalFolder", + message: "Do you want to remove the global DevSpace config folder ~/.devspace?", + choices: ["no", "yes"], + }, + ]) + .then(answers => { + if (answers.checkRemoveGlobalFolder === "yes") { + removeGlobalFolder(); + } + }); } else { console.warn("DevSpace will not remove the global ~/.devspace folder without asking. This uninstall call is being executed in a non-interactive environment.") } @@ -319,24 +323,24 @@ let continueProcess = function(askRemoveGlobalFolder) { if (action === "finish-install") { cleanPathVar = process.env.PATH.replace(/(^|;)[a-z]:/gi, path.delimiter).replace(/(\\)+/g, '/'); cleanGlobalDir = globalDir.replace(/(^|;)[a-z]:/gi, '').replace(/(\\)+/g, '/').trimRight("/"); - + if (cleanPathVar.split(path.delimiter).indexOf(cleanGlobalDir) === -1 && cleanPathVar.split(path.delimiter).indexOf(cleanGlobalDir + "/") === -1) { console.error("\n\n################################################\nWARNING: npm binary directory NOT in $PATH environment variable: " + globalDir + "\n################################################\n\n"); - + if (globalInstall) { process.exit(4) } } - const showRootError = function() { + const showRootError = function(version) { console.error("\n############################################"); console.error( - "Failed to download DevSpace CLI due to permission issues!\n" + "Failed to download DevSpace CLI due to permission issues!\n" ); console.error("There are two options to fix this:"); - console.error("1. Do not run 'npm install' as root (recommended)"); + console.error("1. Run this command once: 'sudo devspace'"); console.error( - "2. Run this command: npm install --unsafe-perm=true -g devspace" + "2. Run this command: 'sudo npm uninstall -g devspace && npm install --unsafe-perm=true -g devspace@"+version+"'" ); console.error(" You may need to run this command using sudo."); console.error("############################################\n"); @@ -345,9 +349,9 @@ let continueProcess = function(askRemoveGlobalFolder) { const downloadRelease = function(version) { let downloadPath = downloadPathTemplate - .replace("{{version}}", version) - .replace("{{platform}}", platform) - .replace("{{arch}}", arch); + .replace("{{version}}", version) + .replace("{{platform}}", platform) + .replace("{{arch}}", arch); if (platform === PLATFORM_MAPPING.win32) { downloadPath += ".exe"; @@ -356,85 +360,85 @@ let continueProcess = function(askRemoveGlobalFolder) { console.log("Download DevSpace CLI release: " + downloadPath + "\n"); const spinner = new Spinner( - "%s Downloading DevSpace CLI... (this may take a minute)" + "%s Downloading DevSpace CLI... (this may take a minute)" ); spinner.setSpinnerString("|/-\\"); spinner.start(); let writeStream = fs - .createWriteStream(binaryPath + downloadExtension) - .on("error", function(err) { - spinner.stop(true); - console.error("Unable to write stream: " + err) - showRootError(); - }); + .createWriteStream(binaryPath + downloadExtension) + .on("error", function(err) { + spinner.stop(true); + console.error("Unable to write stream: " + err) + showRootError(version); + }); request({ uri: downloadPath, headers: requestHeaders, encoding: null }) - .on("error", function() { - spinner.stop(true); - console.error("Error requesting URL: " + downloadPath); - process.exit(6); - }) - .on("response", function(res) { - if (res.statusCode !== 200) { - writeStream.end(); + .on("error", function() { spinner.stop(true); - - if (res.statusCode === 404) { - console.error("Release version " + version + " not found.\n"); - - getLatestVersion(function(latestVersion) { - if (latestVersion !== version) { - console.log( - "Downloading latest stable release instead. Latest version is: " + - latestVersion + - "\n" - ); - - downloadRelease(latestVersion); - } - }); + console.error("Error requesting URL: " + downloadPath); + process.exit(6); + }) + .on("response", function(res) { + if (res.statusCode !== 200) { + writeStream.end(); + spinner.stop(true); + + if (res.statusCode === 404) { + console.error("Release version " + version + " not found.\n"); + + getLatestVersion(function(latestVersion) { + if (latestVersion !== version) { + console.log( + "Downloading latest stable release instead. Latest version is: " + + latestVersion + + "\n" + ); + + downloadRelease(latestVersion); + } + }); + } else { + console.error( + "Error requesting URL " + + downloadPath + + " (Status Code: " + + res.statusCode + + ")" + ); + console.error(err); + process.exit(7); + } } else { - console.error( - "Error requesting URL " + - downloadPath + - " (Status Code: " + - res.statusCode + - ")" - ); - console.error(err); - process.exit(7); + try { + res.pipe(writeStream); + } catch (e) { + console.error("Unable to write stream: " + e) + showRootError(version); + } } - } else { + }) + .on("end", function() { + writeStream.end(); + spinner.stop(true); + try { - res.pipe(writeStream); + fs.chmodSync(binaryPath + downloadExtension, "0755"); } catch (e) { - console.error("Unable to write stream: " + e) - showRootError(); + console.error("Unable to chmod: " + e) + showRootError(version); } - } - }) - .on("end", function() { - writeStream.end(); - spinner.stop(true); - - try { - fs.chmodSync(binaryPath + downloadExtension, "0755"); - } catch (e) { - console.error("Unable to chmod: " + e) - showRootError(); - } - try { - fs.renameSync(binaryPath + downloadExtension, binaryPath); - } catch (e) { - console.log(e); - console.error("\nRenaming release binary failed. Please copy file manually:\n from: " + binaryPath + downloadExtension + "\n to: " + binaryPath + "\n"); - process.exit(8); - } + try { + fs.renameSync(binaryPath + downloadExtension, binaryPath); + } catch (e) { + console.log(e); + console.error("\nRenaming release binary failed. Please copy file manually:\n from: " + binaryPath + downloadExtension + "\n to: " + binaryPath + "\n"); + process.exit(8); + } - removeScripts(true); - }); + removeScripts(true); + }); }; downloadRelease(version); @@ -444,24 +448,24 @@ let continueProcess = function(askRemoveGlobalFolder) { if (process.ppid > 1) { findProcess('pid', process.ppid) - .then(function (list) { - if (list.length === 1 && list[0].ppid > 1) { - findProcess('pid', list[0].ppid) - .then(function (list) { - if (list.length === 1 && /((npm-cli.js("|')\s+up(date)?)|(yarn.js("|')\s+(global\s+)?upgrade))\s+.*((\/)|(\\)|(\s))devspace((\/)|(\\)|(\s)|$)/.test(list[0].cmd)) { - continueProcess(false); - } else { - continueProcess(true); - } - }, function () { - continueProcess(true); - }) - } else { + .then(function (list) { + if (list.length === 1 && list[0].ppid > 1) { + findProcess('pid', list[0].ppid) + .then(function (list) { + if (list.length === 1 && /((npm-cli.js("|')\s+up(date)?)|(yarn.js("|')\s+(global\s+)?upgrade))\s+.*((\/)|(\\)|(\s))devspace((\/)|(\\)|(\s)|$)/.test(list[0].cmd)) { + continueProcess(false); + } else { + continueProcess(true); + } + }, function () { + continueProcess(true); + }) + } else { + continueProcess(true); + } + }, function () { continueProcess(true); - } - }, function () { - continueProcess(true); - }) + }) } else { continueProcess(true); -} +} \ No newline at end of file diff --git a/hack/build-all.bash b/hack/build-all.bash index d6f79bafec..b550189a52 100755 --- a/hack/build-all.bash +++ b/hack/build-all.bash @@ -13,7 +13,6 @@ export GOFLAGS=-mod=vendor # go mod vendor DEVSPACE_ROOT=$(git rev-parse --show-toplevel) -VERSION=$(git describe --tags $(git rev-list --tags --max-count=1)) COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null) DATE=$(date "+%Y-%m-%d") BUILD_PLATFORM=$(uname -a | awk '{print tolower($1);}') diff --git a/hack/build-ui.bash b/hack/build-ui.bash index c2d7572582..b833c204cf 100755 --- a/hack/build-ui.bash +++ b/hack/build-ui.bash @@ -3,7 +3,6 @@ set -e DEVSPACE_ROOT=$(git rev-parse --show-toplevel) -VERSION=$(git describe --tags $(git rev-list --tags --max-count=1)) # Install dependencies cd ui && npm install && npm run build