From 7087a1505e57e5c38bbfc5e49acf7f9b847aa6a2 Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Tue, 28 Dec 2021 16:09:02 +0900 Subject: [PATCH 01/20] feat: allow to update existing asdf --- install/main.js | 45 +++++++++++++++++++++++++++------------------ lib/setup/index.ts | 29 +++++++++++++++++++---------- plugin-test/main.js | 39 ++++++++++++++++++++++++--------------- plugins-add/main.js | 45 +++++++++++++++++++++++++++------------------ setup/main.js | 39 ++++++++++++++++++++++++--------------- 5 files changed, 121 insertions(+), 76 deletions(-) diff --git a/install/main.js b/install/main.js index 11004f0..63c9c00 100644 --- a/install/main.js +++ b/install/main.js @@ -126,7 +126,7 @@ var require_file_command = __commonJS((exports2) => { return result; }; Object.defineProperty(exports2, "__esModule", {value: true}); - var fs2 = __importStar(require("fs")); + var fs3 = __importStar(require("fs")); var os2 = __importStar(require("os")); var utils_1 = require_utils(); function issueCommand(command, message) { @@ -134,10 +134,10 @@ var require_file_command = __commonJS((exports2) => { if (!filePath) { throw new Error(`Unable to find environment variable for file command ${command}`); } - if (!fs2.existsSync(filePath)) { + if (!fs3.existsSync(filePath)) { throw new Error(`Missing file at path: ${filePath}`); } - fs2.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { + fs3.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { encoding: "utf8" }); } @@ -329,9 +329,9 @@ var require_io_util = __commonJS((exports2) => { var _a; Object.defineProperty(exports2, "__esModule", {value: true}); var assert_1 = require("assert"); - var fs2 = require("fs"); + var fs3 = require("fs"); var path2 = require("path"); - _a = fs2.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; + _a = fs3.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; exports2.IS_WINDOWS = process.platform === "win32"; function exists(fsPath) { return __awaiter(this, void 0, void 0, function* () { @@ -1221,12 +1221,13 @@ var exec5 = __toModule(require_exec()); // lib/plugins-add/index.ts var core2 = __toModule(require_core()); var exec3 = __toModule(require_exec()); -var fs = __toModule(require("fs")); +var fs2 = __toModule(require("fs")); // lib/setup/index.ts var core = __toModule(require_core()); var exec = __toModule(require_exec()); var io = __toModule(require_io()); +var fs = __toModule(require("fs")); var os = __toModule(require("os")); var path = __toModule(require("path")); async function setupAsdf() { @@ -1239,17 +1240,25 @@ async function setupAsdf() { core.exportVariable("ASDF_DATA_DIR", asdfDir); core.addPath(`${asdfDir}/bin`); core.addPath(`${asdfDir}/shims`); - core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); const branch = core.getInput("asdf_branch", {required: true}); - await exec.exec("git", [ - "clone", - "--depth", - "1", - "--branch", - branch, - "https://github.com/asdf-vm/asdf.git", - asdfDir - ]); + if (fs.existsSync(asdfDir)) { + core.info(`Updating asdf on ASDF_DIR: ${asdfDir}`); + await exec.exec("git", ["fetch", "--depth", "1"], {cwd: asdfDir}); + await exec.exec("git", ["checkout", "-B", branch, "origin"], { + cwd: asdfDir + }); + } else { + core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); + await exec.exec("git", [ + "clone", + "--depth", + "1", + "--branch", + branch, + "https://github.com/asdf-vm/asdf.git", + asdfDir + ]); + } } // lib/plugins-add/index.ts @@ -1279,11 +1288,11 @@ async function pluginsAdd() { await setupAsdf(); let toolVersions = core2.getInput("tool_versions", {required: false}); if (toolVersions) { - await fs.promises.writeFile(".tool-versions", toolVersions, { + await fs2.promises.writeFile(".tool-versions", toolVersions, { encoding: "utf8" }); } else { - toolVersions = await fs.promises.readFile(".tool-versions", { + toolVersions = await fs2.promises.readFile(".tool-versions", { encoding: "utf8" }); } diff --git a/lib/setup/index.ts b/lib/setup/index.ts index c45baf8..f5d3f4d 100644 --- a/lib/setup/index.ts +++ b/lib/setup/index.ts @@ -1,6 +1,7 @@ import * as core from "@actions/core"; import * as exec from "@actions/exec"; import * as io from "@actions/io"; +import * as fs from "fs"; import * as os from "os"; import * as path from "path"; @@ -14,15 +15,23 @@ export async function setupAsdf(): Promise { core.exportVariable("ASDF_DATA_DIR", asdfDir); core.addPath(`${asdfDir}/bin`); core.addPath(`${asdfDir}/shims`); - core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); const branch = core.getInput("asdf_branch", { required: true }); - await exec.exec("git", [ - "clone", - "--depth", - "1", - "--branch", - branch, - "https://github.com/asdf-vm/asdf.git", - asdfDir, - ]); + if (fs.existsSync(asdfDir)) { + core.info(`Updating asdf on ASDF_DIR: ${asdfDir}`); + await exec.exec("git", ["fetch", "--depth", "1"], { cwd: asdfDir }); + await exec.exec("git", ["checkout", "-B", branch, "origin"], { + cwd: asdfDir, + }); + } else { + core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); + await exec.exec("git", [ + "clone", + "--depth", + "1", + "--branch", + branch, + "https://github.com/asdf-vm/asdf.git", + asdfDir, + ]); + } } diff --git a/plugin-test/main.js b/plugin-test/main.js index bd92e25..b30f318 100644 --- a/plugin-test/main.js +++ b/plugin-test/main.js @@ -126,7 +126,7 @@ var require_file_command = __commonJS((exports2) => { return result; }; Object.defineProperty(exports2, "__esModule", {value: true}); - var fs = __importStar(require("fs")); + var fs2 = __importStar(require("fs")); var os2 = __importStar(require("os")); var utils_1 = require_utils(); function issueCommand(command, message) { @@ -134,10 +134,10 @@ var require_file_command = __commonJS((exports2) => { if (!filePath) { throw new Error(`Unable to find environment variable for file command ${command}`); } - if (!fs.existsSync(filePath)) { + if (!fs2.existsSync(filePath)) { throw new Error(`Missing file at path: ${filePath}`); } - fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { + fs2.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { encoding: "utf8" }); } @@ -329,9 +329,9 @@ var require_io_util = __commonJS((exports2) => { var _a; Object.defineProperty(exports2, "__esModule", {value: true}); var assert_1 = require("assert"); - var fs = require("fs"); + var fs2 = require("fs"); var path2 = require("path"); - _a = fs.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; + _a = fs2.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; exports2.IS_WINDOWS = process.platform === "win32"; function exists(fsPath) { return __awaiter(this, void 0, void 0, function* () { @@ -1222,6 +1222,7 @@ var exec3 = __toModule(require_exec()); var core = __toModule(require_core()); var exec = __toModule(require_exec()); var io = __toModule(require_io()); +var fs = __toModule(require("fs")); var os = __toModule(require("os")); var path = __toModule(require("path")); async function setupAsdf() { @@ -1234,17 +1235,25 @@ async function setupAsdf() { core.exportVariable("ASDF_DATA_DIR", asdfDir); core.addPath(`${asdfDir}/bin`); core.addPath(`${asdfDir}/shims`); - core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); const branch = core.getInput("asdf_branch", {required: true}); - await exec.exec("git", [ - "clone", - "--depth", - "1", - "--branch", - branch, - "https://github.com/asdf-vm/asdf.git", - asdfDir - ]); + if (fs.existsSync(asdfDir)) { + core.info(`Updating asdf on ASDF_DIR: ${asdfDir}`); + await exec.exec("git", ["fetch", "--depth", "1"], {cwd: asdfDir}); + await exec.exec("git", ["checkout", "-B", branch, "origin"], { + cwd: asdfDir + }); + } else { + core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); + await exec.exec("git", [ + "clone", + "--depth", + "1", + "--branch", + branch, + "https://github.com/asdf-vm/asdf.git", + asdfDir + ]); + } } // lib/plugin-test/index.ts diff --git a/plugins-add/main.js b/plugins-add/main.js index fc01339..76581a8 100644 --- a/plugins-add/main.js +++ b/plugins-add/main.js @@ -126,7 +126,7 @@ var require_file_command = __commonJS((exports2) => { return result; }; Object.defineProperty(exports2, "__esModule", {value: true}); - var fs2 = __importStar(require("fs")); + var fs3 = __importStar(require("fs")); var os2 = __importStar(require("os")); var utils_1 = require_utils(); function issueCommand(command, message) { @@ -134,10 +134,10 @@ var require_file_command = __commonJS((exports2) => { if (!filePath) { throw new Error(`Unable to find environment variable for file command ${command}`); } - if (!fs2.existsSync(filePath)) { + if (!fs3.existsSync(filePath)) { throw new Error(`Missing file at path: ${filePath}`); } - fs2.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { + fs3.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { encoding: "utf8" }); } @@ -329,9 +329,9 @@ var require_io_util = __commonJS((exports2) => { var _a; Object.defineProperty(exports2, "__esModule", {value: true}); var assert_1 = require("assert"); - var fs2 = require("fs"); + var fs3 = require("fs"); var path2 = require("path"); - _a = fs2.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; + _a = fs3.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; exports2.IS_WINDOWS = process.platform === "win32"; function exists(fsPath) { return __awaiter(this, void 0, void 0, function* () { @@ -1217,12 +1217,13 @@ var core3 = __toModule(require_core()); // lib/plugins-add/index.ts var core2 = __toModule(require_core()); var exec3 = __toModule(require_exec()); -var fs = __toModule(require("fs")); +var fs2 = __toModule(require("fs")); // lib/setup/index.ts var core = __toModule(require_core()); var exec = __toModule(require_exec()); var io = __toModule(require_io()); +var fs = __toModule(require("fs")); var os = __toModule(require("os")); var path = __toModule(require("path")); async function setupAsdf() { @@ -1235,17 +1236,25 @@ async function setupAsdf() { core.exportVariable("ASDF_DATA_DIR", asdfDir); core.addPath(`${asdfDir}/bin`); core.addPath(`${asdfDir}/shims`); - core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); const branch = core.getInput("asdf_branch", {required: true}); - await exec.exec("git", [ - "clone", - "--depth", - "1", - "--branch", - branch, - "https://github.com/asdf-vm/asdf.git", - asdfDir - ]); + if (fs.existsSync(asdfDir)) { + core.info(`Updating asdf on ASDF_DIR: ${asdfDir}`); + await exec.exec("git", ["fetch", "--depth", "1"], {cwd: asdfDir}); + await exec.exec("git", ["checkout", "-B", branch, "origin"], { + cwd: asdfDir + }); + } else { + core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); + await exec.exec("git", [ + "clone", + "--depth", + "1", + "--branch", + branch, + "https://github.com/asdf-vm/asdf.git", + asdfDir + ]); + } } // lib/plugins-add/index.ts @@ -1275,11 +1284,11 @@ async function pluginsAdd() { await setupAsdf(); let toolVersions = core2.getInput("tool_versions", {required: false}); if (toolVersions) { - await fs.promises.writeFile(".tool-versions", toolVersions, { + await fs2.promises.writeFile(".tool-versions", toolVersions, { encoding: "utf8" }); } else { - toolVersions = await fs.promises.readFile(".tool-versions", { + toolVersions = await fs2.promises.readFile(".tool-versions", { encoding: "utf8" }); } diff --git a/setup/main.js b/setup/main.js index ec508b0..31930a4 100644 --- a/setup/main.js +++ b/setup/main.js @@ -126,7 +126,7 @@ var require_file_command = __commonJS((exports2) => { return result; }; Object.defineProperty(exports2, "__esModule", {value: true}); - var fs = __importStar(require("fs")); + var fs2 = __importStar(require("fs")); var os2 = __importStar(require("os")); var utils_1 = require_utils(); function issueCommand(command, message) { @@ -134,10 +134,10 @@ var require_file_command = __commonJS((exports2) => { if (!filePath) { throw new Error(`Unable to find environment variable for file command ${command}`); } - if (!fs.existsSync(filePath)) { + if (!fs2.existsSync(filePath)) { throw new Error(`Missing file at path: ${filePath}`); } - fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { + fs2.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { encoding: "utf8" }); } @@ -329,9 +329,9 @@ var require_io_util = __commonJS((exports2) => { var _a; Object.defineProperty(exports2, "__esModule", {value: true}); var assert_1 = require("assert"); - var fs = require("fs"); + var fs2 = require("fs"); var path2 = require("path"); - _a = fs.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; + _a = fs2.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; exports2.IS_WINDOWS = process.platform === "win32"; function exists(fsPath) { return __awaiter(this, void 0, void 0, function* () { @@ -1218,6 +1218,7 @@ var core2 = __toModule(require_core()); var core = __toModule(require_core()); var exec = __toModule(require_exec()); var io = __toModule(require_io()); +var fs = __toModule(require("fs")); var os = __toModule(require("os")); var path = __toModule(require("path")); async function setupAsdf() { @@ -1230,17 +1231,25 @@ async function setupAsdf() { core.exportVariable("ASDF_DATA_DIR", asdfDir); core.addPath(`${asdfDir}/bin`); core.addPath(`${asdfDir}/shims`); - core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); const branch = core.getInput("asdf_branch", {required: true}); - await exec.exec("git", [ - "clone", - "--depth", - "1", - "--branch", - branch, - "https://github.com/asdf-vm/asdf.git", - asdfDir - ]); + if (fs.existsSync(asdfDir)) { + core.info(`Updating asdf on ASDF_DIR: ${asdfDir}`); + await exec.exec("git", ["fetch", "--depth", "1"], {cwd: asdfDir}); + await exec.exec("git", ["checkout", "-B", branch, "origin"], { + cwd: asdfDir + }); + } else { + core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); + await exec.exec("git", [ + "clone", + "--depth", + "1", + "--branch", + branch, + "https://github.com/asdf-vm/asdf.git", + asdfDir + ]); + } } // lib/setup/main.ts From 6dbbaf44eadc26e3978bc6bf1215fa4f75df9802 Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Thu, 13 Jan 2022 21:33:19 +0900 Subject: [PATCH 02/20] fix: improve how to switch branch in existing asdf --- install/main.js | 9 ++++++--- lib/setup/index.ts | 9 ++++++--- plugin-test/main.js | 9 ++++++--- plugins-add/main.js | 9 ++++++--- setup/main.js | 9 ++++++--- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/install/main.js b/install/main.js index 63c9c00..6e89bc7 100644 --- a/install/main.js +++ b/install/main.js @@ -1243,10 +1243,12 @@ async function setupAsdf() { const branch = core.getInput("asdf_branch", {required: true}); if (fs.existsSync(asdfDir)) { core.info(`Updating asdf on ASDF_DIR: ${asdfDir}`); - await exec.exec("git", ["fetch", "--depth", "1"], {cwd: asdfDir}); - await exec.exec("git", ["checkout", "-B", branch, "origin"], { + const opts = { cwd: asdfDir - }); + }; + await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); + await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); + await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); } else { core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); await exec.exec("git", [ @@ -1255,6 +1257,7 @@ async function setupAsdf() { "1", "--branch", branch, + "--single-branch", "https://github.com/asdf-vm/asdf.git", asdfDir ]); diff --git a/lib/setup/index.ts b/lib/setup/index.ts index f5d3f4d..9f32b78 100644 --- a/lib/setup/index.ts +++ b/lib/setup/index.ts @@ -18,10 +18,12 @@ export async function setupAsdf(): Promise { const branch = core.getInput("asdf_branch", { required: true }); if (fs.existsSync(asdfDir)) { core.info(`Updating asdf on ASDF_DIR: ${asdfDir}`); - await exec.exec("git", ["fetch", "--depth", "1"], { cwd: asdfDir }); - await exec.exec("git", ["checkout", "-B", branch, "origin"], { + const opts = { cwd: asdfDir, - }); + }; + await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); + await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); + await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); } else { core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); await exec.exec("git", [ @@ -30,6 +32,7 @@ export async function setupAsdf(): Promise { "1", "--branch", branch, + "--single-branch", "https://github.com/asdf-vm/asdf.git", asdfDir, ]); diff --git a/plugin-test/main.js b/plugin-test/main.js index b30f318..41c14b4 100644 --- a/plugin-test/main.js +++ b/plugin-test/main.js @@ -1238,10 +1238,12 @@ async function setupAsdf() { const branch = core.getInput("asdf_branch", {required: true}); if (fs.existsSync(asdfDir)) { core.info(`Updating asdf on ASDF_DIR: ${asdfDir}`); - await exec.exec("git", ["fetch", "--depth", "1"], {cwd: asdfDir}); - await exec.exec("git", ["checkout", "-B", branch, "origin"], { + const opts = { cwd: asdfDir - }); + }; + await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); + await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); + await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); } else { core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); await exec.exec("git", [ @@ -1250,6 +1252,7 @@ async function setupAsdf() { "1", "--branch", branch, + "--single-branch", "https://github.com/asdf-vm/asdf.git", asdfDir ]); diff --git a/plugins-add/main.js b/plugins-add/main.js index 76581a8..38b7ba0 100644 --- a/plugins-add/main.js +++ b/plugins-add/main.js @@ -1239,10 +1239,12 @@ async function setupAsdf() { const branch = core.getInput("asdf_branch", {required: true}); if (fs.existsSync(asdfDir)) { core.info(`Updating asdf on ASDF_DIR: ${asdfDir}`); - await exec.exec("git", ["fetch", "--depth", "1"], {cwd: asdfDir}); - await exec.exec("git", ["checkout", "-B", branch, "origin"], { + const opts = { cwd: asdfDir - }); + }; + await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); + await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); + await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); } else { core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); await exec.exec("git", [ @@ -1251,6 +1253,7 @@ async function setupAsdf() { "1", "--branch", branch, + "--single-branch", "https://github.com/asdf-vm/asdf.git", asdfDir ]); diff --git a/setup/main.js b/setup/main.js index 31930a4..8ad44f8 100644 --- a/setup/main.js +++ b/setup/main.js @@ -1234,10 +1234,12 @@ async function setupAsdf() { const branch = core.getInput("asdf_branch", {required: true}); if (fs.existsSync(asdfDir)) { core.info(`Updating asdf on ASDF_DIR: ${asdfDir}`); - await exec.exec("git", ["fetch", "--depth", "1"], {cwd: asdfDir}); - await exec.exec("git", ["checkout", "-B", branch, "origin"], { + const opts = { cwd: asdfDir - }); + }; + await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); + await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); + await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); } else { core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); await exec.exec("git", [ @@ -1246,6 +1248,7 @@ async function setupAsdf() { "1", "--branch", branch, + "--single-branch", "https://github.com/asdf-vm/asdf.git", asdfDir ]); From 9bca9b72c59c5fda5824342f0e8f3f489d61aba6 Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Thu, 16 Mar 2023 15:35:33 +1100 Subject: [PATCH 03/20] chore: rebuild plugins with asdf repo update --- install/main.js | 46 +++++++++++++++++++++++++++------------------ plugin-test/main.js | 40 ++++++++++++++++++++++++--------------- plugins-add/main.js | 46 +++++++++++++++++++++++++++------------------ setup/main.js | 40 ++++++++++++++++++++++++--------------- 4 files changed, 106 insertions(+), 66 deletions(-) diff --git a/install/main.js b/install/main.js index 4afc292..ae402a0 100644 --- a/install/main.js +++ b/install/main.js @@ -519,7 +519,7 @@ var require_file_command = __commonJS({ }; Object.defineProperty(exports, "__esModule", { value: true }); exports.prepareKeyValueMessage = exports.issueFileCommand = void 0; - var fs2 = __importStar(require("fs")); + var fs3 = __importStar(require("fs")); var os2 = __importStar(require("os")); var uuid_1 = (init_esm_node(), __toCommonJS(esm_node_exports)); var utils_1 = require_utils(); @@ -528,10 +528,10 @@ var require_file_command = __commonJS({ if (!filePath) { throw new Error(`Unable to find environment variable for file command ${command}`); } - if (!fs2.existsSync(filePath)) { + if (!fs3.existsSync(filePath)) { throw new Error(`Missing file at path: ${filePath}`); } - fs2.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { + fs3.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { encoding: "utf8" }); } @@ -2269,9 +2269,9 @@ var require_io_util = __commonJS({ var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCmdPath = exports.tryGetExecutablePath = exports.isRooted = exports.isDirectory = exports.exists = exports.IS_WINDOWS = exports.unlink = exports.symlink = exports.stat = exports.rmdir = exports.rename = exports.readlink = exports.readdir = exports.mkdir = exports.lstat = exports.copyFile = exports.chmod = void 0; - var fs2 = __importStar(require("fs")); + var fs3 = __importStar(require("fs")); var path2 = __importStar(require("path")); - _a = fs2.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink; + _a = fs3.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink; exports.IS_WINDOWS = process.platform === "win32"; function exists(fsPath) { return __awaiter(this, void 0, void 0, function* () { @@ -3276,12 +3276,13 @@ var exec5 = __toESM(require_exec()); // src/plugins-add/index.ts var core2 = __toESM(require_core()); var exec3 = __toESM(require_exec()); -var fs = __toESM(require("fs")); +var fs2 = __toESM(require("fs")); // src/setup/index.ts var core = __toESM(require_core()); var exec = __toESM(require_exec()); var io = __toESM(require_io()); +var fs = __toESM(require("fs")); var os = __toESM(require("os")); var path = __toESM(require("path")); async function setupAsdf() { @@ -3298,17 +3299,26 @@ async function setupAsdf() { if (skip) { return; } - core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); const branch = core.getInput("asdf_branch", { required: true }); - await exec.exec("git", [ - "clone", - "--depth", - "1", - "--branch", - branch, - "https://github.com/asdf-vm/asdf.git", - asdfDir - ]); + if (fs.existsSync(asdfDir)) { + core.info(`Updating asdf in ASDF_DIR "${asdfDir}" on branch "${branch}"`); + const opts = { cwd: asdfDir }; + await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); + await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); + await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); + } else { + core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); + await exec.exec("git", [ + "clone", + "--depth", + "1", + "--branch", + branch, + "--single-branch", + "https://github.com/asdf-vm/asdf.git", + asdfDir + ]); + } } // src/plugins-add/index.ts @@ -3338,11 +3348,11 @@ async function pluginsAdd() { await setupAsdf(); let toolVersions = core2.getInput("tool_versions", { required: false }); if (toolVersions) { - await fs.promises.writeFile(".tool-versions", toolVersions, { + await fs2.promises.writeFile(".tool-versions", toolVersions, { encoding: "utf8" }); } else { - toolVersions = await fs.promises.readFile(".tool-versions", { + toolVersions = await fs2.promises.readFile(".tool-versions", { encoding: "utf8" }); } diff --git a/plugin-test/main.js b/plugin-test/main.js index 618fc32..57cd192 100644 --- a/plugin-test/main.js +++ b/plugin-test/main.js @@ -519,7 +519,7 @@ var require_file_command = __commonJS({ }; Object.defineProperty(exports, "__esModule", { value: true }); exports.prepareKeyValueMessage = exports.issueFileCommand = void 0; - var fs = __importStar(require("fs")); + var fs2 = __importStar(require("fs")); var os2 = __importStar(require("os")); var uuid_1 = (init_esm_node(), __toCommonJS(esm_node_exports)); var utils_1 = require_utils(); @@ -528,10 +528,10 @@ var require_file_command = __commonJS({ if (!filePath) { throw new Error(`Unable to find environment variable for file command ${command}`); } - if (!fs.existsSync(filePath)) { + if (!fs2.existsSync(filePath)) { throw new Error(`Missing file at path: ${filePath}`); } - fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { + fs2.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { encoding: "utf8" }); } @@ -2269,9 +2269,9 @@ var require_io_util = __commonJS({ var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCmdPath = exports.tryGetExecutablePath = exports.isRooted = exports.isDirectory = exports.exists = exports.IS_WINDOWS = exports.unlink = exports.symlink = exports.stat = exports.rmdir = exports.rename = exports.readlink = exports.readdir = exports.mkdir = exports.lstat = exports.copyFile = exports.chmod = void 0; - var fs = __importStar(require("fs")); + var fs2 = __importStar(require("fs")); var path2 = __importStar(require("path")); - _a = fs.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink; + _a = fs2.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink; exports.IS_WINDOWS = process.platform === "win32"; function exists(fsPath) { return __awaiter(this, void 0, void 0, function* () { @@ -3277,6 +3277,7 @@ var exec3 = __toESM(require_exec()); var core = __toESM(require_core()); var exec = __toESM(require_exec()); var io = __toESM(require_io()); +var fs = __toESM(require("fs")); var os = __toESM(require("os")); var path = __toESM(require("path")); async function setupAsdf() { @@ -3293,17 +3294,26 @@ async function setupAsdf() { if (skip) { return; } - core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); const branch = core.getInput("asdf_branch", { required: true }); - await exec.exec("git", [ - "clone", - "--depth", - "1", - "--branch", - branch, - "https://github.com/asdf-vm/asdf.git", - asdfDir - ]); + if (fs.existsSync(asdfDir)) { + core.info(`Updating asdf in ASDF_DIR "${asdfDir}" on branch "${branch}"`); + const opts = { cwd: asdfDir }; + await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); + await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); + await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); + } else { + core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); + await exec.exec("git", [ + "clone", + "--depth", + "1", + "--branch", + branch, + "--single-branch", + "https://github.com/asdf-vm/asdf.git", + asdfDir + ]); + } } // src/plugin-test/index.ts diff --git a/plugins-add/main.js b/plugins-add/main.js index e7e4a19..cf045a3 100644 --- a/plugins-add/main.js +++ b/plugins-add/main.js @@ -519,7 +519,7 @@ var require_file_command = __commonJS({ }; Object.defineProperty(exports, "__esModule", { value: true }); exports.prepareKeyValueMessage = exports.issueFileCommand = void 0; - var fs2 = __importStar(require("fs")); + var fs3 = __importStar(require("fs")); var os2 = __importStar(require("os")); var uuid_1 = (init_esm_node(), __toCommonJS(esm_node_exports)); var utils_1 = require_utils(); @@ -528,10 +528,10 @@ var require_file_command = __commonJS({ if (!filePath) { throw new Error(`Unable to find environment variable for file command ${command}`); } - if (!fs2.existsSync(filePath)) { + if (!fs3.existsSync(filePath)) { throw new Error(`Missing file at path: ${filePath}`); } - fs2.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { + fs3.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { encoding: "utf8" }); } @@ -2269,9 +2269,9 @@ var require_io_util = __commonJS({ var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCmdPath = exports.tryGetExecutablePath = exports.isRooted = exports.isDirectory = exports.exists = exports.IS_WINDOWS = exports.unlink = exports.symlink = exports.stat = exports.rmdir = exports.rename = exports.readlink = exports.readdir = exports.mkdir = exports.lstat = exports.copyFile = exports.chmod = void 0; - var fs2 = __importStar(require("fs")); + var fs3 = __importStar(require("fs")); var path2 = __importStar(require("path")); - _a = fs2.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink; + _a = fs3.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink; exports.IS_WINDOWS = process.platform === "win32"; function exists(fsPath) { return __awaiter(this, void 0, void 0, function* () { @@ -3272,12 +3272,13 @@ var core3 = __toESM(require_core()); // src/plugins-add/index.ts var core2 = __toESM(require_core()); var exec3 = __toESM(require_exec()); -var fs = __toESM(require("fs")); +var fs2 = __toESM(require("fs")); // src/setup/index.ts var core = __toESM(require_core()); var exec = __toESM(require_exec()); var io = __toESM(require_io()); +var fs = __toESM(require("fs")); var os = __toESM(require("os")); var path = __toESM(require("path")); async function setupAsdf() { @@ -3294,17 +3295,26 @@ async function setupAsdf() { if (skip) { return; } - core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); const branch = core.getInput("asdf_branch", { required: true }); - await exec.exec("git", [ - "clone", - "--depth", - "1", - "--branch", - branch, - "https://github.com/asdf-vm/asdf.git", - asdfDir - ]); + if (fs.existsSync(asdfDir)) { + core.info(`Updating asdf in ASDF_DIR "${asdfDir}" on branch "${branch}"`); + const opts = { cwd: asdfDir }; + await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); + await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); + await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); + } else { + core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); + await exec.exec("git", [ + "clone", + "--depth", + "1", + "--branch", + branch, + "--single-branch", + "https://github.com/asdf-vm/asdf.git", + asdfDir + ]); + } } // src/plugins-add/index.ts @@ -3334,11 +3344,11 @@ async function pluginsAdd() { await setupAsdf(); let toolVersions = core2.getInput("tool_versions", { required: false }); if (toolVersions) { - await fs.promises.writeFile(".tool-versions", toolVersions, { + await fs2.promises.writeFile(".tool-versions", toolVersions, { encoding: "utf8" }); } else { - toolVersions = await fs.promises.readFile(".tool-versions", { + toolVersions = await fs2.promises.readFile(".tool-versions", { encoding: "utf8" }); } diff --git a/setup/main.js b/setup/main.js index c60d7d6..58ab65b 100644 --- a/setup/main.js +++ b/setup/main.js @@ -519,7 +519,7 @@ var require_file_command = __commonJS({ }; Object.defineProperty(exports, "__esModule", { value: true }); exports.prepareKeyValueMessage = exports.issueFileCommand = void 0; - var fs = __importStar(require("fs")); + var fs2 = __importStar(require("fs")); var os2 = __importStar(require("os")); var uuid_1 = (init_esm_node(), __toCommonJS(esm_node_exports)); var utils_1 = require_utils(); @@ -528,10 +528,10 @@ var require_file_command = __commonJS({ if (!filePath) { throw new Error(`Unable to find environment variable for file command ${command}`); } - if (!fs.existsSync(filePath)) { + if (!fs2.existsSync(filePath)) { throw new Error(`Missing file at path: ${filePath}`); } - fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { + fs2.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os2.EOL}`, { encoding: "utf8" }); } @@ -2269,9 +2269,9 @@ var require_io_util = __commonJS({ var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCmdPath = exports.tryGetExecutablePath = exports.isRooted = exports.isDirectory = exports.exists = exports.IS_WINDOWS = exports.unlink = exports.symlink = exports.stat = exports.rmdir = exports.rename = exports.readlink = exports.readdir = exports.mkdir = exports.lstat = exports.copyFile = exports.chmod = void 0; - var fs = __importStar(require("fs")); + var fs2 = __importStar(require("fs")); var path2 = __importStar(require("path")); - _a = fs.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink; + _a = fs2.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink; exports.IS_WINDOWS = process.platform === "win32"; function exists(fsPath) { return __awaiter(this, void 0, void 0, function* () { @@ -3273,6 +3273,7 @@ var core2 = __toESM(require_core()); var core = __toESM(require_core()); var exec = __toESM(require_exec()); var io = __toESM(require_io()); +var fs = __toESM(require("fs")); var os = __toESM(require("os")); var path = __toESM(require("path")); async function setupAsdf() { @@ -3289,17 +3290,26 @@ async function setupAsdf() { if (skip) { return; } - core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); const branch = core.getInput("asdf_branch", { required: true }); - await exec.exec("git", [ - "clone", - "--depth", - "1", - "--branch", - branch, - "https://github.com/asdf-vm/asdf.git", - asdfDir - ]); + if (fs.existsSync(asdfDir)) { + core.info(`Updating asdf in ASDF_DIR "${asdfDir}" on branch "${branch}"`); + const opts = { cwd: asdfDir }; + await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); + await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); + await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); + } else { + core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); + await exec.exec("git", [ + "clone", + "--depth", + "1", + "--branch", + branch, + "--single-branch", + "https://github.com/asdf-vm/asdf.git", + asdfDir + ]); + } } // src/setup/main.ts From 63e3f4e4fe43776ae3ccbb4faa10ca80fbdfecdb Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Thu, 16 Mar 2023 15:43:14 +1100 Subject: [PATCH 04/20] test: ensure setup can be run multiple times --- .github/workflows/test.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d3841c1..80e22e0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,6 +24,17 @@ jobs: echo PATH="${PATH}" asdf --version + asdf_updates_clone_if_installed: + strategy: + fail-fast: false + matrix: + os: ["macos-latest", "ubuntu-latest"] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - uses: ./setup + - uses: ./setup + plugin_is_tested: strategy: fail-fast: false From ad28c5909034e6db2b04613ee1bb2df81cb95896 Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Thu, 16 Mar 2023 16:26:51 +1100 Subject: [PATCH 05/20] test: debug logging for asdfPath --- .github/workflows/test.yml | 6 ++++-- src/setup/index.ts | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80e22e0..d46f47d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,8 +32,10 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - - uses: ./setup - - uses: ./setup + - name: "Setup: should clone" + uses: ./setup + - name: "Setup: should update" + uses: ./setup plugin_is_tested: strategy: diff --git a/src/setup/index.ts b/src/setup/index.ts index 69c534f..499547d 100644 --- a/src/setup/index.ts +++ b/src/setup/index.ts @@ -7,6 +7,7 @@ import * as path from "path"; export async function setupAsdf(): Promise { const asdfPath = await io.which("asdf", false); + core.debug(`adsfPath: ${asdfPath}`) if (asdfPath) { return; } From 3a8905e6fc43f60c5f3157e9d069a4db145510e3 Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Thu, 16 Mar 2023 16:29:56 +1100 Subject: [PATCH 06/20] test: asdfPath output in log --- install/main.js | 1 + plugin-test/main.js | 1 + plugins-add/main.js | 1 + setup/main.js | 1 + src/setup/index.ts | 2 +- 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/install/main.js b/install/main.js index ae402a0..6b67a62 100644 --- a/install/main.js +++ b/install/main.js @@ -3287,6 +3287,7 @@ var os = __toESM(require("os")); var path = __toESM(require("path")); async function setupAsdf() { const asdfPath = await io.which("asdf", false); + core.info(`adsfPath: ${asdfPath}`); if (asdfPath) { return; } diff --git a/plugin-test/main.js b/plugin-test/main.js index 57cd192..f686fd7 100644 --- a/plugin-test/main.js +++ b/plugin-test/main.js @@ -3282,6 +3282,7 @@ var os = __toESM(require("os")); var path = __toESM(require("path")); async function setupAsdf() { const asdfPath = await io.which("asdf", false); + core.info(`adsfPath: ${asdfPath}`); if (asdfPath) { return; } diff --git a/plugins-add/main.js b/plugins-add/main.js index cf045a3..b4ebb99 100644 --- a/plugins-add/main.js +++ b/plugins-add/main.js @@ -3283,6 +3283,7 @@ var os = __toESM(require("os")); var path = __toESM(require("path")); async function setupAsdf() { const asdfPath = await io.which("asdf", false); + core.info(`adsfPath: ${asdfPath}`); if (asdfPath) { return; } diff --git a/setup/main.js b/setup/main.js index 58ab65b..370408a 100644 --- a/setup/main.js +++ b/setup/main.js @@ -3278,6 +3278,7 @@ var os = __toESM(require("os")); var path = __toESM(require("path")); async function setupAsdf() { const asdfPath = await io.which("asdf", false); + core.info(`adsfPath: ${asdfPath}`); if (asdfPath) { return; } diff --git a/src/setup/index.ts b/src/setup/index.ts index 499547d..4cf10ed 100644 --- a/src/setup/index.ts +++ b/src/setup/index.ts @@ -7,7 +7,7 @@ import * as path from "path"; export async function setupAsdf(): Promise { const asdfPath = await io.which("asdf", false); - core.debug(`adsfPath: ${asdfPath}`) + core.info(`adsfPath: ${asdfPath}`); if (asdfPath) { return; } From 1581974dad2171eb467733519c9a8ceb898347fe Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Fri, 17 Mar 2023 19:10:46 +1100 Subject: [PATCH 07/20] ci: remove ./asdf/bin/asdf in sequential actions/setup test to simulate hosted runner --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d46f47d..3a9cf09 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,6 +34,9 @@ jobs: - uses: actions/checkout@v3 - name: "Setup: should clone" uses: ./setup + - name: "Simulate self-hosted runner and remove /home/runner/.asdf/bin/asdf" + run: | + rm -rf /home/runner/.asdf/bin/asdf - name: "Setup: should update" uses: ./setup From e665b94f72a2aa26d608d1bb1467a1a7d55ea2ec Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Fri, 17 Mar 2023 23:59:16 +1100 Subject: [PATCH 08/20] chore: rm log --- install/main.js | 1 - plugin-test/main.js | 1 - plugins-add/main.js | 1 - setup/main.js | 1 - src/setup/index.ts | 2 +- 5 files changed, 1 insertion(+), 5 deletions(-) diff --git a/install/main.js b/install/main.js index 6b67a62..ae402a0 100644 --- a/install/main.js +++ b/install/main.js @@ -3287,7 +3287,6 @@ var os = __toESM(require("os")); var path = __toESM(require("path")); async function setupAsdf() { const asdfPath = await io.which("asdf", false); - core.info(`adsfPath: ${asdfPath}`); if (asdfPath) { return; } diff --git a/plugin-test/main.js b/plugin-test/main.js index f686fd7..57cd192 100644 --- a/plugin-test/main.js +++ b/plugin-test/main.js @@ -3282,7 +3282,6 @@ var os = __toESM(require("os")); var path = __toESM(require("path")); async function setupAsdf() { const asdfPath = await io.which("asdf", false); - core.info(`adsfPath: ${asdfPath}`); if (asdfPath) { return; } diff --git a/plugins-add/main.js b/plugins-add/main.js index b4ebb99..cf045a3 100644 --- a/plugins-add/main.js +++ b/plugins-add/main.js @@ -3283,7 +3283,6 @@ var os = __toESM(require("os")); var path = __toESM(require("path")); async function setupAsdf() { const asdfPath = await io.which("asdf", false); - core.info(`adsfPath: ${asdfPath}`); if (asdfPath) { return; } diff --git a/setup/main.js b/setup/main.js index 370408a..58ab65b 100644 --- a/setup/main.js +++ b/setup/main.js @@ -3278,7 +3278,6 @@ var os = __toESM(require("os")); var path = __toESM(require("path")); async function setupAsdf() { const asdfPath = await io.which("asdf", false); - core.info(`adsfPath: ${asdfPath}`); if (asdfPath) { return; } diff --git a/src/setup/index.ts b/src/setup/index.ts index 4cf10ed..f77d496 100644 --- a/src/setup/index.ts +++ b/src/setup/index.ts @@ -7,10 +7,10 @@ import * as path from "path"; export async function setupAsdf(): Promise { const asdfPath = await io.which("asdf", false); - core.info(`adsfPath: ${asdfPath}`); if (asdfPath) { return; } + const asdfDir = path.join(os.homedir(), ".asdf"); core.exportVariable("ASDF_DIR", asdfDir); core.exportVariable("ASDF_DATA_DIR", asdfDir); From 5615cef26525eeaca256a5e7a04147aac3ac1488 Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Sat, 18 Mar 2023 00:05:08 +1100 Subject: [PATCH 09/20] fix: format github action --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3a9cf09..b354ec4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,7 +34,8 @@ jobs: - uses: actions/checkout@v3 - name: "Setup: should clone" uses: ./setup - - name: "Simulate self-hosted runner and remove /home/runner/.asdf/bin/asdf" + - name: + "Simulate self-hosted runner and remove /home/runner/.asdf/bin/asdf" run: | rm -rf /home/runner/.asdf/bin/asdf - name: "Setup: should update" From 6e0ff1444c40cb9f7657cd0f67ddae8b192625ae Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Sat, 18 Mar 2023 00:05:39 +1100 Subject: [PATCH 10/20] chore: check uncommitted changes in pkg json script --- .github/workflows/build.yml | 6 +----- package.json | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fb6cf26..e110237 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,8 +36,4 @@ jobs: shell: bash run: | yarn build - if [ "$(git status --porcelain | wc -l)" -gt "0" ]; then - echo "Detected uncommitted changes after build. See status below:" - git diff - exit 1 - fi + yarn build:check_uncommitted_changes diff --git a/package.json b/package.json index a6eb906..549dc90 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "fmt:check": "prettier --check .", "typecheck": "tsc", "lint": "eslint \"**/*.ts\" --cache", - "build": "esbuild src/install/main.ts src/plugin-test/main.ts src/plugins-add/main.ts src/setup/main.ts --bundle --outdir=. --target=node16 --platform=node" + "build": "esbuild src/install/main.ts src/plugin-test/main.ts src/plugins-add/main.ts src/setup/main.ts --bundle --outdir=. --target=node16 --platform=node", + "build:check_uncommitted_changes": "bash -c 'if [ $(git status --porcelain | grep --extended-regexp \"src|install|plugin-test|plugins-add\" | wc -l) -gt 0 ]; then printf \"* %s\\n\" \"Detected uncommitted changes after build. See status below:\"; git diff; exit 1; fi'" }, "dependencies": { "@actions/core": "^1.10.0", From 7921f37b635a39d21ba34495013f59e6a0a1ea1d Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Sat, 18 Mar 2023 00:06:00 +1100 Subject: [PATCH 11/20] chore: check uncommitted changes on pre-push --- lefthook.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lefthook.yaml b/lefthook.yaml index 4eb66d9..4760388 100644 --- a/lefthook.yaml +++ b/lefthook.yaml @@ -4,6 +4,8 @@ pre-push: run: yarn run lint format: run: yarn fmt:check + check_uncommitted_build_changes: + run: yarn build:check_uncommitted_changes pre-commit: commands: From ecee5f76f355ab10992a5c0168b472a3dd7b6a42 Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Sat, 18 Mar 2023 00:09:39 +1100 Subject: [PATCH 12/20] ci: rerun setup action again to test if it skips --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b354ec4..687d70c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,6 +40,8 @@ jobs: rm -rf /home/runner/.asdf/bin/asdf - name: "Setup: should update" uses: ./setup + - name: "Setup: should do nothing as it is already setup" + uses: ./setup plugin_is_tested: strategy: From 4d1440f87f7c52802779a7abbfc96abd580c9a01 Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Sat, 18 Mar 2023 00:14:43 +1100 Subject: [PATCH 13/20] ci: validate setup repo update in CI --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 687d70c..816e7d9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,16 +32,16 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - - name: "Setup: should clone" + - name: "Setup: should clone repo" uses: ./setup + - run: asdf version - name: - "Simulate self-hosted runner and remove /home/runner/.asdf/bin/asdf" + "Simulate self-hosted runner and remove /home/runner/.asdf/bin/asdf after setup (:shrug:)" run: | rm -rf /home/runner/.asdf/bin/asdf - - name: "Setup: should update" - uses: ./setup - - name: "Setup: should do nothing as it is already setup" + - name: "Setup: should update repo" uses: ./setup + - run: asdf version plugin_is_tested: strategy: From b7c3f13d6bd2b0f889d199b29d78c941e470bf8e Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Sat, 18 Mar 2023 00:15:30 +1100 Subject: [PATCH 14/20] chore: format action workflow --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 816e7d9..004ea82 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,7 +36,8 @@ jobs: uses: ./setup - run: asdf version - name: - "Simulate self-hosted runner and remove /home/runner/.asdf/bin/asdf after setup (:shrug:)" + "Simulate self-hosted runner and remove /home/runner/.asdf/bin/asdf + after setup (:shrug:)" run: | rm -rf /home/runner/.asdf/bin/asdf - name: "Setup: should update repo" From 78af907b6c0b3b2a52859c4cf957cc109ca2ffef Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Sat, 18 Mar 2023 00:32:26 +1100 Subject: [PATCH 15/20] ci: rm different files on different runners --- .github/workflows/test.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 004ea82..d5e5d7d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,11 +35,19 @@ jobs: - name: "Setup: should clone repo" uses: ./setup - run: asdf version +# TODO(jthegedus): how is it that the hosted runners get to this point in the code without ~/.asdf/bin/asdf - name: "Simulate self-hosted runner and remove /home/runner/.asdf/bin/asdf after setup (:shrug:)" + if: ${{ matrix.os == "ubuntu-latest" }} run: | rm -rf /home/runner/.asdf/bin/asdf + - name: + "Simulate self-hosted runner and remove /Users/runner/.asdf/bin/asdf + after setup (:shrug:)" + if: ${{ matrix.os == "macos-latest" }} + run: | + rm -rf /Users/runner/.asdf/bin/asdf - name: "Setup: should update repo" uses: ./setup - run: asdf version From c2d4e1e3c3a5daf465e458fb1f9e13ea85b2646e Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Sat, 18 Mar 2023 00:36:06 +1100 Subject: [PATCH 16/20] chore: format action workflow --- .github/workflows/test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d5e5d7d..dbfc85c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,11 +35,11 @@ jobs: - name: "Setup: should clone repo" uses: ./setup - run: asdf version -# TODO(jthegedus): how is it that the hosted runners get to this point in the code without ~/.asdf/bin/asdf + # TODO(jthegedus): how is it that the hosted runners get to this point in the code without ~/.asdf/bin/asdf - name: "Simulate self-hosted runner and remove /home/runner/.asdf/bin/asdf after setup (:shrug:)" - if: ${{ matrix.os == "ubuntu-latest" }} + if: ${{ matrix.os == 'ubuntu-latest' }} run: | rm -rf /home/runner/.asdf/bin/asdf - name: @@ -50,7 +50,6 @@ jobs: rm -rf /Users/runner/.asdf/bin/asdf - name: "Setup: should update repo" uses: ./setup - - run: asdf version plugin_is_tested: strategy: From 8d25770c5f6d4489ed755726b168707c74347671 Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Sat, 18 Mar 2023 00:36:34 +1100 Subject: [PATCH 17/20] chore: format action workflow --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dbfc85c..7330823 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,7 +45,7 @@ jobs: - name: "Simulate self-hosted runner and remove /Users/runner/.asdf/bin/asdf after setup (:shrug:)" - if: ${{ matrix.os == "macos-latest" }} + if: ${{ matrix.os == 'macos-latest' }} run: | rm -rf /Users/runner/.asdf/bin/asdf - name: "Setup: should update repo" From f9dfea6515813c059200008d80a746cc36cbe25a Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Sat, 18 Mar 2023 00:41:09 +1100 Subject: [PATCH 18/20] fix: use git clean also to rm local changes when updating --- install/main.js | 1 + plugin-test/main.js | 1 + plugins-add/main.js | 1 + setup/main.js | 1 + src/setup/index.ts | 1 + 5 files changed, 5 insertions(+) diff --git a/install/main.js b/install/main.js index ae402a0..17cc365 100644 --- a/install/main.js +++ b/install/main.js @@ -3306,6 +3306,7 @@ async function setupAsdf() { await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); + await exec.exec("git", ["clean", "-fd"], opts); } else { core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); await exec.exec("git", [ diff --git a/plugin-test/main.js b/plugin-test/main.js index 57cd192..ece4a80 100644 --- a/plugin-test/main.js +++ b/plugin-test/main.js @@ -3301,6 +3301,7 @@ async function setupAsdf() { await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); + await exec.exec("git", ["clean", "-fd"], opts); } else { core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); await exec.exec("git", [ diff --git a/plugins-add/main.js b/plugins-add/main.js index cf045a3..b750a6c 100644 --- a/plugins-add/main.js +++ b/plugins-add/main.js @@ -3302,6 +3302,7 @@ async function setupAsdf() { await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); + await exec.exec("git", ["clean", "-fd"], opts); } else { core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); await exec.exec("git", [ diff --git a/setup/main.js b/setup/main.js index 58ab65b..a4aa131 100644 --- a/setup/main.js +++ b/setup/main.js @@ -3297,6 +3297,7 @@ async function setupAsdf() { await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); + await exec.exec("git", ["clean", "-fd"], opts); } else { core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); await exec.exec("git", [ diff --git a/src/setup/index.ts b/src/setup/index.ts index f77d496..d15d957 100644 --- a/src/setup/index.ts +++ b/src/setup/index.ts @@ -29,6 +29,7 @@ export async function setupAsdf(): Promise { await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); + await exec.exec("git", ["clean", "-fd"], opts); } else { core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); await exec.exec("git", [ From 13820115956b6fd124514ca0627f67d30bc2c870 Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Sat, 18 Mar 2023 00:42:31 +1100 Subject: [PATCH 19/20] ci: validate git clean --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7330823..4d1a955 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,6 +50,7 @@ jobs: rm -rf /Users/runner/.asdf/bin/asdf - name: "Setup: should update repo" uses: ./setup + - run: asdf version plugin_is_tested: strategy: From 002bc3d4153300d3559c6cefd00c25bb7745323b Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Sat, 18 Mar 2023 00:49:13 +1100 Subject: [PATCH 20/20] fix: rm git clean in setup action. simplify CI test --- .github/workflows/test.yml | 6 ++++-- install/main.js | 1 - plugin-test/main.js | 1 - plugins-add/main.js | 1 - setup/main.js | 1 - src/setup/index.ts | 1 - 6 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4d1a955..8fa9ea8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,7 +35,6 @@ jobs: - name: "Setup: should clone repo" uses: ./setup - run: asdf version - # TODO(jthegedus): how is it that the hosted runners get to this point in the code without ~/.asdf/bin/asdf - name: "Simulate self-hosted runner and remove /home/runner/.asdf/bin/asdf after setup (:shrug:)" @@ -50,7 +49,10 @@ jobs: rm -rf /Users/runner/.asdf/bin/asdf - name: "Setup: should update repo" uses: ./setup - - run: asdf version + # NB: how is it that the hosted runners get to this point in the code without ~/.asdf/bin/asdf + # the below execution fails because the checkout doesn't seem to fix the rm -rf. + # Comment out for now & trust in the OP of #394 + # - run: asdf version plugin_is_tested: strategy: diff --git a/install/main.js b/install/main.js index 17cc365..ae402a0 100644 --- a/install/main.js +++ b/install/main.js @@ -3306,7 +3306,6 @@ async function setupAsdf() { await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); - await exec.exec("git", ["clean", "-fd"], opts); } else { core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); await exec.exec("git", [ diff --git a/plugin-test/main.js b/plugin-test/main.js index ece4a80..57cd192 100644 --- a/plugin-test/main.js +++ b/plugin-test/main.js @@ -3301,7 +3301,6 @@ async function setupAsdf() { await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); - await exec.exec("git", ["clean", "-fd"], opts); } else { core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); await exec.exec("git", [ diff --git a/plugins-add/main.js b/plugins-add/main.js index b750a6c..cf045a3 100644 --- a/plugins-add/main.js +++ b/plugins-add/main.js @@ -3302,7 +3302,6 @@ async function setupAsdf() { await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); - await exec.exec("git", ["clean", "-fd"], opts); } else { core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); await exec.exec("git", [ diff --git a/setup/main.js b/setup/main.js index a4aa131..58ab65b 100644 --- a/setup/main.js +++ b/setup/main.js @@ -3297,7 +3297,6 @@ async function setupAsdf() { await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); - await exec.exec("git", ["clean", "-fd"], opts); } else { core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); await exec.exec("git", [ diff --git a/src/setup/index.ts b/src/setup/index.ts index d15d957..f77d496 100644 --- a/src/setup/index.ts +++ b/src/setup/index.ts @@ -29,7 +29,6 @@ export async function setupAsdf(): Promise { await exec.exec("git", ["remote", "set-branches", "origin", branch], opts); await exec.exec("git", ["fetch", "--depth", "1", "origin", branch], opts); await exec.exec("git", ["checkout", "-B", branch, "origin"], opts); - await exec.exec("git", ["clean", "-fd"], opts); } else { core.info(`Cloning asdf into ASDF_DIR "${asdfDir}" on branch "${branch}"`); await exec.exec("git", [