Skip to content

Commit f1ae249

Browse files
committed
Add support for output
1 parent 40aba06 commit f1ae249

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,41 @@ 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+
- `web-url`: The web URL to connect to the tmate session (if available)
105+
106+
Example workflow using the SSH command in another job:
107+
108+
```yaml
109+
name: Debug with tmate
110+
on: [push]
111+
jobs:
112+
setup-tmate:
113+
runs-on: ubuntu-latest
114+
outputs:
115+
ssh-command: ${{ steps.tmate.outputs.ssh-command }}
116+
steps:
117+
- uses: actions/checkout@v4
118+
- name: Setup tmate session
119+
id: tmate
120+
uses: mxschmitt/action-tmate@v3
121+
with:
122+
detached: true
123+
124+
use-ssh-command:
125+
needs: setup-tmate
126+
runs-on: ubuntu-latest
127+
steps:
128+
- name: Display SSH command
129+
run: |
130+
echo "Connect to the tmate session with:"
131+
echo ${{ needs.setup-tmate.outputs.ssh-command }}
132+
```
133+
99134
## Without sudo
100135

101136
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ 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+
web-url:
64+
description: 'The web URL to connect to the tmate session (only set when detached mode is enabled and web URL is available)'

lib/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17602,6 +17602,13 @@ 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+
if (tmateWeb) {
17609+
core.setOutput('web-url', tmateWeb)
17610+
}
17611+
1760517612
console.log(message)
1760617613
return
1760717614
}

src/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ 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+
if (tmateWeb) {
223+
core.setOutput('web-url', tmateWeb)
224+
}
225+
219226
console.log(message)
220227
return
221228
}

0 commit comments

Comments
 (0)