Skip to content

Commit

Permalink
mod: use install-dependencies options with all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
y-kawabe committed Nov 2, 2021
1 parent ba22bf1 commit 5647912
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 49 deletions.
48 changes: 24 additions & 24 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
48 changes: 24 additions & 24 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 23 additions & 1 deletion src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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")
});
});

0 comments on commit 5647912

Please sign in to comment.