Skip to content

Commit f39202a

Browse files
seemetherec-m-y-kawabe
authored andcommitted
add option to skip dependency installation
apt-get is not available on certain distributions so it's better to have the option to leave it out so we can still have the ability to run this action without having to be on ubuntu. Signed-off-by: Eli Uriegas <[email protected]>
1 parent 80a9fae commit f39202a

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ inputs:
1111
description: 'If apt should be executed with sudo or without'
1212
required: false
1313
default: 'true'
14+
install_dependencies:
15+
description: 'Whether or not to install dependencies for tmate on linux (openssh-client, xz-utils)'
16+
required: false
17+
default: 'true'
1418
limit-access-to-actor:
1519
description: 'If only the public SSH keys of the user triggering the workflow should be authorized'
1620
required: false
@@ -30,4 +34,4 @@ inputs:
3034
tmate-server-ed25519-fingerprint:
3135
description: 'The ed25519 fingerprint for your tmate server'
3236
required: false
33-
default: ''
37+
default: ''

lib/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10317,6 +10317,11 @@ const TMATE_ARCH_MAP = {
1031710317
/** @param {number} ms */
1031810318
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
1031910319

10320+
async function installDependenciesLinux(optionalSudoPrefix='sudo') {
10321+
await execShellCommand(optionalSudoPrefix + 'apt-get update');
10322+
await execShellCommand(optionalSudoPrefix + 'apt-get install -y openssh-client xz-utils');
10323+
}
10324+
1032010325
async function run() {
1032110326
const optionalSudoPrefix = core.getInput('sudo') === "true" ? "sudo " : "";
1032210327
try {
@@ -10328,8 +10333,9 @@ async function run() {
1032810333
await execShellCommand('pacman -Sy --noconfirm tmate');
1032910334
tmateExecutable = 'CHERE_INVOKING=1 tmate'
1033010335
} else {
10331-
await execShellCommand(optionalSudoPrefix + 'apt-get update');
10332-
await execShellCommand(optionalSudoPrefix + 'apt-get install -y openssh-client xz-utils');
10336+
if (core.getInput('install_dependencies') === "true") {
10337+
await installDependenciesLinux(optionalSudoPrefix);
10338+
}
1033310339

1033410340
const tmateArch = TMATE_ARCH_MAP[external_os_default().arch()];
1033510341
if (!tmateArch) {

src/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ const TMATE_ARCH_MAP = {
2424
/** @param {number} ms */
2525
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
2626

27+
export async function installDependenciesLinux(optionalSudoPrefix='sudo') {
28+
await execShellCommand(optionalSudoPrefix + 'apt-get update');
29+
await execShellCommand(optionalSudoPrefix + 'apt-get install -y openssh-client xz-utils');
30+
}
31+
2732
export async function run() {
2833
const optionalSudoPrefix = core.getInput('sudo') === "true" ? "sudo " : "";
2934
try {
@@ -35,8 +40,9 @@ export async function run() {
3540
await execShellCommand('pacman -Sy --noconfirm tmate');
3641
tmateExecutable = 'CHERE_INVOKING=1 tmate'
3742
} else {
38-
await execShellCommand(optionalSudoPrefix + 'apt-get update');
39-
await execShellCommand(optionalSudoPrefix + 'apt-get install -y openssh-client xz-utils');
43+
if (core.getInput('install_dependencies') === "true") {
44+
await installDependenciesLinux(optionalSudoPrefix);
45+
}
4046

4147
const tmateArch = TMATE_ARCH_MAP[os.arch()];
4248
if (!tmateArch) {

src/index.test.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Tmate GitHub integration', () => {
4141
Object.defineProperty(process, "platform", {
4242
value: "linux"
4343
})
44-
core.getInput.mockReturnValueOnce("true").mockReturnValue("false")
44+
core.getInput.mockReturnValueOnce("true").mockReturnValueOnce("true").mockReturnValue("false")
4545
const customConnectionString = "foobar"
4646
execShellCommand.mockReturnValue(Promise.resolve(customConnectionString))
4747
await run()
@@ -54,7 +54,7 @@ describe('Tmate GitHub integration', () => {
5454
Object.defineProperty(process, "platform", {
5555
value: "linux"
5656
})
57-
core.getInput.mockReturnValue("false")
57+
core.getInput.mockReturnValueOnce("false").mockReturnValueOnce("true").mockReturnValue("false")
5858
const customConnectionString = "foobar"
5959
execShellCommand.mockReturnValue(Promise.resolve(customConnectionString))
6060
await run()
@@ -63,6 +63,19 @@ describe('Tmate GitHub integration', () => {
6363
expect(core.info).toHaveBeenNthCalledWith(2, `SSH: ${customConnectionString}`);
6464
expect(core.info).toHaveBeenNthCalledWith(3, "Exiting debugging session because the continue file was created");
6565
});
66+
it('should be handle the main loop for linux without installing dependencies', async () => {
67+
Object.defineProperty(process, "platform", {
68+
value: "linux"
69+
})
70+
core.getInput.mockReturnValue("false")
71+
const customConnectionString = "foobar"
72+
execShellCommand.mockReturnValue(Promise.resolve(customConnectionString))
73+
await run()
74+
expect(execShellCommand).not.toHaveBeenNthCalledWith(1, "apt-get update")
75+
expect(core.info).toHaveBeenNthCalledWith(1, `Web shell: ${customConnectionString}`);
76+
expect(core.info).toHaveBeenNthCalledWith(2, `SSH: ${customConnectionString}`);
77+
expect(core.info).toHaveBeenNthCalledWith(3, "Exiting debugging session because the continue file was created");
78+
});
6679
it('should install tmate via brew for darwin', async () => {
6780
Object.defineProperty(process, "platform", {
6881
value: "darwin"

0 commit comments

Comments
 (0)