prplos/.gitlab/build.yml
Petr Štetiar 742dd9cd65 ci: build: generate release version files for tags
Release binaries must be reproducible from the sources shipped with them.
Generate version and version.date from git when CI_COMMIT_TAG is set,
before the build reads either value.

Compute both values before writing either file, then print them for
traceability. The tag condition is the exact complement of the development
guard, so generation cannot run on development builds.

Assisted-by: codex:gpt-5.6-sol:medium-fast
Assisted-by: claude:opus-5:orchestrator
Signed-off-by: Petr Štetiar <petr.stetiar@prplfoundation.org>
References: PCF-2730
2026-08-18 09:06:22 +00:00

189 lines
7.0 KiB
YAML

.build test config:
stage: build
timeout: 2 hours
image: "$CI_REGISTRY_IMAGE/$CI_DESIGNATED_BRANCH_SLUG/builder:latest"
tags:
- firmware-builder
variables:
CI_BUILD_CONFIG: >
+DEVEL +BUILD_LOG +SDK +INCLUDE_CONFIG +IB +IB_STANDALONE
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_COMMIT_BRANCH == $CI_DESIGNATED_BRANCH'
- if: '$CI_COMMIT_TAG =~ /^prplware-v[0-9]+\.[0-9]+\.[0-9]+.*$/'
- when: manual
before_script:
- touch .build_failed
- export CI_BUILD_PROFILE="$(echo $CI_JOB_NAME | sed 's/build test \(.*\)/\1/')"
script:
- source .gitlab/scripts/helpers.sh
- section_start "build-setup" "Build Setup" "collapsed"
- mkdir -p logs
- set -o pipefail
- git config --global --add safe.directory '*'
- |
sudo apt-get update && \
sudo apt-get install --yes --no-install-recommends \
swig \
coccinelle \
libbsd-dev \
libssl-dev \
libpython3-dev \
lzop
- |
crlf_check_failed=$(rgrep -U $'\x0D' profiles | cut -d: -f1 | sort -u || true)
if test -n "$crlf_check_failed"; then
echo -e "ERROR: detected CRLF issues in the following YAML profiles:\n"
for profile in $crlf_check_failed; do
echo " * $profile"
done
echo -e "\nIt might result in hard to debug issues, please fix them."
exit 1
fi
- |
if [ -z "$CI_COMMIT_TAG" ] && { [ -e version ] || [ -e version.date ]; }; then
echo "ERROR: version or version.date is present in a development build. Development builds must use git-derived version data. Cherry-pick upstream's \"revert to branch defaults\" commit alongside release-tag syncs."
exit 1
fi
- |
if [ -n "$CI_COMMIT_TAG" ]; then
release_version="$(scripts/getver.sh)"
release_version_date="$(scripts/get_source_date_epoch.sh)"
printf '%s\n' "$release_version" > version
printf '%s\n' "$release_version_date" > version.date
printf 'Generated release version data: version=%s version.date=%s\n' "$release_version" "$release_version_date"
fi
- |
if [ -z "$CI_COMMIT_TAG" ] && [ "$CI_DESIGNATED_BRANCH" != "$CI_COMMIT_BRANCH" ]; then
echo "Enabling coredumps and exception tracing in the build."
export CI_BUILD_ENABLE_COREDUMPS=1
export CI_BUILD_ENABLE_EXCEPTION_TRACE=1
else
echo "Coredumps and exception tracing are disabled in this build."
fi
- for script in .gitlab/scripts/build.d/*; do bash "$script"; done
- section_end "build-setup"
- section_start "gen-config" "Running gen_config.py" "collapsed"
- |
sed -i -E 's;git.openwrt.org/(feed|project);github.com/openwrt;' feeds.conf.default
scripts/gen_config.py $CI_BUILD_PROFILE 2>&1 | tee logs/build.log
git checkout -- feeds.conf.default
- section_end "gen-config"
- section_start "defconfig" "Running defconfig" "collapsed"
- |
for option in $CI_BUILD_CONFIG $CI_BUILD_CONFIG_EXTRA; do
echo "$option" | sed -E "s/^\+(.*)$/CONFIG_\1=y/;s/^\-(.*)$/CONFIG_\1=n/" >> .config
done
cat .config
make defconfig | tee --append logs/build.log
- section_end "defconfig"
- section_start "tools-tar-compile" "Compiling tar tool" "collapsed"
- make -j $(nproc) tools/tar/compile 2>&1 | tee --append logs/build.log
- section_end "tools-tar-compile"
- section_start "download" "Downloading source code" "collapsed"
- |
if [[ "$CI_MERGE_REQUEST_LABELS" == *"skip_integrity_check"* ]]; then
make -j $(nproc) download 2>&1 | tee --append logs/build.log
else
make -j $(nproc) download check FIXUP=1 2>&1 | tee --append logs/build.log
fi
- section_end "download"
- section_start "integrity-check" "Package & feed integrity check" "collapsed"
- >
git diff-index --exit-code HEAD || {
ret=$?
echo "Package integrity issues, please check the output bellow or packages-hash-issues.patch from artifacts"
git diff | tee packages-hash-issues.patch
exit $ret
}
- >
topdir=$(pwd);
for feed in $(find feeds -name .git); do
pushd $(dirname $feed) > /dev/null; git diff-index --exit-code HEAD || {
ret=$?
echo "Feed $(dirname $feed) packages integrity issues, please check the output bellow or feed-packages-hash-issues.patch from artifacts"
git diff | tee --append $topdir/feed-packages-hash-issues.patch
exit $ret
}
popd > /dev/null
done
- section_end "integrity-check"
- >
trap "
grep -qz 'package/install[[:space:]]make -r world' logs/build.log && {
echo '[!] ERROR: package/install seems to fail, enabling verbose output'
make package/install V=s 2>&1 | tee --append logs/build.log
grep -C5 'Collected errors:' logs/build.log
}
echo '[!] ERROR: build failed'
exit 1
" ERR
- >
trap "
grep -qz 'ERROR: target/linux failed to build' logs/build.log && {
echo '[!] ERROR: target/linux seems to fail, enabling verbose output'
make target/install -j $(nproc) V=s 2>&1 | tee --append logs/build.log
}
echo '[!] ERROR: build failed'
exit 1
" ERR
- section_start "compile-world" "Compiling world using $(nproc) make threads" "expanded"
- make -j $(nproc) 2>&1 | tee --append logs/build.log
- section_end "compile-world"
- section_start "export-rootfs" "Exporting staging rootfs to a tarball" "collapsed"
- >
if [ -n "$CI_BUILD_EXPORT_STAGING_ROOTFS" ]; then
root_dir=$(find $(pwd)/staging_dir -maxdepth 2 -type d -name root-*)
tar cfJ "rootfs-debug.tar.xz" -C "$root_dir" .
echo "Export of staging_dir/root-* completed in rootfs-debug.tar.xz"
else
echo "Skipping export of staging/root-* as \$CI_BUILD_EXPORT_STAGING_ROOTFS is not set."
fi
- section_end "export-rootfs"
- rm .build_failed
after_script:
- >
if test -f .build_failed && grep -qr 'make\[[[:digit:]]\].*Error [[:digit:]]$' logs; then
printf "\n====== Showing Make errors found in the log files ======";
for file in $(grep -lr 'make\[[[:digit:]]\+\].*Error [[:digit:]]\+$' logs); do
printf "\n====== Make errors from $CI_JOB_URL/artifacts/file/$file ======\n" ;
grep -r -C20 'make\[[[:digit:]]\+\].*Error [[:digit:]]\+$' $file ;
done
fi
artifacts:
expire_in: 1 month
when: always
paths:
- bin
- logs
- ./*packages-hash-issues.patch
- rootfs-debug.tar.xz
exclude:
- bin/**/prplos-intel_x86-lgm-*-kernel.itb
- bin/**/prplos-intel_x86-lgm-*-rootfs.itb
- bin/**/prplos-intel_x86-lgm-PRPL_OSP_v2-*_wav700-fullimage.itb
- bin/**/prplos-intel_x86-lgm-PRPL_OSP_v2-kernel.bin
- bin/**/prplos-intel_x86-lgm-PRPL_OSP_v2-overlay.dtbo
- bin/**/prplos-intel_x86-lgm-PRPL_OSP_v2-*_wav700_eth.dtb
- bin/**/prplos-intel_x86-lgm-PRPL_OSP_v2-squashfs-fs.rootfs
- bin/**/ext4.fs