Skip to content

Commit 5aa87dc

Browse files
yanksyoonvadi2dave-gray101dschochenrui333
authored
chore: sync upstream (#12)
* Don't create /continue on macOS * add connect-timeout variable Signed-off-by: Dave Lee <[email protected]> * run the build Signed-off-by: Dave Lee <[email protected]> * action.yml Signed-off-by: Dave Lee <[email protected]> * connect-timeout-seconds is a better name Signed-off-by: Dave Lee <[email protected]> * chore(deps): bump to use actions/checkout v4 (node20 runtime) (mxschmitt#197) * chore(deps-dev): bump braces from 3.0.2 to 3.0.3 (mxschmitt#196) * chore(deps-dev): bump micromatch from 4.0.5 to 4.0.8 (mxschmitt#201) * Adding support for RHEL-based distributions Signed-off-by: Loic Pottier <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> * chore(deps-dev): bump cross-spawn from 7.0.3 to 7.0.5 (mxschmitt#207) * add new input msys2-location add new msys2-location input and use instead of hardcoding c:\msys64 * Update README.md with new input * Update index.js * use msys2-location input in didTmateQuit and continueFileExists * Offer `mxschmitt/action-tmate/detached` for convenience The `mxschmitt/action-tmate/detached` Action does exactly the same as the `mxschmitt/action-tmate` Action, except defaulting to detached mode. This will come in handy in the increasingly many cases I seem to experience of late where I want to use the detached mode without the price of adding a `with` section. Not a big price, but it accumulates. Signed-off-by: Johannes Schindelin <[email protected]> * README: document the `mxschmitt/action-tmate/detached` Action This "sub-"Action merely switches the default to `detached: true`. Which is so much more convenient than having to add a `with:` section _just_ for that mode. Signed-off-by: Johannes Schindelin <[email protected]> * ci(manual-detached-test): use the `./detached` "sub-Action" Signed-off-by: Johannes Schindelin <[email protected]> * ci(manual-detached-test): drop no-longer-needed setting We now limit access to the actor by default, iff the actor has a public SSH key registered in their GitHub profile. Signed-off-by: Johannes Schindelin <[email protected]> * ci(manual-test): stop mentioning the obsolete ubuntu-20.04 pool It has gone to the ~Google~GitHub Graveyard. Signed-off-by: Johannes Schindelin <[email protected]> * Add support for output * Add ssh to output * (feature) Add outputs to detached action as well * ci: verify that the `action.yml` files are in sync In mxschmitt#218, I added a convenient way to launch this Action in detached mode: `mxschmitt/action-tmate/detached@v3`. The way this is implemented is a copy/edited version of `action.yml` in the `detached/` subdirectory. This runs the danger of inadvertent divergences, as happened in mxschmitt#221 (which I caught in time and the contributor gracefully addressed). Let's add automation not only to update the file easily but also to cause a failure in the PR build with a helpful message suggesting how to fix the problem. Signed-off-by: Johannes Schindelin <[email protected]> * detached/action.yml: synchronize with `action.yml` There was a difference in whitespace, caught by the new step in `checkin.yml`. Signed-off-by: Johannes Schindelin <[email protected]> * ci: fix 'Verify that the project is built' The output of that step, if something goes wrong, claims that `dist/` is not up to date, but the build product is in `lib/`. Also, `git status -s` shows not only differences in the tracked files, but also untracked files (which should not exist at that stage). Let's avoid puzzling contributors when there are untracked files by logging the output of `git status -s`. Signed-off-by: Johannes Schindelin <[email protected]> * ci(manual-test): update list of runner images See https://github.com/actions/runner-images/blob/310e8e963731084df01bcbdbd5044a5ca7fc0c88/README.md#available-images. * ci(manual-test): convert from a matrix job to a single job With this change, the `manual-test` workflow accepts user input as to what runner OS or Docker image to run on. It is more useful this way, too, as I never encountered a situation where I would want to run this Action on multiple runners, having to log in concurrently into multiple tmate sessions, and I doubt that anyone else has encountered that situation, either. Signed-off-by: Johannes Schindelin <[email protected]> * Add a node.js script to update manual-test's `runs-on` options As I had suggested in mxschmitt#224 (comment), it would be good to have some sort of automation to update the ever-changing list of runner pools that are supported by GitHub. Signed-off-by: Johannes Schindelin <[email protected]> * ci(manual-test): update `runs-on` options Brought to you by the new `update-manual-test.js` script. Signed-off-by: Johannes Schindelin <[email protected]> * update-manual-test: special-case Windows/ARM64 runners For a little more than two weeks, as of time of writing, there are GitHub-hosted Windows/ARM64 runners (at long last!), announced here: https://github.blog/changelog/2025-04-14-windows-arm64-hosted-runners-now-available-in-public-preview/ These are not yet listed in the `runner-images` README, therefore we want to add them manually. Signed-off-by: Johannes Schindelin <[email protected]> * manual-test: install MSYS2 on Windows/ARM64 The Windows/ARM64 runners that are currently in public preview do not have MSYS2 installed by default, so let's do that. Signed-off-by: Johannes Schindelin <[email protected]> --------- Signed-off-by: Dave Lee <[email protected]> Signed-off-by: Loic Pottier <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Co-authored-by: Vadim Peretokin <[email protected]> Co-authored-by: Dave Lee <[email protected]> Co-authored-by: Johannes Schindelin <[email protected]> Co-authored-by: Rui Chen <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Loic Pottier <[email protected]> Co-authored-by: jeremyd2019 <[email protected]> Co-authored-by: Max schwenk <[email protected]> Co-authored-by: Yukai Chou <[email protected]>
1 parent 366d153 commit 5aa87dc

File tree

12 files changed

+1685
-1380
lines changed

12 files changed

+1685
-1380
lines changed

.github/workflows/checkin.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v3
11+
- uses: actions/checkout@v4
1212
- name: Use Node.js
1313
uses: actions/setup-node@v3
1414
with:
1515
node-version: 20
16+
- name: Verify that action.yml files are in sync
17+
run: |
18+
npm run update-detached-action.yml &&
19+
if ! git diff --exit-code \*action.yml
20+
then
21+
echo '::error::action.yml files are not in sync, maybe run `npm run update-detached-action.yml`?'
22+
exit 1
23+
fi
1624
- name: Install dependencies
1725
run: npm ci
1826
- name: Run tests
@@ -24,7 +32,8 @@ jobs:
2432
- name: Verify that the project is built
2533
run: |
2634
if [[ -n $(git status -s) ]]; then
27-
echo "ERROR: generated dist/ differs from the current sources"
35+
echo "ERROR: generated lib/ differs from the current sources"
36+
git status -s
2837
git diff
2938
exit 1
3039
fi

.github/workflows/manual-detached-test.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ jobs:
55
test:
66
runs-on: ubuntu-latest
77
steps:
8-
- uses: actions/checkout@v3
9-
- uses: ./
8+
- uses: actions/checkout@v4
9+
- uses: ./detached
1010
with:
11-
limit-access-to-actor: true
12-
detached: true
11+
connect-timeout-seconds: 60
1312
- run: |
1413
echo "A busy loop"
1514
for value in $(seq 10)

.github/workflows/manual-test.yml

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,73 @@
1-
name: Manual test matrix
2-
on: workflow_dispatch
1+
name: Manual test
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
runs-on:
6+
type: choice
7+
description: 'The runner pool to run the job on'
8+
required: true
9+
default: ubuntu-24.04
10+
options:
11+
- ubuntu-24.04
12+
- ubuntu-22.04
13+
- macos-15-large
14+
- macos-15
15+
- macos-14-large
16+
- macos-14
17+
- macos-13
18+
- macos-13-xlarge
19+
- windows-2025
20+
- windows-2022
21+
- windows-2019
22+
- windows-11-arm
23+
container-runs-on:
24+
type: choice
25+
description: 'The Docker container to run the job on (this overrides the `runs-on` input)'
26+
required: false
27+
default: '(none)'
28+
options:
29+
- '(none)'
30+
- fedora:latest
31+
- archlinux:latest
32+
- ubuntu:latest
33+
limit-access-to-actor:
34+
type: choice
35+
description: 'Whether to limit access to the actor only'
36+
required: true
37+
default: 'auto'
38+
options:
39+
- auto
40+
- 'true'
41+
- 'false'
342

443
jobs:
544
test:
6-
strategy:
7-
fail-fast: false
8-
matrix:
9-
runs-on:
10-
- ubuntu-20.04
11-
- ubuntu-22.04
12-
- macos-11.0
13-
- macos-12.0
14-
- windows-2019
15-
- windows-2022
16-
limit-access-to-actor:
17-
- true
18-
- false
19-
runs-on: ${{ matrix.runs-on }}
45+
if: ${{ inputs.container-runs-on == '(none)' }}
46+
runs-on: ${{ inputs.runs-on }}
2047
steps:
21-
- uses: actions/checkout@v3
48+
- uses: msys2/setup-msys2@v2
49+
# The public preview of GitHub-hosted Windows/ARM64 runners lacks
50+
# a working MSYS2 installation, so we need to set it up ourselves.
51+
if: ${{ inputs.runs-on == 'windows-11-arm' }}
52+
with:
53+
msystem: 'CLANGARM64'
54+
# We cannot use `C:\` because `msys2/setup-msys2` erroneously
55+
# believes that an MSYS2 exists at `C:\msys64`, but it doesn't,
56+
# which is the entire reason why we need to set it up in this
57+
# here step... However, by using `C:\.\` we can fool that
58+
# overzealous check.
59+
location: C:\.\
60+
- uses: actions/checkout@v4
2261
- uses: ./
2362
with:
24-
limit-access-to-actor: ${{ matrix.limit-access-to-actor }}
63+
limit-access-to-actor: ${{ inputs.limit-access-to-actor }}
2564
test-container:
26-
strategy:
27-
fail-fast: false
28-
matrix:
29-
container-runs-on:
30-
- fedora:latest
31-
- archlinux:latest
32-
- ubuntu:latest
33-
limit-access-to-actor:
34-
- true
35-
- false
65+
if: ${{ inputs.container-runs-on != '(none)' }}
3666
runs-on: ubuntu-latest
3767
container:
38-
image: ${{ matrix.container-runs-on }}
68+
image: ${{ inputs.container-runs-on }}
3969
steps:
40-
- uses: actions/checkout@v3
70+
- uses: actions/checkout@v4
4171
- uses: ./
4272
with:
43-
limit-access-to-actor: ${{ matrix.limit-access-to-actor }}
73+
limit-access-to-actor: ${{ inputs.limit-access-to-actor }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env node
2+
3+
// Update the `runs-on` options of the `manual-test.yml` workflow file with the
4+
// latest available images from the GitHub Actions runner images README file.
5+
6+
(async () => {
7+
const fs = require('fs')
8+
9+
const readme = await (await fetch("https://github.com/actions/runner-images/raw/HEAD/README.md")).text()
10+
11+
// This will be the first `ubuntu` one.
12+
let defaultOption = ''
13+
14+
const choices = readme
15+
// Get the "Available Images" section
16+
.split(/\n## Available Images\n/)[1]
17+
.split(/##\s*[^#]/)[0]
18+
// Split by lines
19+
.split('\n')
20+
.map(line => {
21+
// The relevant lines are table rows; The first column is the image name,
22+
// the second one contains a relatively free-form list of the `runs-on`
23+
// options that we are interested in. Those `runs-on` options are
24+
// surrounded by backticks.
25+
const match = line.match(/^\|\s*([^|]+)\s*\|([^|]*)`([^`|]+)`\s*\|/)
26+
if (!match) return false // Skip e.g. the table header and empty lines
27+
let runsOn = match[3] // default to the last `runs-on` option
28+
const alternatives = match[2]
29+
.split(/`([^`]*)`/) // split by backticks
30+
.filter((_, i) => (i % 2)) // keep only the text between backticks
31+
.sort((a, b) => a.length - b.length) // order by length
32+
if (alternatives.length > 0 && alternatives[0].length < runsOn.length) runsOn = alternatives[0]
33+
if (!defaultOption && match[3].startsWith('ubuntu-')) defaultOption = runsOn
34+
return runsOn
35+
})
36+
.filter(runsOn => runsOn)
37+
38+
// The Windows/ARM64 runners are in public preview (and for the time being,
39+
// not listed in the `runner-images` README file), so we need to add this
40+
// manually.
41+
if (!choices.includes('windows-11-arm')) choices.push('windows-11-arm')
42+
43+
// Now edit the `manual-test` workflow definition
44+
const ymlPath = `${__dirname}/manual-test.yml`
45+
const yml = fs.readFileSync(ymlPath, 'utf8')
46+
47+
// We want to replace the `runs-on` options and the `default` value. This
48+
// would be easy if there was a built-in YAML parser and renderer in Node.js,
49+
// but there is none. Therefore, we use a regular expression to find certain
50+
// "needles" near the beginning of the file: first `workflow_dispatch:`,
51+
// after that `runs-on:` and then `default:` and `options:`. Then we replace
52+
// the `default` value and the `options` values with the new ones.
53+
const [, beforeDefault, beforeOptions, optionsIndent, afterOptions] =
54+
yml.match(/^([^]*?workflow_dispatch:[^]*?runs-on:[^]*?default:)(?:.*)([^]*?options:)(\n +- )(?:.*)(?:\3.*)*([^]*)/) || []
55+
if (!beforeDefault) throw new Error(`The 'manual-test.yml' file does not match the expected format!`)
56+
const newYML =
57+
`${beforeDefault} ${defaultOption}${[beforeOptions, ...choices].join(optionsIndent)}${afterOptions}`
58+
fs.writeFileSync(ymlPath, newYML)
59+
})().catch(e => {
60+
console.error(e)
61+
process.exitCode = 1
62+
})

README.md

Lines changed: 83 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
build:
3434
runs-on: self-hosted
3535
steps:
36-
- uses: actions/checkout@v3
36+
- uses: actions/checkout@v4
3737
- name: Setup tmate session
3838
uses: canonical/action-tmate@main
3939
```
@@ -91,7 +91,7 @@ jobs:
9191
build:
9292
runs-on: self-hosted
9393
steps:
94-
- uses: actions/checkout@v3
94+
- uses: actions/checkout@v4
9595
- name: Setup tmate session
9696
uses: canonical/action-tmate@main
9797
with:
@@ -100,6 +100,44 @@ jobs:
100100

101101
By default, this mode will wait at the end of the job for a user to connect and then to terminate the tmate session. If no user has connected within 10 minutes after the post-job step started, it will terminate the `tmate` session and quit gracefully.
102102

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

105143
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.
@@ -111,7 +149,7 @@ jobs:
111149
build:
112150
runs-on: self-hosted
113151
steps:
114-
- uses: actions/checkout@v3
152+
- uses: actions/checkout@v4
115153
- name: Setup tmate session
116154
uses: canonical/action-tmate@main
117155
with:
@@ -129,7 +167,7 @@ jobs:
129167
build:
130168
runs-on: self-hosted
131169
steps:
132-
- uses: actions/checkout@v3
170+
- uses: actions/checkout@v4
133171
- name: Setup tmate session
134172
uses: canonical/action-tmate@main
135173
timeout-minutes: 15
@@ -148,7 +186,7 @@ jobs:
148186
build:
149187
runs-on: self-hosted
150188
steps:
151-
- uses: actions/checkout@v3
189+
- uses: actions/checkout@v4
152190
- name: Setup tmate session
153191
if: ${{ failure() }}
154192
uses: canonical/action-tmate@main
@@ -157,6 +195,26 @@ jobs:
157195
{% endraw %}
158196
-->
159197

198+
## Use registered public SSH key(s)
199+
200+
If [you have registered one or more public SSH keys with your GitHub profile](https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account), tmate will be started such that only those keys are authorized to connect, otherwise anybody can connect to the tmate session. If you want to require a public SSH key to be installed with the tmate session, no matter whether the user who started the workflow has registered any in their GitHub profile, you will need to configure the setting `limit-access-to-actor` to `true`, like so:
201+
202+
```yaml
203+
name: CI
204+
on: [push]
205+
jobs:
206+
build:
207+
runs-on: ubuntu-latest
208+
steps:
209+
- uses: actions/checkout@v4
210+
- name: Setup tmate session
211+
uses: canonical/action-tmate@v3
212+
with:
213+
limit-access-to-actor: true
214+
```
215+
216+
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>`.
217+
160218
## Use your own tmate servers
161219

162220
By default, this action uses environment variables to pick up tmate ssh configuration settings and
@@ -169,7 +227,7 @@ jobs:
169227
build:
170228
runs-on: ubuntu-latest
171229
steps:
172-
- uses: actions/checkout@v3
230+
- uses: actions/checkout@v4
173231
- name: Setup tmate session
174232
uses: canonical/action-tmate@main
175233
with:
@@ -179,9 +237,27 @@ jobs:
179237
- tmate-server-ed25519-fingerprint: SHA256:jfttvoypkHiQYUqUCwKeqd9d1fJj/ZiQlFOHVl6E9sI
180238
```
181239

240+
## Use a different MSYS2 location
241+
242+
If you want to integrate with the msys2/setup-msys2 action or otherwise don't have an MSYS2 installation at `C:\msys64`, you can specify a different location for MSYS2:
243+
244+
```yaml
245+
name: CI
246+
on: [push]
247+
jobs:
248+
build:
249+
runs-on: windows-latest
250+
steps:
251+
- uses: msys2/setup-msys2@v2
252+
id: setup-msys2
253+
- uses: mxschmitt/action-tmate@v3
254+
with:
255+
msys2-location: ${{ steps.setup-msys2.outputs.msys2-location }}
256+
```
257+
182258
## Continue a workflow
183259

184-
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`.
260+
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` (on Linux).
185261

186262
## Connection string / URL is not visible
187263

0 commit comments

Comments
 (0)