diff --git a/lib/index.js b/lib/index.js index 164de2c2..d3e01dec 100644 --- a/lib/index.js +++ b/lib/index.js @@ -10319,38 +10319,38 @@ const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); async function run() { try { - core.debug("Installing dependencies") let tmateExecutable = "tmate" - if (process.platform === "darwin") { - await execShellCommand('brew install tmate'); - } else if (process.platform === "win32") { - await execShellCommand('pacman -Sy --noconfirm tmate'); - tmateExecutable = 'CHERE_INVOKING=1 tmate' - } else { - if (core.getInput("install-dependencies") === "true") { + if (core.getInput("install-dependencies") === "true") { + core.debug("Installing dependencies") + if (process.platform === "darwin") { + await execShellCommand('brew install tmate'); + } else if (process.platform === "win32") { + await execShellCommand('pacman -Sy --noconfirm tmate'); + } else { const optionalSudoPrefix = core.getInput("sudo") === "true" ? "sudo " : ""; await execShellCommand(optionalSudoPrefix + "apt-get update"); await execShellCommand(optionalSudoPrefix + "apt-get install -y openssh-client xz-utils"); - } - const tmateArch = TMATE_ARCH_MAP[external_os_default().arch()]; - if (!tmateArch) { - throw new Error(`Unsupported architecture: ${external_os_default().arch()}`) - } - const tmateReleaseTar = await tool_cache.downloadTool(`https://github.com/tmate-io/tmate/releases/download/${TMATE_LINUX_VERSION}/tmate-${TMATE_LINUX_VERSION}-static-linux-${tmateArch}.tar.xz`); - const tmateDir = external_path_default().join(external_os_default().tmpdir(), "tmate") - tmateExecutable = external_path_default().join(tmateDir, "tmate") + const tmateArch = TMATE_ARCH_MAP[external_os_default().arch()]; + if (!tmateArch) { + throw new Error(`Unsupported architecture: ${external_os_default().arch()}`) + } + const tmateReleaseTar = await tool_cache.downloadTool(`https://github.com/tmate-io/tmate/releases/download/${TMATE_LINUX_VERSION}/tmate-${TMATE_LINUX_VERSION}-static-linux-${tmateArch}.tar.xz`); + const tmateDir = external_path_default().join(external_os_default().tmpdir(), "tmate") + tmateExecutable = external_path_default().join(tmateDir, "tmate") - if (external_fs_default().existsSync(tmateExecutable)) - external_fs_default().unlinkSync(tmateExecutable) - external_fs_default().mkdirSync(tmateDir, { recursive: true }) - await execShellCommand(`tar x -C ${tmateDir} -f ${tmateReleaseTar} --strip-components=1`) - external_fs_default().unlinkSync(tmateReleaseTar) + if (external_fs_default().existsSync(tmateExecutable)) + external_fs_default().unlinkSync(tmateExecutable) + external_fs_default().mkdirSync(tmateDir, { recursive: true }) + await execShellCommand(`tar x -C ${tmateDir} -f ${tmateReleaseTar} --strip-components=1`) + external_fs_default().unlinkSync(tmateReleaseTar) + } + core.debug("Installed dependencies successfully"); } - core.debug("Installed dependencies successfully"); - - if (process.platform !== "win32") { + if (process.platform === "win32") { + tmateExecutable = 'CHERE_INVOKING=1 tmate' + } else { core.debug("Generating SSH keys") external_fs_default().mkdirSync(external_path_default().join(external_os_default().homedir(), ".ssh"), { recursive: true }) try { diff --git a/src/index.js b/src/index.js index d672afcb..4cd4fdc1 100644 --- a/src/index.js +++ b/src/index.js @@ -26,38 +26,38 @@ const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); export async function run() { try { - core.debug("Installing dependencies") let tmateExecutable = "tmate" - if (process.platform === "darwin") { - await execShellCommand('brew install tmate'); - } else if (process.platform === "win32") { - await execShellCommand('pacman -Sy --noconfirm tmate'); - tmateExecutable = 'CHERE_INVOKING=1 tmate' - } else { - if (core.getInput("install-dependencies") === "true") { + if (core.getInput("install-dependencies") === "true") { + core.debug("Installing dependencies") + if (process.platform === "darwin") { + await execShellCommand('brew install tmate'); + } else if (process.platform === "win32") { + await execShellCommand('pacman -Sy --noconfirm tmate'); + } else { const optionalSudoPrefix = core.getInput("sudo") === "true" ? "sudo " : ""; await execShellCommand(optionalSudoPrefix + "apt-get update"); await execShellCommand(optionalSudoPrefix + "apt-get install -y openssh-client xz-utils"); - } - const tmateArch = TMATE_ARCH_MAP[os.arch()]; - if (!tmateArch) { - throw new Error(`Unsupported architecture: ${os.arch()}`) + const tmateArch = TMATE_ARCH_MAP[os.arch()]; + if (!tmateArch) { + throw new Error(`Unsupported architecture: ${os.arch()}`) + } + const tmateReleaseTar = await tc.downloadTool(`https://github.com/tmate-io/tmate/releases/download/${TMATE_LINUX_VERSION}/tmate-${TMATE_LINUX_VERSION}-static-linux-${tmateArch}.tar.xz`); + const tmateDir = path.join(os.tmpdir(), "tmate") + tmateExecutable = path.join(tmateDir, "tmate") + + if (fs.existsSync(tmateExecutable)) + fs.unlinkSync(tmateExecutable) + fs.mkdirSync(tmateDir, { recursive: true }) + await execShellCommand(`tar x -C ${tmateDir} -f ${tmateReleaseTar} --strip-components=1`) + fs.unlinkSync(tmateReleaseTar) } - const tmateReleaseTar = await tc.downloadTool(`https://github.com/tmate-io/tmate/releases/download/${TMATE_LINUX_VERSION}/tmate-${TMATE_LINUX_VERSION}-static-linux-${tmateArch}.tar.xz`); - const tmateDir = path.join(os.tmpdir(), "tmate") - tmateExecutable = path.join(tmateDir, "tmate") - - if (fs.existsSync(tmateExecutable)) - fs.unlinkSync(tmateExecutable) - fs.mkdirSync(tmateDir, { recursive: true }) - await execShellCommand(`tar x -C ${tmateDir} -f ${tmateReleaseTar} --strip-components=1`) - fs.unlinkSync(tmateReleaseTar) + core.debug("Installed dependencies successfully"); } - core.debug("Installed dependencies successfully"); - - if (process.platform !== "win32") { + if (process.platform === "win32") { + tmateExecutable = 'CHERE_INVOKING=1 tmate' + } else { core.debug("Generating SSH keys") fs.mkdirSync(path.join(os.homedir(), ".ssh"), { recursive: true }) try { diff --git a/src/index.test.js b/src/index.test.js index 62cb07b4..f1b92bdc 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -32,7 +32,20 @@ describe('Tmate GitHub integration', () => { const customConnectionString = "foobar" execShellCommand.mockReturnValue(Promise.resolve(customConnectionString)) await run() - expect(execShellCommand).toHaveBeenNthCalledWith(1, "pacman -Sy --noconfirm tmate") + expect(execShellCommand).toHaveBeenNthCalledWith(1, "pacman -Sy --noconfirm tmate"); + expect(core.info).toHaveBeenNthCalledWith(1, `Web shell: ${customConnectionString}`); + expect(core.info).toHaveBeenNthCalledWith(2, `SSH: ${customConnectionString}`); + expect(core.info).toHaveBeenNthCalledWith(3, "Exiting debugging session because the continue file was created"); + }); + it('should handle the main loop for Windows without dependency installation', async () => { + Object.defineProperty(process, "platform", { + value: "win32" + }) + core.getInput.mockReturnValue("false") + const customConnectionString = "foobar" + execShellCommand.mockReturnValue(Promise.resolve(customConnectionString)) + await run() + expect(execShellCommand).not.toHaveBeenNthCalledWith(1, "pacman -Sy --noconfirm tmate"); expect(core.info).toHaveBeenNthCalledWith(1, `Web shell: ${customConnectionString}`); expect(core.info).toHaveBeenNthCalledWith(2, `SSH: ${customConnectionString}`); expect(core.info).toHaveBeenNthCalledWith(3, "Exiting debugging session because the continue file was created"); @@ -80,7 +93,16 @@ describe('Tmate GitHub integration', () => { Object.defineProperty(process, "platform", { value: "darwin" }) + core.getInput.mockReturnValue("true") await run() expect(execShellCommand).toHaveBeenNthCalledWith(1, "brew install tmate") }); + it('should not install dependencies for darwin', async () => { + Object.defineProperty(process, "platform", { + value: "darwin" + }) + core.getInput.mockReturnValue("false") + await run() + expect(execShellCommand).not.toHaveBeenNthCalledWith(1, "brew install tmate") + }); });