Skip to content

Commit 3f6efa8

Browse files
authored
Merge pull request #221 from maschwenk/mfs-add-support-for-output
In complex corporate setups, it is not uncommon that CI processes are designed to notify engineers at strategic times during lengthy workflows. To integrate `action-tmate` in such a process, it is necessary to have vital information (such as the SSH address) at hand, to be able to, say, send a Slack message to the person who will most likely want to connect to the tmate session. This PR adds support for that, by providing said information via Action outputs.
2 parents 40aba06 + fda7fb3 commit 3f6efa8

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,42 @@ By default, this mode will wait at the end of the job for a user to connect and
9696

9797
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.
9898

99+
### Using SSH command output in other jobs
100+
101+
When running in detached mode, the action sets the following outputs that can be used in subsequent steps or jobs:
102+
103+
- `ssh-command`: The SSH command to connect to the tmate session
104+
- `ssh-address`: The raw SSH address without the "ssh" prefix
105+
- `web-url`: The web URL to connect to the tmate session (if available)
106+
107+
Example workflow using the SSH command in another job:
108+
109+
```yaml
110+
name: Debug with tmate
111+
on: [push]
112+
jobs:
113+
setup-tmate:
114+
runs-on: ubuntu-latest
115+
outputs:
116+
ssh-command: ${{ steps.tmate.outputs.ssh-command }}
117+
ssh-address: ${{ steps.tmate.outputs.ssh-address }}
118+
steps:
119+
- uses: actions/checkout@v4
120+
- name: Setup tmate session
121+
id: tmate
122+
uses: mxschmitt/action-tmate@v3
123+
with:
124+
detached: true
125+
126+
use-ssh-command:
127+
needs: setup-tmate
128+
runs-on: ubuntu-latest
129+
steps:
130+
- name: Display SSH command
131+
run: |
132+
# Send a Slack message to someone telling them they can ssh to ${{ needs.setup-tmate.outputs.ssh-address }}
133+
```
134+
99135
## Without sudo
100136

101137
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.

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,11 @@ inputs:
5656
Also when generating a new PAT, select the least scopes necessary.
5757
[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)
5858
default: ${{ github.token }}
59+
60+
outputs:
61+
ssh-command:
62+
description: 'The SSH command to connect to the tmate session (only set when detached mode is enabled)'
63+
ssh-address:
64+
description: 'The raw SSH address without the "ssh" prefix (only set when detached mode is enabled)'
65+
web-url:
66+
description: 'The web URL to connect to the tmate session (only set when detached mode is enabled and web URL is available)'

detached/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,11 @@ inputs:
5757
[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)
5858
default: ${{ github.token }}
5959

60+
outputs:
61+
ssh-command:
62+
description: 'The SSH command to connect to the tmate session (only set when detached mode is enabled)'
63+
ssh-address:
64+
description: 'The raw SSH address without the "ssh" prefix (only set when detached mode is enabled)'
65+
web-url:
66+
description: 'The web URL to connect to the tmate session (only set when detached mode is enabled and web URL is available)'
67+

lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17602,6 +17602,15 @@ async function run() {
1760217602
}
1760317603
core.saveState('message', message)
1760417604
core.saveState('tmate', tmate)
17605+
17606+
// Set the SSH command as an output so other jobs can use it
17607+
core.setOutput('ssh-command', tmateSSH)
17608+
// Extract and set the raw SSH address (without the "ssh" prefix)
17609+
core.setOutput('ssh-address', tmateSSH.replace(/^ssh /, ''))
17610+
if (tmateWeb) {
17611+
core.setOutput('web-url', tmateWeb)
17612+
}
17613+
1760517614
console.log(message)
1760617615
return
1760717616
}

src/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@ export async function run() {
216216
}
217217
core.saveState('message', message)
218218
core.saveState('tmate', tmate)
219+
220+
// Set the SSH command as an output so other jobs can use it
221+
core.setOutput('ssh-command', tmateSSH)
222+
// Extract and set the raw SSH address (without the "ssh" prefix)
223+
core.setOutput('ssh-address', tmateSSH.replace(/^ssh /, ''))
224+
if (tmateWeb) {
225+
core.setOutput('web-url', tmateWeb)
226+
}
227+
219228
console.log(message)
220229
return
221230
}

0 commit comments

Comments
 (0)