Skip to content

Commit

Permalink
fix: turn errexit off in the shell sessions (#64)
Browse files Browse the repository at this point in the history
* DRY up the `tmate` invocations

We always pass the `-S /tmp/tmate.sock` option; Let's not repeat this
(and risk forgetting it anywhere, or risk typos, or... something).

Signed-off-by: Johannes Schindelin <[email protected]>

* Work around Actions adding `set -e` to the Bash profile

When `set -e` (or more verbosely, `set -o errexit`) is in effect, any
failing command will automatically exit the shell. This is quite
convenient for scripts.

It is quite awful, however, for interactive sessions: even a tiny typo
will send the session to the happy hunting ground.

In fact, it is actually not _all_ that good an option to use, anyway,
see https://mywiki.wooledge.org/BashFAQ/105 for more details.

Therefore, no `/etc/profile` will set this, as it would render the
interactive sessions useless.

However, `conda-incubator/setup-miniconda` does this. Granted, the
assumption that GitHub workflows do not run interactively is an easy one
to make. And it was correct... until `action-tmate` came along.

Let's work around this by _specifically_ turning off `errexit`.

Since we do not want to add hackery on top of hackery, we will not edit
`~/.profile` but instead write our own rcfile and pass it onto the
default command `tmate` runs.

This fixes #37.

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho authored Mar 25, 2021
1 parent 2715745 commit 03e13f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
14 changes: 10 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9679,14 +9679,20 @@ async function run() {
newSessionExtra = `-a "${authorizedKeysPath}"`
}

const tmate = `${tmateExecutable} -S /tmp/tmate.sock`;

// Work around potential `set -e` commands in `~/.profile` (looking at you, `setup-miniconda`!)
external_fs_default().writeFileSync('/tmp/tmate.bashrc', 'set +e\n');
const setDefaultCommand = `set-option -g default-command "bash --rcfile /tmp/tmate.bashrc" \\;`;

core.debug("Creating new session")
await execShellCommand(`${tmateExecutable} -S /tmp/tmate.sock ${newSessionExtra} new-session -d`);
await execShellCommand(`${tmateExecutable} -S /tmp/tmate.sock wait tmate-ready`);
await execShellCommand(`${tmate} ${setDefaultCommand} ${newSessionExtra} new-session -d`);
await execShellCommand(`${tmate} wait tmate-ready`);
console.debug("Created new session successfully")

core.debug("Fetching connection strings")
const tmateSSH = await execShellCommand(`${tmateExecutable} -S /tmp/tmate.sock display -p '#{tmate_ssh}'`);
const tmateWeb = await execShellCommand(`${tmateExecutable} -S /tmp/tmate.sock display -p '#{tmate_web}'`);
const tmateSSH = await execShellCommand(`${tmate} display -p '#{tmate_ssh}'`);
const tmateWeb = await execShellCommand(`${tmate} display -p '#{tmate_web}'`);

console.debug("Entering main loop")
while (true) {
Expand Down
14 changes: 10 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,20 @@ export async function run() {
newSessionExtra = `-a "${authorizedKeysPath}"`
}

const tmate = `${tmateExecutable} -S /tmp/tmate.sock`;

// Work around potential `set -e` commands in `~/.profile` (looking at you, `setup-miniconda`!)
fs.writeFileSync('/tmp/tmate.bashrc', 'set +e\n');
const setDefaultCommand = `set-option -g default-command "bash --rcfile /tmp/tmate.bashrc" \\;`;

core.debug("Creating new session")
await execShellCommand(`${tmateExecutable} -S /tmp/tmate.sock ${newSessionExtra} new-session -d`);
await execShellCommand(`${tmateExecutable} -S /tmp/tmate.sock wait tmate-ready`);
await execShellCommand(`${tmate} ${setDefaultCommand} ${newSessionExtra} new-session -d`);
await execShellCommand(`${tmate} wait tmate-ready`);
console.debug("Created new session successfully")

core.debug("Fetching connection strings")
const tmateSSH = await execShellCommand(`${tmateExecutable} -S /tmp/tmate.sock display -p '#{tmate_ssh}'`);
const tmateWeb = await execShellCommand(`${tmateExecutable} -S /tmp/tmate.sock display -p '#{tmate_web}'`);
const tmateSSH = await execShellCommand(`${tmate} display -p '#{tmate_ssh}'`);
const tmateWeb = await execShellCommand(`${tmate} display -p '#{tmate_web}'`);

console.debug("Entering main loop")
while (true) {
Expand Down
1 change: 1 addition & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jest.mock("fs", () => ({
mkdirSync: () => true,
existsSync: () => true,
unlinkSync: () => true,
writeFileSync: () => true
}));
jest.mock('./helpers');
import { execShellCommand } from "./helpers"
Expand Down

0 comments on commit 03e13f1

Please sign in to comment.