From f31779654ae4509060eaf1116e167a0697f1e2ff Mon Sep 17 00:00:00 2001 From: Kari Hamalainen Date: Mon, 11 Aug 2025 09:10:14 +0300 Subject: [PATCH] ci: add multiplatform twister Add twister workflows Signed-off-by: Kari Hamalainen --- .github/workflows/twister_integration.yaml | 122 +++++++++++++++++++++ .github/workflows/twister_nightly.yaml | 95 ++++++++++++++++ scripts/ci/twister_runner.sh | 51 +++++++++ 3 files changed, 268 insertions(+) create mode 100644 .github/workflows/twister_integration.yaml create mode 100644 .github/workflows/twister_nightly.yaml create mode 100755 scripts/ci/twister_runner.sh diff --git a/.github/workflows/twister_integration.yaml b/.github/workflows/twister_integration.yaml new file mode 100644 index 0000000000..18b43b26e3 --- /dev/null +++ b/.github/workflows/twister_integration.yaml @@ -0,0 +1,122 @@ +name: Twister integration run + +on: + push: + branches: + - main + - v*-branch + pull_request: + branches: + - main + - v*-branch + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + twister-build: + strategy: + fail-fast: false + matrix: +# os: [ubuntu-24.04, macos-14, windows-2022] +# subset: [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] + subset: [1,2] + + runs-on: + - runs-on=${{ github.run_id }} + - runner=4cpu-linux-x64 + + steps: + - name: Set up Python + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 + with: + python-version: 3.12 + + - name: Checkout sources + uses: nrfconnect/action-checkout-west-update@main + with: + git-fetch-depth: 0 + + - name: Setup ncs toolchain + uses: nrfconnect/action-ncs-toolchain-setup@main + + - name: install additional requirements + run: | + sudo apt-get update + sudo apt-get install gcc-multilib + + - name: Run twister + working-directory: ncs + shell: bash + run: | + TOOLCHAIN_BUNDLE_ID=$(./nrf/scripts/print_toolchain_checksum.sh) + ZEPHYR_BASE=${{ github.workspace }}/ncs/zephyr + NRFUTIL="../nrfutil sdk-manager toolchain launch --toolchain-bundle-id $TOOLCHAIN_BUNDLE_ID -- python zephyr/scripts/twister" + $NRFUTIL --ninja --inline-logs --verbose --overflow-as-errors --integration \ + --retry-build-errors --quarantine-list nrf/scripts/quarantine.yaml \ + --quarantine-list nrf/scripts/quarantine_integration.yaml \ + --subset ${{ matrix.subset }}/40 --outdir twister_build --report-dir results_samples -T nrf/samples -T nrf/applications \ + + - name: Prepare Twister artifact (tar) + if: always() + shell: bash + run: | + mkdir -p upload + tar -czf upload/twister-results-${{ matrix.subset }}.tar.gz --exclude='*build.ninja*' \ + ncs/twister_build + + - name: Upload twister + if: always() + id: artifact-upload-step + uses: actions/upload-artifact@v4 + with: + name: Twister results dir ${{matrix.subset}} + if-no-files-found: ignore + include-hidden-files: false + retention-days: 7 + path: | + ncs/results_samples/**/* + upload/twister-results-${{ matrix.subset }}.tar.gz + !ncs/twister_build/**/build.ninja* + + artifact-combination: + needs: twister-build + runs-on: ubuntu-latest + steps: + - name: Download all twister artifacts + uses: actions/download-artifact@v4 + with: + pattern: Twister results dir * + path: artifacts + merge-multiple: true + - name: Combine all artifacts into one tarball + shell: bash + run: | + set -euo pipefail + + mkdir -p combined/twister_build combined/results_samples + + # Merge all results_samples directories into one + find artifacts -type d -path '*/ncs/results_samples' -print0 | while IFS= read -r -d '' dir; do + rsync -a "$dir"/ combined/results_samples/ + done + + # Extract all twister_build tarballs, merging into one twister_build dir + find artifacts -type f -path '*/upload/twister-results-*.tar.gz' -print0 | while IFS= read -r -d '' tarfile; do + # Tar contains ncs/twister_build; strip the leading 'ncs' so we get combined/twister_build/... + tar -xzf "$tarfile" -C combined --strip-components=1 + done + + # Create a single compressed archive containing combined results and builds + tar -czf twister-combined-artifacts.tar.gz -C combined . + + - name: Upload combined twister artifact + uses: actions/upload-artifact@v4 + with: + name: Twister combined results + retention-days: 7 + path: twister-combined-artifacts.tar.gz diff --git a/.github/workflows/twister_nightly.yaml b/.github/workflows/twister_nightly.yaml new file mode 100644 index 0000000000..ea56cdbfc9 --- /dev/null +++ b/.github/workflows/twister_nightly.yaml @@ -0,0 +1,95 @@ +name: Twister nightly multiplatform + +on: + workflow_dispatch: +# push: +# branches: +# - main +# - v*-branch + pull_request: + branches: + - main + - v*-branch + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + twister-build: + strategy: + fail-fast: false + matrix: + os: [linux] + subset: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] + include: + - os: linux + runner: '["runner=16cpu-linux-x64/runs-on=${{ github.run_id }}/volume=250gb"]' +# - os: windows +# runner: '["windows-2022"]' +# - os: macos +# runner: '["macos-15"]' + + + runs-on: ${{ fromJson(matrix.runner) }} + steps: + - name: Set up Python + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 + with: + python-version: 3.12 + + - name: Checkout sources + uses: nrfconnect/action-checkout-west-update@main + with: + git-fetch-depth: 0 + + - name: Setup ncs toolchain + uses: nrfconnect/action-ncs-toolchain-setup@main + + - name: Run twister + working-directory: ncs + shell: bash + run: | + nrf/scripts/ci/twister_runner.sh tb ${{ matrix.subset }}/20 + +# run: | +# TOOLCHAIN_BUNDLE_ID=$(./nrf/scripts/print_toolchain_checksum.sh) +# ZEPHYR_BASE=${{ github.workspace }}/ncs/zephyr +# if [ "${{ runner.os }}" = "macOS" ]; then +# EXTRA_TWISTER_FLAGS="--quarantine-list nrf/scripts/quarantine_windows_mac.yaml" +# NRFUTIL="sudo ../nrfutil sdk-manager toolchain launch --toolchain-bundle-id $TOOLCHAIN_BUNDLE_ID -- python zephyr/scripts/twister " +# elif [ "${{ runner.os }}" = "Windows" ]; then +# export PYTHONUTF8=1 +# EXTRA_TWISTER_FLAGS="--short-build-path --quarantine-list nrf\scripts\quarantine_windows_mac.yaml --no-detailed-test-id" +# NRFUTIL="../nrfutil.exe sdk-manager toolchain launch --toolchain-bundle-id $TOOLCHAIN_BUNDLE_ID -- python zephyr/scripts/twister" +# else +# EXTRA_TWISTER_FLAGS="" +# NRFUTIL="../nrfutil sdk-manager toolchain launch --toolchain-bundle-id $TOOLCHAIN_BUNDLE_ID -- python zephyr/scripts/twister" +# sudo apt-get install gcc-multilib +# fi +# $NRFUTIL --ninja --inline-logs --verbose --overflow-as-errors --integration \ +# --retry-build-errors --quarantine-list nrf/scripts/quarantine.yaml \ +# --quarantine-list nrf/scripts/quarantine_integration.yaml \ +# --subset ${{ matrix.subset }}/40 --outdir twister_build --report-dir results_samples -T nrf/samples -T nrf/applications \ +# -v $EXTRA_TWISTER_FLAGS + + + - name: Upload twister + if: always() + id: artifact-upload-step + uses: actions/upload-artifact@v4 + with: + name: Twister results dir ${{ runner.os }} ${{matrix.subset}} + if-no-files-found: ignore + include-hidden-files: false + retention-days: 7 + path: | + ncs/results_samples/**/* + !ncs/twister_build/**/build.ninja* + ncs/tb/**/*.hex + ncs/tb/**/build.log + + diff --git a/scripts/ci/twister_runner.sh b/scripts/ci/twister_runner.sh new file mode 100755 index 0000000000..e14c42a633 --- /dev/null +++ b/scripts/ci/twister_runner.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -euo pipefail + +# --- Usage check --- +if [[ $# -ne 2 ]]; then + echo "Usage: $0 " + echo "Example: $0 twister_build 5/40" + exit 1 +fi + +OUTDIR=$1 +SUBSET=$2 + +EXTRA_FLAGS="" +NRFUTIL="" +OS="$(uname)" +TOOLCHAIN_BUNDLE_ID=$(./nrf/scripts/print_toolchain_checksum.sh) + +echo "Detected OS: $OS" +echo "Toolchain bundle: $TOOLCHAIN_BUNDLE_ID" +echo "Using subset: $SUBSET" +echo "Output dir: $OUTDIR" + +# Detect OS and set OS-specific commands +case "$(uname -s)" in + MINGW*) + EXTRA_FLAGS="--short-build-path --quarantine-list nrf\\scripts\\quarantine_windows_mac.yaml --no-detailed-test-id" + export PYTHONUTF8=1 + NRFUTIL="../nrfutil.exe sdk-manager toolchain launch --toolchain-bundle-id $TOOLCHAIN_BUNDLE_ID -- python zephyr\\scripts\\twister" + ;; + Linux*) + sudo apt-get update && sudo apt-get install gcc-multilib + EXTRA_FLAGS="--jobs 8" + NRFUTIL="../nrfutil sdk-manager toolchain launch --toolchain-bundle-id $TOOLCHAIN_BUNDLE_ID -- python zephyr/scripts/twister" + ;; + Darwin*) + EXTRA_FLAGS="--quarantine-list nrf/scripts/quarantine_windows_mac.yaml" + NRFUTIL="sudo ../nrfutil sdk-manager toolchain launch --toolchain-bundle-id $TOOLCHAIN_BUNDLE_ID -- python zephyr/scripts/twister" + ;; + *) + echo "Unsupported OS: $(uname -s)" + exit 1 + ;; +esac + +set -x +$NRFUTIL --ninja --inline-logs --verbose --overflow-as-errors --integration \ + --retry-build-errors \ + --quarantine-list nrf/scripts/quarantine.yaml \ + --subset "$SUBSET" --outdir "$OUTDIR" --report-dir results_samples \ + -T nrf/samples -T nrf/applications $EXTRA_FLAGS