-
Notifications
You must be signed in to change notification settings - Fork 337
130 lines (119 loc) · 4.25 KB
/
testAllCI_step1.yml
File metadata and controls
130 lines (119 loc) · 4.25 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
name: cobratoolboxCI (merge, test, and upload)
on:
pull_request:
branches:
- develop
- master
types: [opened, synchronize, reopened]
workflow_dispatch:
permissions:
contents: read
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
build:
runs-on: self-hosted
steps:
- name: Cleanup orphaned MATLAB containers
run: docker ps -q --filter ancestor=matlab | xargs -r docker rm -f
continue-on-error: true
- name: Check out merged PR code
uses: actions/checkout@v6
with:
submodules: recursive
fetch-depth: 0
- name: Fix workspace ownership and permissions for Docker
run: |
sudo chown -R "$(id -u):$(id -g)" "${GITHUB_WORKSPACE}"
chmod -R o+rwx "${GITHUB_WORKSPACE}"
# MATLAB runs inside Docker
- name: Run MATLAB Tests in Docker (licensed MAC, xvfb headless)
env:
QT_QPA_PLATFORM: offscreen
JAVA_AWT_HEADLESS: "1"
run: |
set -euo pipefail
# Confirm MATLAB image exists
docker image inspect matlab >/dev/null
docker run --rm \
--mac-address="02:42:ac:11:00:02" \
--platform linux/amd64 \
-e HOME=/tmp \
-e USER=matlab \
-e LOGNAME=matlab \
-e COBRA_CI=1 \
-e QT_QPA_PLATFORM="${QT_QPA_PLATFORM}" \
-e JAVA_AWT_HEADLESS="${JAVA_AWT_HEADLESS}" \
-v "${GITHUB_WORKSPACE}:/work" \
-w /work \
--entrypoint bash \
matlab \
-lc '
set -euo pipefail
echo "Running inside container as:"
id
echo "HOME=$HOME"
echo "USER=$USER"
mkdir -p /tmp/.matlab /tmp/.MathWorks
echo "Configuring git safe directory..."
git config --global --add safe.directory /work
git config --global --add safe.directory "*"
echo "Starting MATLAB tests..."
xvfb-run -a -s "-screen 0 1280x1024x24" \
matlab -noFigureWindows -batch "try; \
run(\"initCobraToolbox.m\"); \
changeCobraSolver(\"gurobi\",\"all\",0); \
set(0,\"DefaultFigureVisible\",\"off\"); \
run(\"test/testAll.m\"); \
catch ME; \
disp(getReport(ME,\"extended\")); \
exit(1); \
end; \
exit(0);"
'
- name: Fix workspace permissions after Docker run
run: sudo chown -R "$(id -u):$(id -g)" "${GITHUB_WORKSPACE}"
continue-on-error: true
- name: Set up Node.js 20
uses: actions/setup-node@v6
with:
node-version: '20'
- name: Convert JUnit to CTRF
run: |
MAJOR="$(node -p "process.versions.node.split('.')[0]")"
if [ "$MAJOR" -lt 20 ]; then
echo "❌ Node.js version too old: $(node -v)"
exit 1
fi
echo "✅ Node version: $(node -v)"
echo "✅ npm version: $(npm -v)"
mkdir -p ./ctrf
echo "Converting JUnit XML to CTRF JSON..."
npx --yes junit-to-ctrf@0.0.12 ./testReport.junit.xml -o ./ctrf/ctrf-report.json
- name: Normalize CTRF Test Names
run: |
node -e '
const fs = require("fs");
const path = "./ctrf/ctrf-report.json";
const report = JSON.parse(fs.readFileSync(path, "utf8"));
for (const test of report.results?.tests || []) {
if (typeof test.name === "string") {
test.name = test.name.split(": ").pop();
}
}
fs.writeFileSync(path, JSON.stringify(report, null, 2) + "\n");
'
- name: Upload CTRF Artifact
uses: actions/upload-artifact@v6
with:
name: testReport
path: ./ctrf/ctrf-report.json
- name: Save PR Number
run: echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
- name: Upload PR Number as Artifact
run: echo $PR_NUMBER > pr_number.txt
- name: Upload PR Number Artifact
uses: actions/upload-artifact@v6
with:
name: pr_number
path: pr_number.txt