Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,42 @@ By default, this mode will wait at the end of the job for a user to connect and

As this mode has turned out to be so useful as to having the potential for being the default mode once time travel becomes available, it is also available as `mxschmitt/action-tmate/detached` for convenience.

### Using SSH command output in other jobs

When running in detached mode, the action sets the following outputs that can be used in subsequent steps or jobs:

- `ssh-command`: The SSH command to connect to the tmate session
- `ssh-address`: The raw SSH address without the "ssh" prefix
- `web-url`: The web URL to connect to the tmate session (if available)

Example workflow using the SSH command in another job:

```yaml
name: Debug with tmate
on: [push]
jobs:
setup-tmate:
runs-on: ubuntu-latest
outputs:
ssh-command: ${{ steps.tmate.outputs.ssh-command }}
ssh-address: ${{ steps.tmate.outputs.ssh-address }}
steps:
- uses: actions/checkout@v4
- name: Setup tmate session
id: tmate
uses: mxschmitt/action-tmate@v3
with:
detached: true

use-ssh-command:
needs: setup-tmate
runs-on: ubuntu-latest
steps:
- name: Display SSH command
run: |
# Send a Slack message to someone telling them they can ssh to ${{ needs.setup-tmate.outputs.ssh-address }}
```

## Without sudo

By default we run installation commands using sudo on Linux. If you get `sudo: not found` you can use the parameter below to execute the commands directly.
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ inputs:
Also when generating a new PAT, select the least scopes necessary.
[Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
default: ${{ github.token }}

outputs:
ssh-command:
description: 'The SSH command to connect to the tmate session (only set when detached mode is enabled)'
ssh-address:
description: 'The raw SSH address without the "ssh" prefix (only set when detached mode is enabled)'
web-url:
description: 'The web URL to connect to the tmate session (only set when detached mode is enabled and web URL is available)'
Comment on lines +59 to +66
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add this to detached/action.yml.

9 changes: 9 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17602,6 +17602,15 @@ async function run() {
}
core.saveState('message', message)
core.saveState('tmate', tmate)

// Set the SSH command as an output so other jobs can use it
core.setOutput('ssh-command', tmateSSH)
// Extract and set the raw SSH address (without the "ssh" prefix)
core.setOutput('ssh-address', tmateSSH.replace(/^ssh /, ''))
if (tmateWeb) {
core.setOutput('web-url', tmateWeb)
}

console.log(message)
return
}
Expand Down
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ export async function run() {
}
core.saveState('message', message)
core.saveState('tmate', tmate)

// Set the SSH command as an output so other jobs can use it
core.setOutput('ssh-command', tmateSSH)
// Extract and set the raw SSH address (without the "ssh" prefix)
core.setOutput('ssh-address', tmateSSH.replace(/^ssh /, ''))
if (tmateWeb) {
core.setOutput('web-url', tmateWeb)
}

console.log(message)
return
}
Expand Down