Last active
November 27, 2024 02:55
-
-
Save cfriedt/69e15671cd61e1e6295ddc1a4958dd0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) 2024 Tenstorrent, Inc. | |
# SPDX-License-Identifier: Apache-2.0 | |
variables: | |
# sdk version, path, etc are tied to the zephyr-build image tag | |
ZEPHYR_BUILD_CONTAINER_TAG: "v0.27.4" | |
ZEPHYR_BUILD_CONTAINER: "docker.io/zephyrprojectrtos/ci:${ZEPHYR_BUILD_CONTAINER_TAG}" | |
ZEPHYR_SDK_VERSION: "0.17.0" | |
ZEPHYR_TOOLCHAIN_VARIANT: "zephyr" | |
ZEPHYR_SDK_INSTALL_DIR: "/opt/toolchains/zephyr-sdk-${ZEPHYR_SDK_VERSION}" | |
# this is the default directory for builds in the zephyr-build container | |
WEST_WORKSPACE: "/workdir/zephyrproject" | |
ZEPHYR_BASE: "${WEST_WORKSPACE}/zephyr" | |
.default_rules: | |
rules: | |
# to make merge train work | |
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' | |
- if: $CI_COMMIT_TAG | |
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH | |
.default_before_script: | |
before_script: | | |
# to get around the following error | |
# fatal: detected dubious ownership in repository at '/builds/syseng-platform/bh-bmfw' | |
git config --global --add safe.directory '*' | |
# To avoid the following warning | |
# You are in 'detached HEAD' state. | |
# ... | |
# Turn off this advice by setting config variable advice.detachedHead to false | |
git config --global advice.detachedHead false | |
# workaround for the following error | |
# ccache: error: failed to create temporary file for /ccache/tmp/cpp_stdout.tmp.CsrLM7.i: Permission denied | |
sudo mkdir -p /ccache | |
sudo chown -R 1000:1000 /ccache | |
# ensure we have a (hopefully functional) west.yml | |
if [ ! -f west.yml ]; then | |
echo "no west.yml file present" | |
exit 1 | |
fi | |
# We cannot use 'west init -m <url>' because that will not reflect the changes in the current PR | |
# Additionally, we cannot init from url because the runner may lack credentials. | |
# We cannot use 'west init -l .' because the .west/config will be created in ${CI_BUILDS_DIR}/${CI_NAMESPACE_DIR} | |
# which will cause conflicts with other gitlab runners. | |
# This is a bit of a workaround. | |
mkdir -p "${WEST_WORKSPACE}" | |
cd "${WEST_WORKSPACE}" | |
mv "${CI_PROJECT_DIR}" "${CI_PROJECT_NAME}" | |
west init -l "${CI_PROJECT_NAME}" | |
# enable optional modules from upstream | |
west config manifest.group-filter -- +optional | |
# clone projects listed in this repository's west.yml | |
west update | |
# the workaround continues.. | |
mv "${CI_PROJECT_NAME}" "${CI_PROJECT_DIR}" | |
ln -sf "${CI_PROJECT_DIR}" "${WEST_WORKSPACE}/modules/${CI_PROJECT_NAME}" | |
sed -i -e "s|.*path.*|path = modules/${CI_PROJECT_NAME}|" .west/config | |
# if zephyr/patches.yml and zephyr/patches exist, apply patches | |
if [ -d "${WEST_WORKSPACE}/modules/${CI_PROJECT_NAME}/zephyr/patches" ] && [ -f "${WEST_WORKSPACE}/modules/${CI_PROJECT_NAME}/zephyr/patches.yml" ]; then | |
wget -O /tmp/apply_patches.py 'https://bit.ly/3Zb5DPs' | |
chmod +x /tmp/apply_patches.py | |
/tmp/apply_patches.py -b "${WEST_WORKSPACE}/modules/${CI_PROJECT_NAME}/zephyr/patches" -l "${WEST_WORKSPACE}/modules/${CI_PROJECT_NAME}/zephyr/patches.yml" -w . | |
fi | |
# prepare for running either west or twister | |
cd "${ZEPHYR_BASE}" | |
west zephyr-export | |
source zephyr-env.sh | |
.default_after_script: | |
after_script: | | |
# move artifacts to CI directory | |
if [ -d "${ZEPHYR_BASE}/build" ]; then | |
# for build jobs run with west | |
mv "${ZEPHYR_BASE}/build" "${CI_PROJECT_DIR}/build-${CI_JOB_ID}" | |
elif [ -d "${ZEPHYR_BASE}/twister-out" ]; then | |
# for build / test jobs run with twister | |
mv "${ZEPHYR_BASE}/twister-out" "${CI_PROJECT_DIR}/twister-out-${CI_JOB_ID}" | |
fi | |
if [ ! -z "$AFTER_SCRIPT" ] && [ -x "$AFTER_SCRIPT" ]; then | |
"$AFTER_SCRIPT" | |
fi | |
stages: | |
- build | |
- test | |
default: | |
# container image for build / test | |
# see https://github.com/zephyrproject-rtos/docker-image | |
image: ${ZEPHYR_BUILD_CONTAINER} | |
before_script: | |
# install ubuntu packages | |
# clone Zephyr and apply patches | |
# link Zephyr modules into build | |
# set up environment variables for script | |
- !reference [.default_before_script, before_script] | |
after_script: | |
# move build artifacts to unique directory | |
# reset firmware state to known good condition after testing | |
- !reference [.default_after_script, after_script] | |
# West => build one Zephyr firmware image | |
.west: | |
stage: build | |
script: | | |
echo "please define a custom west invocation to build something other than samples/hello_world" | |
west build -p auto -b qemu_riscv64 samples/hello_world | |
artifacts: | |
paths: | |
- build-${CI_JOB_ID}/**/.config | |
- build-${CI_JOB_ID}/**/include/generated/devicetree_generated.h | |
- build-${CI_JOB_ID}/**/linker.cmd | |
- build-${CI_JOB_ID}/**/*.bin | |
- build-${CI_JOB_ID}/**/*.dts | |
- build-${CI_JOB_ID}/**/*.elf | |
- build-${CI_JOB_ID}/**/*.lst | |
- build-${CI_JOB_ID}/**/*.map | |
- build-${CI_JOB_ID}/**/*.stat | |
- build-${CI_JOB_ID}/**/isr_tables.c | |
expire_in: 1 week | |
rules: | |
- !reference [.default_rules, rules] | |
# Twister => build and test many Zephyr firmware images | |
.twister: | |
stage: test | |
script: | | |
echo "please define a custom twister invocation to test something other than samples/hello_world" | |
twister -i -p qemu_riscv64 -T samples/hello_world | |
artifacts: | |
paths: | |
- twister-out-${CI_JOB_ID}/testplan.json | |
- twister-out-${CI_JOB_ID}/twister.json | |
- twister-out-${CI_JOB_ID}/twister.log | |
- twister-out-${CI_JOB_ID}/**/*.log | |
expire_in: 1 week | |
reports: | |
junit: twister-out-${CI_JOB_ID}/**/*.xml | |
rules: | |
- !reference [.default_rules, rules] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment