Build firmware #3
This file contains 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
name: Build firmware | |
on: | |
workflow_dispatch: | |
push: | |
tags: | |
- '*' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
container: registry.gitlab.com/hadzhioglu/padavan-ng | |
defaults: { run: { shell: bash } } | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get variables | |
run: | | |
sed -i 's|\r$||g' variables build.config | |
. <(cat variables build.config) | |
PADAVAN_THEMES="${PADAVAN_THEMES[*]}" | |
for v in "${!PADAVAN_@}" "${!CONFIG_@}"; do | |
echo "$v=${!v}" >> $GITHUB_ENV | |
done | |
- name: Download sources and toolchain | |
run: | | |
git config --global --add safe.directory '*' | |
git clone -b "$PADAVAN_BRANCH" "$PADAVAN_REPO" | |
git -C padavan-ng checkout "$PADAVAN_COMMIT" | |
wget -qO- "$PADAVAN_TOOLCHAIN_URL" | tar -C padavan-ng --zstd -xf - | |
- name: Install themes | |
run: | | |
if [[ -n $PADAVAN_THEMES ]]; then | |
git clone --depth 1 -b "$PADAVAN_THEMES_BRANCH" "$PADAVAN_THEMES_REPO" themes | |
cp -r themes/common-theme themes/jquery.js padavan-ng/trunk/user/www/n56u_ribbon_fixed | |
for theme in $PADAVAN_THEMES; do | |
echo "Installing $theme theme" | |
cp -r "themes/$theme-theme" padavan-ng/trunk/user/www/n56u_ribbon_fixed | |
done | |
fi | |
- name: Run custom pre-build script | |
run: '[[ -f pre-build.sh ]] && . pre-build.sh || :' | |
- name: Build firmware | |
run: | | |
cp build.config padavan-ng/trunk/.config | |
pushd padavan-ng/trunk | |
./clear_tree.sh | |
./build_firmware.sh | |
popd | |
- name: Run custom post-build script | |
run: '[[ -f post-build.sh ]] && . post-build.sh || :' | |
- name: Prepare artifacts | |
run: | | |
FW_FILE_NAME="$(find padavan-ng/trunk/images -type f -regextype posix-extended -iregex ".*\.(trx|bin)$" \ | |
-printf "%T@\t%f\n" | sort -V | tail -1 | cut -f2)" | |
cp "padavan-ng/trunk/images/$FW_FILE_NAME" . | |
echo "FW_FILE_NAME=$FW_FILE_NAME" >> $GITHUB_ENV | |
echo "BUILD_TIMESTAMP=$(date '+%Y.%m.%d_%H.%M.%S')" >> $GITHUB_ENV | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: padavan-ng_${{ env.CONFIG_VENDOR }}_${{ env.CONFIG_FIRMWARE_PRODUCT_ID }}_${{ env.BUILD_TIMESTAMP }} | |
retention-days: 7 | |
path: | | |
${{ env.FW_FILE_NAME }} | |
build.config | |
- name: Check firmware size | |
run: | | |
partitions=padavan-ng/trunk/configs/boards/$CONFIG_VENDOR/$CONFIG_FIRMWARE_PRODUCT_ID/partitions.config | |
max_fw_size="$(awk '/Firmware/ { getline; getline; sub(",", ""); print strtonum($2); }' "$partitions")" | |
fw_size="$(stat -c %s "$FW_FILE_NAME")" | |
if ((fw_size > max_fw_size)); then | |
fw_size_fmtd="$(numfmt --grouping "$fw_size") bytes" | |
max_fw_size_fmtd="$(numfmt --grouping "$max_fw_size") bytes" | |
echo "Firmware size ($fw_size_fmtd) exceeds max size ($max_fw_size_fmtd) for your target device" | |
exit 1 | |
fi |