Skip to content

Commit

Permalink
feat: support user own tmate server (#93)
Browse files Browse the repository at this point in the history
Co-authored-by: Johannes Schindelin <[email protected]>
Co-authored-by: Max Schmitt <[email protected]>
  • Loading branch information
3 people authored Oct 5, 2021
1 parent ecba4db commit 19a49ed
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 5 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@ jobs:

If the registered public SSH key is not your default private SSH key, you will need to specify the path manually, like so: `ssh -i <path-to-key> <tmate-connection-string>`.

## Use your own tmate servers

By default the tmate session uses `ssh.tmate.io`. You can use your own tmate servers. [tmate-ssh-server](https://github.com/tmate-io/tmate-ssh-server) is the server side part of tmate.

```yaml
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
with:
tmate-server-host: ssh.tmate.io
tmate-server-port: 22
tmate-server-rsa-fingerprint: SHA256:Hthk2T/M/Ivqfk1YYUn5ijC2Att3+UPzD7Rn72P5VWs
tmate-server-ed25519-fingerprint: SHA256:jfttvoypkHiQYUqUCwKeqd9d1fJj/ZiQlFOHVl6E9sI
```

## Continue a workflow

If you want to continue a workflow and you are inside a tmate session, just create a empty file with the name `continue` either in the root directory or in the project directory by running `touch continue` or `sudo touch /continue`.
Expand Down
18 changes: 17 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,20 @@ inputs:
limit-access-to-actor:
description: 'If only the public SSH keys of the user triggering the workflow should be authorized'
required: false
default: 'false'
default: 'false'
tmate-server-host:
description: 'The hostname for your tmate server'
required: false
default: ''
tmate-server-port:
description: 'The port for your tmate server'
required: false
default: ''
tmate-server-rsa-fingerprint:
description: 'The RSA fingerprint for your tmate server'
required: false
default: ''
tmate-server-ed25519-fingerprint:
description: 'The ed25519 fingerprint for your tmate server'
required: false
default: ''
23 changes: 22 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10242,6 +10242,7 @@ var external_child_process_ = __nccwpck_require__(3129);
// @ts-check



/**
* @param {string} cmd
* @returns {Promise<string>}
Expand Down Expand Up @@ -10277,6 +10278,18 @@ const execShellCommand = (cmd) => {
});
}

/**
* @param {string} key
* @return {string}
*/
const getValidatedInput = (key) => {
const value = core.getInput(key);
if (/^[-.+A-Za-z0-9]*$/.test(value)) {
throw new Error(`Invalid value for '${key}': '${value}'`);
}
return value;
}

;// CONCATENATED MODULE: ./src/index.js
// @ts-check

Expand Down Expand Up @@ -10366,7 +10379,14 @@ async function run() {

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

if (core.getInput("tmate-server-host") !== "") {
setDefaultCommand = `${setDefaultCommand} set-option -g tmate-server-host "${getValidatedInput("tmate-server-host")}" \\;`;
setDefaultCommand = `${setDefaultCommand} set-option -g tmate-server-port "${getValidatedInput("tmate-server-port")}" \\;`;
setDefaultCommand = `${setDefaultCommand} set-option -g tmate-server-rsa-fingerprint "${getValidatedInput("tmate-server-rsa-fingerprint")}" \\;`;
setDefaultCommand = `${setDefaultCommand} set-option -g tmate-server-ed25519-fingerprint "${getValidatedInput("tmate-server-ed25519-fingerprint")}" \\;`;
}

core.debug("Creating new session")
await execShellCommand(`${tmate} ${newSessionExtra} ${setDefaultCommand} new-session -d`);
Expand Down Expand Up @@ -10411,6 +10431,7 @@ function continueFileExists() {
const continuePath = process.platform === "win32" ? "C:/msys64/continue" : "/continue"
return external_fs_default().existsSync(continuePath) || external_fs_default().existsSync(external_path_default().join(process.env.GITHUB_WORKSPACE, "continue"))
}

;// CONCATENATED MODULE: ./src/main.js


Expand Down
13 changes: 13 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
import { spawn } from 'child_process'
import * as core from "@actions/core"

/**
* @param {string} cmd
Expand Down Expand Up @@ -35,3 +36,15 @@ export const execShellCommand = (cmd) => {
});
});
}

/**
* @param {string} key
* @return {string}
*/
export const getValidatedInput = (key) => {
const value = core.getInput(key);
if (/^[-.+A-Za-z0-9]*$/.test(value)) {
throw new Error(`Invalid value for '${key}': '${value}'`);
}
return value;
}
13 changes: 10 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as github from "@actions/github"
import * as tc from "@actions/tool-cache"
import { Octokit } from "@octokit/rest"

import { execShellCommand } from "./helpers"
import { execShellCommand, getValidatedInput } from "./helpers"

const TMATE_LINUX_VERSION = "2.4.0"

Expand Down Expand Up @@ -86,7 +86,14 @@ export async function run() {

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

if (core.getInput("tmate-server-host") !== "") {
setDefaultCommand = `${setDefaultCommand} set-option -g tmate-server-host "${getValidatedInput("tmate-server-host")}" \\;`;
setDefaultCommand = `${setDefaultCommand} set-option -g tmate-server-port "${getValidatedInput("tmate-server-port")}" \\;`;
setDefaultCommand = `${setDefaultCommand} set-option -g tmate-server-rsa-fingerprint "${getValidatedInput("tmate-server-rsa-fingerprint")}" \\;`;
setDefaultCommand = `${setDefaultCommand} set-option -g tmate-server-ed25519-fingerprint "${getValidatedInput("tmate-server-ed25519-fingerprint")}" \\;`;
}

core.debug("Creating new session")
await execShellCommand(`${tmate} ${newSessionExtra} ${setDefaultCommand} new-session -d`);
Expand Down Expand Up @@ -130,4 +137,4 @@ function didTmateQuit() {
function continueFileExists() {
const continuePath = process.platform === "win32" ? "C:/msys64/continue" : "/continue"
return fs.existsSync(continuePath) || fs.existsSync(path.join(process.env.GITHUB_WORKSPACE, "continue"))
}
}

0 comments on commit 19a49ed

Please sign in to comment.