-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
195 lines (167 loc) · 7.04 KB
/
action.yml
File metadata and controls
195 lines (167 loc) · 7.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: Run MATLAB Command with Options
description: >
Run MATLAB commands in CI. Optionally enforce a time limit and treat timeout as success. Supports Linux/macOS runners.
author: >
ZHANG Zaikun (https://www.zhangzk.net)
branding:
icon: play
color: blue
inputs:
command:
description: MATLAB commands to execute (as in matlab-actions/run-command). Multi-line supported.
required: true
timelimit:
description: >
Optional. If set (e.g. 5h, 45m, 300s), terminate the step after this duration and mark it as success.
If empty, no time limit is applied.
required: false
default: ""
working-directory:
description: Optional working directory in which to run the command.
required: false
default: ""
install-run-matlab-command:
description: Install run-matlab-command if it is not found on PATH.
required: false
default: "true"
# Passed through to run-bash-command when timelimit is set
signal:
description: Signal sent when the time limit is reached (passed to timeout/gtimeout).
required: false
default: "TERM"
kill-after:
description: Wait time before sending SIGKILL after signal (passed to timeout/gtimeout).
required: false
default: "30s"
quiet:
description: Reduce log output (passed to run-bash-command).
required: false
default: "false"
outputs:
timed_out:
description: "true if the time limit was reached (and treated as success), else false."
value: ${{ steps.rbc.outputs.timed_out || steps.direct.outputs.timed_out }}
exit_code:
description: "Exit code of the underlying command (124 typically indicates timeout)."
value: ${{ steps.rbc.outputs.exit_code || steps.direct.outputs.exit_code }}
run_matlab_command_path:
description: "Resolved path to run-matlab-command."
value: ${{ steps.install.outputs.rmc_path }}
script_path:
description: "Path to the generated .m script file."
value: ${{ steps.prep.outputs.script_path }}
runs:
using: composite
steps:
- name: Ensure bash
shell: bash
run: |
set -euo pipefail
- name: Install / locate run-matlab-command
id: install
shell: bash
run: |
set -Eeuo pipefail
if command -v run-matlab-command >/dev/null 2>&1; then
rmc_path="$(command -v run-matlab-command)"
echo "Found run-matlab-command at: $rmc_path"
echo "rmc_path=$rmc_path" >> "$GITHUB_OUTPUT"
exit 0
fi
if [[ "${{ inputs.install-run-matlab-command }}" != "true" ]]; then
echo "run-matlab-command not found on PATH and install-run-matlab-command=false."
exit 1
fi
# Determine MathWorks platform code
case "${RUNNER_OS:-}" in
Linux)
oscode="glnxa64"
;;
macOS)
arch="$(uname -m)"
if [[ "$arch" == "x86_64" ]]; then
oscode="maci64"
elif [[ "$arch" == "arm64" ]]; then
oscode="maca64"
else
echo "Unsupported macOS architecture: $arch"
exit 1
fi
;;
*)
echo "Unsupported OS: ${RUNNER_OS:-unknown} (this action supports Linux/macOS only)"
exit 1
;;
esac
# See https://github.com/matlab-actions/run-command/issues/53#issuecomment-3935660870 for
# the URL. Note the "run-matlab-command" binary is undocumented and subject to change in the future.
url="https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/${oscode}/run-matlab-command"
echo "Downloading run-matlab-command from: $url"
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" >&2
echo "WARNING: This URL is corresponding to run-matlab-command v2. Check whether new versions are available!" >&2
echo "WARNING: This binary is not officially documented by MathWorks and may change without notice!" >&2
echo "See https://github.com/matlab-actions/run-command/issues/53#issuecomment-3935660870 for details." >&2
echo "If the binary stops working, consider using the officially supported matlab-batch utility." >&2
echo "matlab-batch needs a MATLAB batch licensing token provided with the MLM_LICENSE_TOKEN environment variable via a secret." >&2
echo "For details on using matlab-batch and MATLAB batch licensing token, see" >&2
echo "https://github.com/matlab-actions#use-matlab-batch-licensing-token" >&2
echo "https://github.com/mathworks-ref-arch/matlab-dockerfile/blob/main/alternates/non-interactive/MATLAB-BATCH.md" >&2
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" >&2
echo ""
base="${RUNNER_TEMP:-$HOME/tmp}"
mkdir -p "$base"
rmc_dir="$(mktemp -d "$base/run-matlab-command.XXXXXX")"
rmc_path="$rmc_dir/run-matlab-command"
echo "Downloading run-matlab-command from:"
echo " $url"
curl -fsSL "$url" -o "$rmc_path"
chmod +x "$rmc_path"
echo "Installed run-matlab-command at: $rmc_path"
echo "$rmc_dir" >> "$GITHUB_PATH"
echo "rmc_path=$rmc_path" >> "$GITHUB_OUTPUT"
- name: Prepare MATLAB script
id: prep
shell: bash
env:
MATLAB_COMMAND: ${{ inputs.command }}
run: |
set -Eeuo pipefail
# Write the MATLAB commands into a temporary .m file (avoids quoting issues)
base="./" # Use current directory for script to respect relative paths in commands
script_path="$base/run_matlab_command_${GITHUB_RUN_ID:-0}_${GITHUB_RUN_ATTEMPT:-0}.m"
printf '%s\n' "$MATLAB_COMMAND" > "$script_path"
# Build MATLAB evaluation string: run('<script_path>');
# Escape single quotes for MATLAB string literals by doubling them.
esc_path="${script_path//\'/\'\'}"
matlab_eval="run('${esc_path}');"
echo "script_path=$script_path" >> "$GITHUB_OUTPUT"
echo "matlab_eval=$matlab_eval" >> "$GITHUB_OUTPUT"
- name: Run MATLAB (no time limit)
id: direct
if: ${{ inputs.timelimit == '' }}
shell: bash
run: |
set -Eeuo pipefail
if [[ -n "${{ inputs.working-directory }}" ]]; then
cd "${{ inputs.working-directory }}"
fi
set +e
run-matlab-command "${{ steps.prep.outputs.matlab_eval }}"
ec=$?
set -e
echo "timed_out=false" >> "$GITHUB_OUTPUT"
echo "exit_code=$ec" >> "$GITHUB_OUTPUT"
exit "$ec"
- name: Run MATLAB with time limit (timeout => success)
id: rbc
if: ${{ inputs.timelimit != '' }}
uses: equipez/run-bash-command@v2
with:
timelimit: ${{ inputs.timelimit }}
signal: ${{ inputs.signal }}
kill-after: ${{ inputs.kill-after }}
working-directory: ${{ inputs.working-directory }}
quiet: ${{ inputs.quiet }}
command: |
run-matlab-command "${{ steps.prep.outputs.matlab_eval }}"