Skip to content

Commit b81e8c4

Browse files
committed
[WIP] ci: Add twister workflow
This commit adds the Twister workflow that can be used to run Zephyr tests on-demand with a specific Zephyr SDK build.
1 parent a827661 commit b81e8c4

File tree

1 file changed

+317
-0
lines changed

1 file changed

+317
-0
lines changed

.github/workflows/twister.yml

Lines changed: 317 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,317 @@
1+
name: Twister
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
sdk-build-job-id:
7+
description: 'SDK Build Job ID'
8+
required: true
9+
sdk-bundle-basename:
10+
description: 'SDK Bundle Base Name'
11+
required: true
12+
default: 'zephyr-sdk-VER'
13+
sdk-toolchain:
14+
description: 'SDK Toolchain'
15+
type: choice
16+
required: true
17+
options:
18+
- gnu
19+
- llvm
20+
default: gnu
21+
zephyr-ref:
22+
description: 'Zephyr Ref (branch, tag, SHA ...)'
23+
required: true
24+
default: collab-sdk-dev
25+
host:
26+
description: 'Host'
27+
type: choice
28+
required: true
29+
options:
30+
- linux-x86_64
31+
- linux-aarch64
32+
- macos-x86_64
33+
- macos-aarch64
34+
- windows-x86_64
35+
default: linux-x86_64
36+
twister-mode:
37+
description: 'Twister Mode'
38+
type: choice
39+
required: true
40+
options:
41+
- integration
42+
- all
43+
default: integration
44+
twister-extra-args:
45+
description: 'Twister Extra Arguments'
46+
required: true
47+
default: '--build-only --show-footprint'
48+
subset-count:
49+
description: 'Subset Count'
50+
required: false
51+
52+
concurrency:
53+
group: ${{ github.run_id }}
54+
cancel-in-progress: false
55+
56+
jobs:
57+
prep:
58+
name: Prep
59+
runs-on: ubuntu-24.04
60+
61+
outputs:
62+
runner: ${{ steps.plan.outputs.runner }}
63+
subset: ${{ steps.plan.outputs.subset }}
64+
size: ${{ steps.plan.outputs.size }}
65+
66+
steps:
67+
- name: Plan
68+
id: plan
69+
run: |
70+
# Resolve runner type
71+
case "${{ github.event.inputs.host }}" in
72+
linux-x86_64) runner="zephyr-runner-v2-linux-x64-4xlarge";;
73+
linux-aarch64) runner="zephyr-runner-v2-linux-arm64-4xlarge";;
74+
macos-x86_64) runner="zephyr-runner-v2-macos-arm64-2xlarge";;
75+
macos-aarch64) runner="zephyr-runner-v2-macos-arm64-2xlarge";;
76+
windows-x86_64) runner="zephyr-runner-v2-windows-x64-2xlarge";;
77+
esac
78+
79+
# Resolve subset count
80+
if [ "${{ github.event.inputs.subset-count }}" != "" ]; then
81+
size="${{ github.event.inputs.subset_count }}"
82+
else
83+
case "${{ github.event.inputs.twister-mode }}" in
84+
integration) size="20";;
85+
all) size="200";;
86+
esac
87+
fi
88+
89+
subset="[ $(seq -s',' 1 ${size}) ]"
90+
91+
# Export output variables
92+
echo "runner=${runner}" >> $GITHUB_OUTPUT
93+
echo "subset=${subset}" >> $GITHUB_OUTPUT
94+
echo "size=${size}" >> $GITHUB_OUTPUT
95+
96+
build:
97+
name: Build (${{ matrix.subset }})
98+
needs: [ plan ]
99+
runs-on:
100+
group: ${{ needs.prep.outputs.runner }}
101+
102+
strategy:
103+
fail-fast: false
104+
matrix:
105+
subset: ${{ needs.prep.outputs.subset }}
106+
107+
steps:
108+
- name: Set up Python
109+
uses: actions/setup-python@v5
110+
with:
111+
# Force Python 3.10, which is the minimum Python version supported by
112+
# Zephyr and intended to be used with Zephyr SDK.
113+
python-version: '3.10'
114+
115+
- name: Set up test environment (Linux)
116+
if: ${{ runner.os == 'Linux' }}
117+
run: |
118+
# Install required system packages
119+
sudo apt-get update
120+
sudo apt-get install -y dos2unix jq
121+
122+
# Set environment variables
123+
echo "TAR=tar" >> $$GITHUB_ENV
124+
125+
- name: Set up test environment (macOS)
126+
if: ${{ runner.os == 'macOS' }}
127+
run: |
128+
# Set environment variables
129+
echo "TAR=gtar" >> $GITHUB_ENV
130+
131+
- name: Set up test environment (Windows)
132+
if: ${{ runner.os == 'Windows' }}
133+
run: |
134+
# Install required system packages
135+
choco install ccache dtc-msys2 gperf jq ninja wget 7zip
136+
137+
# Enable long paths support for Git
138+
git config --system core.longpaths true
139+
140+
- name: Create Python virtual environment
141+
run: |
142+
# Create Python virtual environment
143+
python3 -m venv ${GITHUB_WORKSPACE}/venv
144+
145+
# Resolve activation script path
146+
if [ "${{ runner.os }}" == "Windows" ]; then
147+
VENV_ACTIVATE="${GITHUB_WORKSPACE}/venv/Scripts/activate"
148+
else
149+
VENV_ACTIVATE="${GITHUB_WORKSPACE}/venv/bin/activate"
150+
fi
151+
152+
# Test Python virtual environment
153+
source ${VENV_ACTIVATE}
154+
which python3
155+
which pip3
156+
157+
# Install core components
158+
python3 -m pip install --upgrade pip
159+
pip3 install --upgrade setuptools wheel
160+
161+
# Set environment variables
162+
echo "VENV=${GITHUB_WORKSPACE}/venv" >> $GITHUB_ENV
163+
echo "VENV_ACTIVATE=${VENV_ACTIVATE}" >> $GITHUB_ENV
164+
165+
- name: Resolve distribution bundle name
166+
run: |
167+
BUNDLE_DIR="${{ github.event.inputs.sdk-bundle-basename }}"
168+
BUNDLE_NAME="${BUNDLE_DIR}_${{ github.event.inputs.host }}"
169+
BUNDLE_FILE="${BUNDLE_NAME}_${{ github.event.inputs.sdk-toolchain }}"
170+
171+
if [ "${{ github.event.inputs.host }}" == "windows-x86_64" ]; then
172+
BUNDLE_EXT="7z"
173+
else
174+
BUNDLE_EXT="tar.xz"
175+
fi
176+
177+
echo "BUNDLE_DIR=${BUNDLE_DIR}" >> $GITHUB_ENV
178+
echo "BUNDLE_NAME=${BUNDLE_NAME}" >> $GITHUB_ENV
179+
echo "BUNDLE_FILE=${BUNDLE_FILE}" >> $GITHUB_ENV
180+
echo "BUNDLE_EXT=${BUNDLE_EXT}" >> $GITHUB_ENV
181+
182+
- name: Download distribution bundle
183+
uses: actions/download-artifact@v4
184+
with:
185+
name: ${{ env.BUNDLE_NAME }}
186+
path: artifacts
187+
188+
- name: Install distribution bundle
189+
run: |
190+
# Create tools directory
191+
mkdir -p tools
192+
193+
# Verify distribution bundle archive checksum
194+
pushd artifacts
195+
md5sum --check md5.sum
196+
sha256sum --check sha256.sum
197+
popd
198+
199+
# Extract distribution bundle archive
200+
if [ "${BUNDLE_EXT}" == "tar.xz" ]; then
201+
${TAR} -Jxvf artifacts/${BUNDLE_FILE}.${BUNDLE_EXT} -C tools
202+
elif [ "${BUNDLE_EXT}" == "7z" ]; then
203+
7z x -otools artifacts/${BUNDLE_FILE}.${BUNDLE_EXT}
204+
fi
205+
206+
# Run setup script
207+
pushd tools/${BUNDLE_DIR}
208+
209+
if [ "${{ runner.os }}" == "Windows" ]; then
210+
# Shorten distribution bundle path on Windows
211+
subst s: ${PWD}
212+
pushd /s
213+
# NOTE: Escape forward slashes because MinGW (bash)
214+
# NOTE: A full path (using PWD) must be specified to ensure that the
215+
# setup script is launched from the shortened path.
216+
if [ "${{ matrix.toolchain }}" == "gnu" ]; then
217+
${PWD}/setup.cmd //t all //h //c
218+
elif [ "${{ matrix.toolchain }}" == "llvm" ]; then
219+
${PWD}/setup.cmd //l //h //c
220+
fi
221+
popd
222+
else
223+
if [ "${{ matrix.toolchain }}" == "gnu" ]; then
224+
./setup.sh -t all -h -c
225+
elif [ "${{ matrix.toolchain }}" == "llvm" ]; then
226+
./setup.sh -l -h -c
227+
fi
228+
fi
229+
230+
# Clean up bundle archive to reduce disk usage
231+
rm -f ${ARTIFACT_ROOT}/${BUNDLE_FILE}
232+
233+
popd
234+
235+
- name: Install west
236+
run: |
237+
# Activate Python virtual environment
238+
source ${VENV_ACTIVATE}
239+
240+
# Install or upgrade west
241+
pip3 install --upgrade west
242+
243+
- name: Set up Zephyr repository
244+
run: |
245+
# Activate Python virtual environment
246+
source ${VENV_ACTIVATE}
247+
248+
# Create Zephyr workspace
249+
ZEPHYR_WORKSPACE=${GITHUB_WORKSPACE}/zephyrproject
250+
west init ${ZEPHYR_WORKSPACE}
251+
cd ${ZEPHYR_WORKSPACE}
252+
253+
# Check out specified Zephyr ref
254+
pushd zephyr
255+
git fetch origin ${{ github.event.inputs.zephyr-ref }}
256+
git checkout FETCH_HEAD
257+
popd
258+
259+
# Clone Zephyr repositories
260+
west update
261+
west zephyr-export
262+
263+
# Export variables
264+
echo "ZEPHYR_WORKSPACE=${ZEPHYR_WORKSPACE}" >> $GITHUB_ENV
265+
echo "ZEPHYR_ROOT=${ZEPHYR_WORKSPACE}/zephyr" >> $GITHUB_ENV
266+
267+
- name: Install Python dependencies
268+
run: |
269+
# Activate Python virtual environment
270+
source ${VENV_ACTIVATE}
271+
272+
# Install Python dependencies from the checked out Zephyr repository.
273+
pip3 install -r ${ZEPHYR_ROOT}/scripts/requirements.txt
274+
275+
- name: Run test suites
276+
run: |
277+
# Activate Python virtual environment
278+
source ${VENV_ACTIVATE}
279+
280+
# Create working directory
281+
mkdir -p test
282+
cd test
283+
284+
# Set host-specific twister parameters
285+
if [ "${{ runner.os }}" == "Windows" ]; then
286+
# Shorten twister output paths on Windows in order to work around the
287+
# long path issues
288+
HOST_ARGS+="--short-build-path "
289+
fi
290+
291+
# Set toolchain variant
292+
export ZEPHYR_TOOLCHAIN_VARIANT="zephyr/${{ github.event.input.sdk-toolchain }}"
293+
294+
# Run tests with twister
295+
TWISTER="${ZEPHYR_ROOT}/scripts/twister"
296+
297+
${TWISTER} \
298+
-v \
299+
-N \
300+
-M \
301+
--force-color \
302+
--inline-logs \
303+
--retry-failed 3 \
304+
--retry-build-errors \
305+
--force-toolchain \
306+
--no-detailed-test-id \
307+
--subset ${{ matrix.subset }}/${{ needs.prep.outputs.size }} \
308+
${HOST_ARGS} \
309+
${{ github.event.input.twister-extra-args }}
310+
311+
- name: Publish test results
312+
if: always()
313+
uses: actions/upload-artifact@v4
314+
with:
315+
name: twister_result_subset_${{ matrix.subset }}
316+
if-no-files-found: ignore
317+
path: test/twister-out/twister.xml

0 commit comments

Comments
 (0)