From 95a77582bbdeb47e9b20331367892743c8dc9deb Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 4 Dec 2019 00:47:58 -0500 Subject: [PATCH 1/4] Uninstall the default profile on Windows --- lib/main.js | 3 ++- lib/rustup.js | 6 +++++- node_modules/.bin/uuid | 2 +- node_modules/.bin/which | 2 +- src/rustup.ts | 3 +++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index a169eeb..f390ba3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,9 +1,10 @@ "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; diff --git a/lib/rustup.js b/lib/rustup.js index e3d06ee..bb79ace 100644 --- a/lib/rustup.js +++ b/lib/rustup.js @@ -1,9 +1,10 @@ "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; @@ -35,6 +36,9 @@ function install() { // to leverage newer features like "latest latest compatible nightly" yield exec.exec('rustup', ['self', 'update']); yield exec.exec('rustup', ['set', 'profile', 'minimal']); + // Github's default Windows install comes with rustup pre-installed with stable, including + // rust-docs. This removes the default stable install so that it doesn't update rust-docs. + yield exec.exec('rustup', ['toolchain', 'uninstall', 'stable']); } }); } diff --git a/node_modules/.bin/uuid b/node_modules/.bin/uuid index b3e45bc..df26561 120000 --- a/node_modules/.bin/uuid +++ b/node_modules/.bin/uuid @@ -1 +1 @@ -../uuid/bin/uuid \ No newline at end of file +../uuid/bin/uuid diff --git a/node_modules/.bin/which b/node_modules/.bin/which index f62471c..fa2db9f 120000 --- a/node_modules/.bin/which +++ b/node_modules/.bin/which @@ -1 +1 @@ -../which/bin/which \ No newline at end of file +../which/bin/which diff --git a/src/rustup.ts b/src/rustup.ts index 1613512..f94821e 100644 --- a/src/rustup.ts +++ b/src/rustup.ts @@ -20,6 +20,9 @@ export async function install() { await exec.exec('rustup', ['self', 'update']); await exec.exec('rustup', ['set', 'profile', 'minimal']); + // Github's default Windows install comes with rustup pre-installed with stable, including + // rust-docs. This removes the default stable install so that it doesn't update rust-docs. + await exec.exec('rustup', ['toolchain', 'uninstall', 'stable']); } } From 69d806023af15ec737a01c5135fba1dcf9f45bd8 Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 4 Dec 2019 01:01:39 -0500 Subject: [PATCH 2/4] Try something really dirty --- lib/main.js | 3 +-- lib/rustup.js | 40 +++++++++++++++++++++++++++++++++++----- node_modules/.bin/uuid | 2 +- node_modules/.bin/which | 2 +- package-lock.json | 6 +++--- package.json | 2 +- src/rustup.ts | 41 +++++++++++++++++++++++++++++++++++++---- 7 files changed, 79 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index f390ba3..a169eeb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,10 +1,9 @@ "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; diff --git a/lib/rustup.js b/lib/rustup.js index bb79ace..d7d88e5 100644 --- a/lib/rustup.js +++ b/lib/rustup.js @@ -1,10 +1,9 @@ "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; @@ -22,7 +21,9 @@ const toolCache = __importStar(require("@actions/tool-cache")); const path = __importStar(require("path")); const os = __importStar(require("os")); const fs_1 = require("fs"); +const util_1 = require("util"); let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || ''; +const renameAsync = util_1.promisify(fs_1.rename); function install() { return __awaiter(this, void 0, void 0, function* () { // `rustup` is already installed on Linux and Windows platforms @@ -36,9 +37,38 @@ function install() { // to leverage newer features like "latest latest compatible nightly" yield exec.exec('rustup', ['self', 'update']); yield exec.exec('rustup', ['set', 'profile', 'minimal']); - // Github's default Windows install comes with rustup pre-installed with stable, including - // rust-docs. This removes the default stable install so that it doesn't update rust-docs. - yield exec.exec('rustup', ['toolchain', 'uninstall', 'stable']); + if (os.platform() == 'win32') { + let rustDocsInstalled = false; + { + let installedComponents = ''; + const options = { + listeners: { + stdout: (data) => { + installedComponents += data.toString(); + } + } + }; + yield exec.exec('rustup', ['component', 'list'], options); + rustDocsInstalled = installedComponents.match(/rust-docs.+\(installed\)/) != null; + } + if (rustDocsInstalled) { + let cargoPath = ''; + { + const options = { + listeners: { + stdout: (data) => { + cargoPath += data.toString(); + } + } + }; + yield exec.exec('where', ['rustup.exe'], options); + } + let rustupPath = cargoPath.split('\\').slice(0, -3).concat([".rustup"]).join("\\"); + // Github's default Windows install comes with rustup pre-installed with stable, including + // rust-docs. This removes the default stable install so that it doesn't update rust-docs. + yield renameAsync(`${rustupPath}\\toolchains`, `${rustupPath}\\_toolchains`); + } + } } }); } diff --git a/node_modules/.bin/uuid b/node_modules/.bin/uuid index df26561..b3e45bc 120000 --- a/node_modules/.bin/uuid +++ b/node_modules/.bin/uuid @@ -1 +1 @@ -../uuid/bin/uuid +../uuid/bin/uuid \ No newline at end of file diff --git a/node_modules/.bin/which b/node_modules/.bin/which index fa2db9f..f62471c 120000 --- a/node_modules/.bin/which +++ b/node_modules/.bin/which @@ -1 +1 @@ -../which/bin/which +../which/bin/which \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 59e4a7d..ed0f22a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -633,9 +633,9 @@ "dev": true }, "@types/node": { - "version": "12.6.9", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.6.9.tgz", - "integrity": "sha512-+YB9FtyxXGyD54p8rXwWaN1EWEyar5L58GlGWgtH2I9rGmLGBQcw63+0jw+ujqVavNuO47S1ByAjm9zdHMnskw==", + "version": "12.12.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.14.tgz", + "integrity": "sha512-u/SJDyXwuihpwjXy7hOOghagLEV1KdAST6syfnOk6QZAMzZuWZqXy5aYYZbh8Jdpd4escVFP0MvftHNDb9pruA==", "dev": true }, "@types/semver": { diff --git a/package.json b/package.json index 21b06c3..fcbecae 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ }, "devDependencies": { "@types/jest": "^24.0.13", - "@types/node": "^12.0.4", + "@types/node": "^12.12.14", "@types/semver": "^6.0.0", "jest": "^24.8.0", "jest-circus": "^24.7.1", diff --git a/src/rustup.ts b/src/rustup.ts index f94821e..4e74337 100644 --- a/src/rustup.ts +++ b/src/rustup.ts @@ -3,9 +3,11 @@ import * as exec from '@actions/exec'; import * as toolCache from '@actions/tool-cache'; import * as path from 'path'; import * as os from 'os'; -import {chmodSync} from 'fs'; +import {chmodSync, rename} from 'fs'; +import {promisify} from 'util'; let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || ''; +const renameAsync = promisify(rename); export async function install() { // `rustup` is already installed on Linux and Windows platforms @@ -20,9 +22,40 @@ export async function install() { await exec.exec('rustup', ['self', 'update']); await exec.exec('rustup', ['set', 'profile', 'minimal']); - // Github's default Windows install comes with rustup pre-installed with stable, including - // rust-docs. This removes the default stable install so that it doesn't update rust-docs. - await exec.exec('rustup', ['toolchain', 'uninstall', 'stable']); + + if (os.platform() == 'win32') { + let rustDocsInstalled = false; + { + let installedComponents = ''; + const options = { + listeners: { + stdout: (data: Buffer) => { + installedComponents += data.toString(); + } + } + }; + await exec.exec('rustup', ['component', 'list'], options); + rustDocsInstalled = installedComponents.match(/rust-docs.+\(installed\)/) != null; + } + + if (rustDocsInstalled) { + let cargoPath = ''; + { + const options = { + listeners: { + stdout: (data: Buffer) => { + cargoPath += data.toString(); + } + } + }; + await exec.exec('where', ['rustup.exe'], options); + } + let rustupPath = cargoPath.split('\\').slice(0, -3).concat([".rustup"]).join("\\"); + // Github's default Windows install comes with rustup pre-installed with stable, including + // rust-docs. This removes the default stable install so that it doesn't update rust-docs. + await renameAsync(`${rustupPath}\\toolchains`, `${rustupPath}\\_toolchains`); + } + } } } From 468970f930d0dcbddc495d140c68f9c98c7302af Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 4 Dec 2019 02:25:23 -0500 Subject: [PATCH 3/4] Try using environment variables --- lib/rustup.js | 31 +++++++++++++++++-------------- src/rustup.ts | 31 +++++++++++++++++-------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/lib/rustup.js b/lib/rustup.js index d7d88e5..508c38e 100644 --- a/lib/rustup.js +++ b/lib/rustup.js @@ -38,20 +38,22 @@ function install() { yield exec.exec('rustup', ['self', 'update']); yield exec.exec('rustup', ['set', 'profile', 'minimal']); if (os.platform() == 'win32') { - let rustDocsInstalled = false; - { - let installedComponents = ''; - const options = { - listeners: { - stdout: (data) => { - installedComponents += data.toString(); - } - } - }; - yield exec.exec('rustup', ['component', 'list'], options); - rustDocsInstalled = installedComponents.match(/rust-docs.+\(installed\)/) != null; - } - if (rustDocsInstalled) { + let clearedEnvVar = '__SETUP_RUST_ACTION_DEFAULT_INSTALL_CLEARED'; + // let rustDocsInstalled = false; + // { + // let installedComponents = ''; + // const options = { + // listeners: { + // stdout: (data: Buffer) => { + // installedComponents += data.toString(); + // } + // } + // }; + // await exec.exec('rustup', ['component', 'list'], options); + // rustDocsInstalled = installedComponents.match(/rust-docs.+\(installed\)/) != null; + // } + // If the rust-docs component isn't installed, + if (process.env[clearedEnvVar] == null) { let cargoPath = ''; { const options = { @@ -67,6 +69,7 @@ function install() { // Github's default Windows install comes with rustup pre-installed with stable, including // rust-docs. This removes the default stable install so that it doesn't update rust-docs. yield renameAsync(`${rustupPath}\\toolchains`, `${rustupPath}\\_toolchains`); + yield exec.exec('setx', [clearedEnvVar, "1"]); } } } diff --git a/src/rustup.ts b/src/rustup.ts index 4e74337..c44f5a2 100644 --- a/src/rustup.ts +++ b/src/rustup.ts @@ -24,21 +24,23 @@ export async function install() { await exec.exec('rustup', ['set', 'profile', 'minimal']); if (os.platform() == 'win32') { - let rustDocsInstalled = false; - { - let installedComponents = ''; - const options = { - listeners: { - stdout: (data: Buffer) => { - installedComponents += data.toString(); - } - } - }; - await exec.exec('rustup', ['component', 'list'], options); - rustDocsInstalled = installedComponents.match(/rust-docs.+\(installed\)/) != null; - } + let clearedEnvVar = '__SETUP_RUST_ACTION_DEFAULT_INSTALL_CLEARED'; + // let rustDocsInstalled = false; + // { + // let installedComponents = ''; + // const options = { + // listeners: { + // stdout: (data: Buffer) => { + // installedComponents += data.toString(); + // } + // } + // }; + // await exec.exec('rustup', ['component', 'list'], options); + // rustDocsInstalled = installedComponents.match(/rust-docs.+\(installed\)/) != null; + // } - if (rustDocsInstalled) { + // If the rust-docs component isn't installed, + if (process.env[clearedEnvVar] == null) { let cargoPath = ''; { const options = { @@ -54,6 +56,7 @@ export async function install() { // Github's default Windows install comes with rustup pre-installed with stable, including // rust-docs. This removes the default stable install so that it doesn't update rust-docs. await renameAsync(`${rustupPath}\\toolchains`, `${rustupPath}\\_toolchains`); + await exec.exec('setx', [clearedEnvVar, "1"]); } } } From de871ef0a4d772a8f2e0cc5dde065ddf24083d71 Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 4 Dec 2019 02:34:45 -0500 Subject: [PATCH 4/4] Use filesystem to check if operation has been run --- lib/rustup.js | 46 +++++++++++++++------------------------------- src/rustup.ts | 50 +++++++++++++++++--------------------------------- 2 files changed, 32 insertions(+), 64 deletions(-) diff --git a/lib/rustup.js b/lib/rustup.js index 508c38e..243ca64 100644 --- a/lib/rustup.js +++ b/lib/rustup.js @@ -21,9 +21,7 @@ const toolCache = __importStar(require("@actions/tool-cache")); const path = __importStar(require("path")); const os = __importStar(require("os")); const fs_1 = require("fs"); -const util_1 = require("util"); let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || ''; -const renameAsync = util_1.promisify(fs_1.rename); function install() { return __awaiter(this, void 0, void 0, function* () { // `rustup` is already installed on Linux and Windows platforms @@ -38,38 +36,24 @@ function install() { yield exec.exec('rustup', ['self', 'update']); yield exec.exec('rustup', ['set', 'profile', 'minimal']); if (os.platform() == 'win32') { - let clearedEnvVar = '__SETUP_RUST_ACTION_DEFAULT_INSTALL_CLEARED'; - // let rustDocsInstalled = false; - // { - // let installedComponents = ''; - // const options = { - // listeners: { - // stdout: (data: Buffer) => { - // installedComponents += data.toString(); - // } - // } - // }; - // await exec.exec('rustup', ['component', 'list'], options); - // rustDocsInstalled = installedComponents.match(/rust-docs.+\(installed\)/) != null; - // } - // If the rust-docs component isn't installed, - if (process.env[clearedEnvVar] == null) { - let cargoPath = ''; - { - const options = { - listeners: { - stdout: (data) => { - cargoPath += data.toString(); - } + let cargoPath = ''; + { + const options = { + listeners: { + stdout: (data) => { + cargoPath += data.toString(); } - }; - yield exec.exec('where', ['rustup.exe'], options); - } - let rustupPath = cargoPath.split('\\').slice(0, -3).concat([".rustup"]).join("\\"); + } + }; + yield exec.exec('where', ['rustup.exe'], options); + } + let rustupPath = cargoPath.split('\\').slice(0, -3).concat([".rustup"]).join("\\"); + let defaultClearedFilePath = `${rustupPath}\\default_cleared`; + if (!fs_1.existsSync(defaultClearedFilePath)) { // Github's default Windows install comes with rustup pre-installed with stable, including // rust-docs. This removes the default stable install so that it doesn't update rust-docs. - yield renameAsync(`${rustupPath}\\toolchains`, `${rustupPath}\\_toolchains`); - yield exec.exec('setx', [clearedEnvVar, "1"]); + fs_1.renameSync(`${rustupPath}\\toolchains`, `${rustupPath}\\_toolchains`); + fs_1.appendFileSync(defaultClearedFilePath, ''); } } } diff --git a/src/rustup.ts b/src/rustup.ts index c44f5a2..15013f0 100644 --- a/src/rustup.ts +++ b/src/rustup.ts @@ -3,11 +3,9 @@ import * as exec from '@actions/exec'; import * as toolCache from '@actions/tool-cache'; import * as path from 'path'; import * as os from 'os'; -import {chmodSync, rename} from 'fs'; -import {promisify} from 'util'; +import {chmodSync, renameSync, existsSync, appendFileSync} from 'fs'; let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || ''; -const renameAsync = promisify(rename); export async function install() { // `rustup` is already installed on Linux and Windows platforms @@ -24,39 +22,25 @@ export async function install() { await exec.exec('rustup', ['set', 'profile', 'minimal']); if (os.platform() == 'win32') { - let clearedEnvVar = '__SETUP_RUST_ACTION_DEFAULT_INSTALL_CLEARED'; - // let rustDocsInstalled = false; - // { - // let installedComponents = ''; - // const options = { - // listeners: { - // stdout: (data: Buffer) => { - // installedComponents += data.toString(); - // } - // } - // }; - // await exec.exec('rustup', ['component', 'list'], options); - // rustDocsInstalled = installedComponents.match(/rust-docs.+\(installed\)/) != null; - // } - - // If the rust-docs component isn't installed, - if (process.env[clearedEnvVar] == null) { - let cargoPath = ''; - { - const options = { - listeners: { - stdout: (data: Buffer) => { - cargoPath += data.toString(); - } + let cargoPath = ''; + { + const options = { + listeners: { + stdout: (data: Buffer) => { + cargoPath += data.toString(); } - }; - await exec.exec('where', ['rustup.exe'], options); - } - let rustupPath = cargoPath.split('\\').slice(0, -3).concat([".rustup"]).join("\\"); + } + }; + await exec.exec('where', ['rustup.exe'], options); + } + let rustupPath = cargoPath.split('\\').slice(0, -3).concat([".rustup"]).join("\\"); + let defaultClearedFilePath = `${rustupPath}\\default_cleared`; + + if (!existsSync(defaultClearedFilePath)) { // Github's default Windows install comes with rustup pre-installed with stable, including // rust-docs. This removes the default stable install so that it doesn't update rust-docs. - await renameAsync(`${rustupPath}\\toolchains`, `${rustupPath}\\_toolchains`); - await exec.exec('setx', [clearedEnvVar, "1"]); + renameSync(`${rustupPath}\\toolchains`, `${rustupPath}\\_toolchains`); + appendFileSync(defaultClearedFilePath, ''); } } }