1+ name : Setup Zephyr project
2+ description : Setup a Zephyr base project using west and downloading the Zephyr SDK
3+
4+ inputs :
5+ app-path :
6+ description : |
7+ Application code path, should contain a west.yml file if
8+ "manifest-file-name" is not specified, cannot contain multiple
9+ directories (use base-path instead)
10+ required : true
11+
12+ base-path :
13+ description : |
14+ Application base path, should contain the app-path. Defaults to "." if
15+ unspecified
16+ required : false
17+ default : .
18+
19+ ccache-max-size :
20+ description : |
21+ Maximum size of the files stored in the compiler cache (ccache). Defaults to 512MB.
22+ required : false
23+ default : 512MB
24+
25+ enable-ccache :
26+ description : |
27+ Enable caching/restoring of compiler cache (ccache) files between invocations.
28+ Defaults to 'true'.
29+ required : false
30+ default : true
31+
32+ ccache-cache-key :
33+ description : |
34+ An additional string used in the ccache cache key, use it to identify the
35+ cache in a way that makes sense for compiled object cache reuse between
36+ different build workflows. Default to "default".
37+ required : false
38+ default : default
39+
40+ manifest-file-name :
41+ description : Name of the west workspace manifest file name in "app-path"
42+ required : false
43+ default : west.yml
44+
45+ sdk-version :
46+ description : Zephyr SDK version to use or "auto" to detect automatically
47+ required : false
48+ default : auto
49+
50+ sdk-base :
51+ description : Base URL of the Zephyr SDK
52+ required : false
53+ default : https://github.com/zephyrproject-rtos/sdk-ng/releases/download
54+
55+ toolchains :
56+ description : List of toolchains to install, colon separated
57+ required : false
58+ default : arm-zephyr-eabi
59+
60+ west-project-filter :
61+ description : West project filter
62+ required : false
63+ default : " "
64+
65+ west-group-filter :
66+ description : West group filter
67+ required : false
68+ default : " "
69+
70+ west-version :
71+ description : West version to install, latest if omitted
72+ required : false
73+ default : " "
74+
75+ runs :
76+ using : " composite"
77+ steps :
78+ - name : Install dependencies
79+ shell : bash
80+ run : |
81+ if [ "${{ runner.os }}" = "Windows" ]; then
82+ python.exe -m pip install -U pip
83+ fi
84+
85+ pip3 install -U pip wheel
86+
87+ if [ -n "${{ inputs.west-version }}" ]; then
88+ pip3 install west==${{ inputs.west-version }}
89+ else
90+ pip3 install west
91+ fi
92+
93+ if [ "${{ runner.os }}" = "Linux" ]; then
94+ sudo rm -f /var/lib/man-db/auto-update
95+ sudo apt-get update -y
96+ sudo apt-get install -y ninja-build ccache gperf
97+ if [ "${{ runner.arch }}" = "X64" ]; then
98+ sudo apt-get install -y libc6-dev-i386 g++-multilib
99+ fi
100+ elif [ "${{ runner.os }}" = "macOS" ]; then
101+ brew install ninja ccache qemu dtc gperf
102+ elif [ "${{ runner.os }}" = "Windows" ]; then
103+ choco feature enable -n allowGlobalConfirmation
104+ choco install ninja wget gperf
105+ fi
106+
107+ - name : Initialize
108+ working-directory : ${{ inputs.base-path }}
109+ shell : bash
110+ run : |
111+ west init -l ${{ inputs.app-path }} --mf ${{ inputs.manifest-file-name }}
112+ if [ -n "${{ inputs.west-group-filter }}" ]; then
113+ west config manifest.group-filter -- ${{ inputs.west-group-filter }}
114+ fi
115+ if [ -n "${{ inputs.west-project-filter }}" ]; then
116+ west config manifest.project-filter -- ${{ inputs.west-project-filter }}
117+ fi
118+ west update -o=--depth=1 -n
119+
120+ - name : Environment setup
121+ working-directory : ${{ inputs.base-path }}
122+ id : env-setup
123+ shell : bash
124+ run : |
125+ runner="${{ runner.os }}-${{ runner.arch }}"
126+ if [ "$runner" = "Linux-X64" ]; then
127+ sdk_variant="linux-x86_64"
128+ elif [ "$runner" = "Linux-ARM64" ]; then
129+ sdk_variant="linux-aarch64"
130+ elif [ "$runner" = "macOS-X64" ]; then
131+ sdk_variant="macos-x86_64"
132+ elif [ "$runner" = "macOS-ARM64" ]; then
133+ sdk_variant="macos-aarch64"
134+ elif [ "$runner" = "Windows-X64" ]; then
135+ sdk_variant="windows-x86_64"
136+ else
137+ echo "Unsupported runner platform: $runner"
138+ fi
139+
140+ if [ "${{ runner.os }}" = "Linux" ]; then
141+ pip_cache_path="~/.cache/pip"
142+ ccache_path="$HOME/.cache/ccache"
143+ sdk_ext="tar.xz"
144+ setup_file="./setup.sh"
145+ setup_opt="-"
146+ elif [ "${{ runner.os }}" = "macOS" ]; then
147+ pip_cache_path="~/Library/Caches/pip"
148+ ccache_path="$HOME/Library/Caches/ccache"
149+ sdk_ext="tar.xz"
150+ setup_file="./setup.sh"
151+ setup_opt="-"
152+ elif [ "${{ runner.os }}" = "Windows" ]; then
153+ pip_cache_path="~/AppData/Local/pip/Cache"
154+ ccache_path="$HOME/AppData/Local/ccache/Cache"
155+ sdk_ext="7z"
156+ setup_file="./setup.cmd"
157+ setup_opt="//"
158+ fi
159+
160+ if [ "${{ inputs.sdk-version }}" = "auto" ]; then
161+ zephyr_path="zephyr"
162+ if west list -f '{abspath}' zephyr; then
163+ zephyr_path="$( west list -f '{abspath}' zephyr )"
164+ fi
165+
166+ if [ -f "${zephyr_path}/SDK_VERSION" ]; then
167+ echo "Reading SDK version from ${zephyr_path}/SDK_VERSION"
168+ sdk_version=$( cat ${zephyr_path}/SDK_VERSION )
169+ else
170+ echo "Cannot find ${zephyr_path}/SDK_VERSION"
171+ exit 1
172+ fi
173+ else
174+ sdk_version="${{ inputs.sdk-version }}"
175+ fi
176+
177+ echo "SDK_VERSION=${sdk_version}" >> $GITHUB_ENV
178+ echo "SDK_FILE=zephyr-sdk-${sdk_version}_${sdk_variant}_minimal.${sdk_ext}" >> $GITHUB_ENV
179+ echo "PIP_CACHE_PATH=${pip_cache_path}" >> $GITHUB_ENV
180+ echo "CCACHE_TIMESTAMP=$(date +%s)" >> $GITHUB_ENV
181+ echo "CCACHE_DIR=${ccache_path}" >> $GITHUB_ENV
182+ echo "CCACHE_IGNOREOPTIONS=-specs=* --specs=*" >> $GITHUB_ENV
183+ echo "SETUP_FILE=${setup_file}" >> $GITHUB_ENV
184+ echo "SETUP_OPT=${setup_opt}" >> $GITHUB_ENV
185+
186+ - name : Cache Python packages
187+ uses : actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
188+ with :
189+ path : ${{ env.PIP_CACHE_PATH }}
190+ key : pip-${{ runner.os }}-${{ hashFiles(format('{0}/zephyr/scripts/requirements*.txt', inputs.base-path)) }}
191+
192+ - name : Install Python packages
193+ working-directory : ${{ inputs.base-path }}
194+ shell : bash
195+ # The direct use of pip3 should be removed after zephyr 4.1 has been phased out, and the west
196+ # command should only be used instead.
197+ run : |
198+ west packages pip --install --ignore-venv-check || pip3 install -r zephyr/scripts/requirements.txt
199+
200+ - name : Cache Zephyr SDK
201+ id : cache-toolchain
202+ uses : actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
203+ with :
204+ path : ${{ inputs.base-path }}/zephyr-sdk
205+ key : ${{ env.SDK_FILE }}-${{ github.event.repository.name }}-${{ inputs.toolchains }}
206+
207+ - if : ${{ steps.cache-toolchain.outputs.cache-hit != 'true' }}
208+ working-directory : ${{ inputs.base-path }}
209+ name : Download Zephyr SDK
210+ shell : bash
211+ run : |
212+ wget --progress=dot:giga ${{ inputs.sdk-base }}/v${SDK_VERSION}/${SDK_FILE}
213+ rm -rf zephyr-sdk
214+ if [ "${{ runner.os }}" = "Windows" ]; then
215+ 7z x $SDK_FILE
216+ mv zephyr-sdk-${SDK_VERSION} zephyr-sdk
217+ else
218+ mkdir zephyr-sdk
219+ tar xvf $SDK_FILE -C zephyr-sdk --strip-components=1
220+ fi
221+ rm -f $SDK_FILE
222+
223+ - name : Setup Zephyr SDK
224+ working-directory : ${{ inputs.base-path }}/zephyr-sdk
225+ shell : bash
226+ run : |
227+ IFS=":"
228+ TOOLCHAINS="${{ inputs.toolchains }}"
229+ for toolchain in $TOOLCHAINS; do
230+ ${SETUP_FILE} ${SETUP_OPT}t $toolchain
231+ done
232+ if [ ! -d sysroots ]; then
233+ ${SETUP_FILE} ${SETUP_OPT}h
234+ fi
235+ ${SETUP_FILE} ${SETUP_OPT}c
236+
237+ - name : Cache ccache data
238+ if : inputs.enable-ccache == 'true' && runner.os != 'Windows'
239+ uses : actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
240+ with :
241+ path : ${{ env.CCACHE_DIR }}
242+ key : ccache-${{ inputs.ccache-cache-key }}-${{ env.CCACHE_TIMESTAMP }}
243+ restore-keys : ccache-${{ inputs.ccache-cache-key }}-
244+
245+ - name : Set up ccache
246+ if : inputs.enable-ccache == 'true' && runner.os != 'Windows'
247+ shell : bash
248+ run : |
249+ mkdir -p ${{ env.CCACHE_DIR }}
250+ ccache -M ${{ inputs.ccache-max-size }}
251+ ccache -p
252+ ccache -z -s -vv
0 commit comments