Use filesystem to check if operation has been run

This commit is contained in:
Osspial 2019-12-04 02:34:45 -05:00
parent 468970f930
commit de871ef0a4
2 changed files with 32 additions and 64 deletions

View File

@ -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, '');
}
}
}

View File

@ -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, '');
}
}
}