1name: Prepare For a Twister Run
2
3on:
4  workflow_call:
5    outputs:
6      subset:
7        description: subset
8        value: ${{ jobs.prep_push.outputs.subset != '' && jobs.prep_push.outputs.subset ||  jobs.prep_pr.outputs.subset }}
9      size:
10        description: size
11        value: ${{ jobs.prep_push.outputs.size != '' && jobs.prep_push.outputs.size || jobs.prep_pr.outputs.size }}
12      fullrun:
13        description: fullrun
14        value: ${{ jobs.prep_push.outputs.fullrun != '' && jobs.prep_push.outputs.fullrun || jobs.prep_pr.outputs.size }}
15
16jobs:
17  prep_pr:
18    if: github.repository_owner == 'zephyrproject-rtos' && github.event_name == 'pull_request_target'
19    runs-on:
20      group: zephyr-runner-v2-linux-x64-4xlarge
21    container:
22      image: ghcr.io/zephyrproject-rtos/ci-repo-cache:v0.27.4.20241026
23      options: '--entrypoint /bin/bash'
24    outputs:
25      subset: ${{ steps.output-services.outputs.subset }}
26      size: ${{ steps.output-services.outputs.size }}
27      fullrun: ${{ steps.output-services.outputs.fullrun }}
28    env:
29      MATRIX_SIZE: 10
30      PUSH_MATRIX_SIZE: 20
31      DAILY_MATRIX_SIZE: 80
32      BSIM_OUT_PATH: /opt/bsim/
33      BSIM_COMPONENTS_PATH: /opt/bsim/components
34      TESTS_PER_BUILDER: 700
35      COMMIT_RANGE: ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}
36      BASE_REF: ${{ github.base_ref }}
37    steps:
38      - name: Apply container owner mismatch workaround
39        run: |
40          # FIXME: The owner UID of the GITHUB_WORKSPACE directory may not
41          #        match the container user UID because of the way GitHub
42          #        Actions runner is implemented. Remove this workaround when
43          #        GitHub comes up with a fundamental fix for this problem.
44          git config --global --add safe.directory ${GITHUB_WORKSPACE}
45
46      - name: Print cloud service information
47        run: |
48          echo "ZEPHYR_RUNNER_CLOUD_PROVIDER = ${ZEPHYR_RUNNER_CLOUD_PROVIDER}"
49          echo "ZEPHYR_RUNNER_CLOUD_NODE = ${ZEPHYR_RUNNER_CLOUD_NODE}"
50          echo "ZEPHYR_RUNNER_CLOUD_POD = ${ZEPHYR_RUNNER_CLOUD_POD}"
51
52      - name: Clone cached Zephyr repository
53        continue-on-error: true
54        run: |
55          git clone --shared /repo-cache/zephyrproject/zephyr .
56          git remote set-url origin ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}
57
58      - name: Checkout
59        uses: actions/checkout@v4
60        with:
61          ref: ${{ github.event.pull_request.head.sha }}
62          fetch-depth: 0
63          persist-credentials: false
64
65      - name: Environment Setup
66        run: |
67          git config --global user.email "bot@zephyrproject.org"
68          git config --global user.name "Zephyr Bot"
69          rm -fr ".git/rebase-apply"
70          rm -fr ".git/rebase-merge"
71          git rebase origin/${BASE_REF}
72          git clean -f -d
73          git log  --pretty=oneline | head -n 10
74          west init -l . || true
75          west config manifest.group-filter -- +ci,+optional
76          west config --global update.narrow true
77          west update --path-cache /repo-cache/zephyrproject 2>&1 1> west.update.log || west update --path-cache /repo-cache/zephyrproject 2>&1 1> west.update.log || ( rm -rf ../modules ../bootloader ../tools && west update --path-cache /repo-cache/zephyrproject)
78          west forall -c 'git reset --hard HEAD'
79
80          echo "ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-$( cat SDK_VERSION )" >> $GITHUB_ENV
81
82      - name: Generate Test Plan with Twister
83        id: test-plan
84        run: |
85          export ZEPHYR_BASE=${PWD}
86          export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
87          python3 ./scripts/ci/test_plan.py -c origin/${BASE_REF}.. --no-detailed-test-id --pull-request -t $TESTS_PER_BUILDER
88          if [ -s .testplan ]; then
89            cat .testplan >> $GITHUB_ENV
90          else
91            echo "TWISTER_NODES=${MATRIX_SIZE}" >> $GITHUB_ENV
92          fi
93          rm -f testplan.json .testplan
94
95      - name: Determine matrix size
96        id: output-services
97        run: |
98          if [ -n "${TWISTER_NODES}" ]; then
99            subset="[$(seq -s',' 1 ${TWISTER_NODES})]"
100          else
101            subset="[$(seq -s',' 1 ${MATRIX_SIZE})]"
102          fi
103          size=${TWISTER_NODES}
104
105          echo "subset=${subset}" >> $GITHUB_OUTPUT
106          echo "size=${size}" >> $GITHUB_OUTPUT
107          echo "fullrun=${TWISTER_FULL}" >> $GITHUB_OUTPUT
108
109  prep_push:
110    if: github.repository_owner == 'zephyrproject-rtos' && (github.event_name == 'push' || github.event_name == 'schedule')
111    runs-on: ubuntu-22.04
112    outputs:
113      subset: ${{ steps.output-services.outputs.subset }}
114      size: ${{ steps.output-services.outputs.size }}
115      fullrun: ${{ steps.output-services.outputs.fullrun }}
116    env:
117      MATRIX_SIZE: 10
118      PUSH_MATRIX_SIZE: 20
119      DAILY_MATRIX_SIZE: 80
120      BSIM_OUT_PATH: /opt/bsim/
121      BSIM_COMPONENTS_PATH: /opt/bsim/components
122      TESTS_PER_BUILDER: 700
123      COMMIT_RANGE: ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}
124      BASE_REF: ${{ github.base_ref }}
125    steps:
126      - name: Print cloud service information
127        run: |
128          echo "ZEPHYR_RUNNER_CLOUD_PROVIDER = ${ZEPHYR_RUNNER_CLOUD_PROVIDER}"
129          echo "ZEPHYR_RUNNER_CLOUD_NODE = ${ZEPHYR_RUNNER_CLOUD_NODE}"
130          echo "ZEPHYR_RUNNER_CLOUD_POD = ${ZEPHYR_RUNNER_CLOUD_POD}"
131
132      - name: Determine matrix size
133        id: output-services
134        run: |
135          if [ "${{github.event_name}}" = "push" ]; then
136            subset="[$(seq -s',' 1 ${PUSH_MATRIX_SIZE})]"
137            size=${MATRIX_SIZE}
138          elif [ "${{github.event_name}}" = "schedule" -a "${{github.repository}}" = "zephyrproject-rtos/zephyr" ]; then
139            subset="[$(seq -s',' 1 ${DAILY_MATRIX_SIZE})]"
140            size=${DAILY_MATRIX_SIZE}
141          else
142            size=0
143          fi
144
145          echo "subset=${subset}" >> $GITHUB_OUTPUT
146          echo "size=${size}" >> $GITHUB_OUTPUT
147          echo "fullrun=${TWISTER_FULL}" >> $GITHUB_OUTPUT
148