Files
trail-mate/.github/workflows/ci.yml
T

290 lines
9.9 KiB
YAML

name: CI
on:
push:
branches: ["**"]
tags:
- "v*"
pull_request:
jobs:
boundary:
name: Boundary Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Verify shared/platform UI boundaries
run: python3 scripts/check_platform_ui_boundaries.py
- name: Verify ESP stack hygiene
run: python3 scripts/check_esp_stack_hygiene.py
- name: Verify track file streaming
run: python3 scripts/check_track_file_streaming.py
- name: Verify repository root has no build artifacts
run: python3 scripts/check_root_build_artifacts.py
- name: Verify locale packs
run: python3 tools/validate_locale_packs.py --pack-root packs
format:
name: Format Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install clang-format
run: sudo apt-get update && sudo apt-get install -y clang-format-14
- name: Verify formatting
run: |
clang-format-14 --version
git ls-files -z '*.c' '*.cpp' '*.h' '*.hpp' ':(exclude)modules/core_chat/generated/**' \
':(exclude)modules/ui_shared/include/ui/assets/**' \
':(exclude)modules/ui_shared/src/ui/assets/**' \
':(exclude)platform/nrf52/arduino_common/include/ui/fonts/**' \
':(exclude)platform/nrf52/arduino_common/src/ui/fonts/**' \
':(exclude)third_party/codec2/**' \
| xargs -0 clang-format-14 --dry-run --Werror
build:
name: PlatformIO Build (${{ matrix.env }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- env: tlora_pager_sx1262
project_dir: .
build_root: .pio/build
- env: tlora_pager_lr1121
project_dir: .
build_root: .pio/build
- env: tdeck
project_dir: .
build_root: .pio/build
- env: lilygo_twatch_s3
project_dir: .
build_root: .pio/build
- env: gat562_mesh_evb_pro
project_dir: .
build_root: .pio/build
- env: t-echo-lite
project_dir: builds/pio_nrf52
build_root: builds/pio_nrf52/.pio/build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Extract version
id: version
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION="${GITHUB_REF_NAME#v}"
else
VERSION=$(iconv -f UTF-16LE -t UTF-8 CHANGELOG.md | awk -F'[][]' '/^## \\[[0-9]/ {print $2; exit}')
fi
if [ -z "$VERSION" ]; then
VERSION="unknown"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Cache PlatformIO
uses: actions/cache@v4
with:
path: |
~/.platformio
key: ${{ runner.os }}-platformio-${{ hashFiles('platformio.ini', 'builds/pio_nrf52/platformio.ini') }}
- name: Install PlatformIO
run: python -m pip install --upgrade platformio
- name: Build (${{ matrix.env }})
run: pio run -d ${{ matrix.project_dir }} -e ${{ matrix.env }}
- name: Validate OTA slot size
run: |
BUILD_DIR="${{ matrix.build_root }}/${{ matrix.env }}"
if [ -f "${BUILD_DIR}/firmware.bin" ]; then
SIZE=$(stat -c%s "${BUILD_DIR}/firmware.bin")
MAX_SIZE=$((0x400000))
echo "firmware.bin size=${SIZE} max=${MAX_SIZE}"
if [ "${SIZE}" -gt "${MAX_SIZE}" ]; then
echo "firmware.bin exceeds OTA slot size" >&2
exit 1
fi
fi
- name: Prepare and verify nRF52840 UF2
if: matrix.env == 'gat562_mesh_evb_pro' || matrix.env == 't-echo-lite'
run: |
python scripts/prepare_nrf52_uf2.py \
--env ${{ matrix.env }} \
--build-root ${{ matrix.build_root }}
- name: Collect firmware
run: |
mkdir -p dist
BUILD_DIR="${{ matrix.build_root }}/${{ matrix.env }}"
copied=0
for ext in bin hex uf2 zip; do
if [ -f "${BUILD_DIR}/firmware.${ext}" ]; then
cp "${BUILD_DIR}/firmware.${ext}" "dist/trail-mate-${{ matrix.env }}-v${{ steps.version.outputs.version }}.${ext}"
copied=$((copied + 1))
fi
done
if [ "${copied}" -eq 0 ]; then
echo "No firmware artifacts found in ${BUILD_DIR}" >&2
exit 1
fi
- name: Prepare web flasher image
if: matrix.env == 'tlora_pager_sx1262' || matrix.env == 'tlora_pager_lr1121' || matrix.env == 'tdeck' || matrix.env == 'lilygo_twatch_s3'
run: |
python scripts/prepare_webflash_release.py \
--env ${{ matrix.env }} \
--build-root ${{ matrix.build_root }} \
--dist dist \
--boot-app0 ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin \
--esptool ~/.platformio/packages/tool-esptoolpy/esptool.py
- name: Collect debug symbols
if: startsWith(github.ref, 'refs/tags/v')
run: |
BUILD_DIR="${{ matrix.build_root }}/${{ matrix.env }}"
SYMBOL_DIR="dist/symbols/${{ matrix.env }}"
mkdir -p "${SYMBOL_DIR}"
copied=0
for name in firmware.elf firmware.map firmware.bin firmware.hex; do
if [ -f "${BUILD_DIR}/${name}" ]; then
cp "${BUILD_DIR}/${name}" "${SYMBOL_DIR}/${name}"
copied=$((copied + 1))
fi
done
if [ "${copied}" -eq 0 ]; then
echo "No debug symbol inputs found for ${{ matrix.env }}"
rm -rf "${SYMBOL_DIR}"
exit 0
fi
{
echo "schema=trail-mate.symbols.v1"
echo "env=${{ matrix.env }}"
echo "version=${{ steps.version.outputs.version }}"
echo "git_ref=${GITHUB_REF}"
echo "git_ref_name=${GITHUB_REF_NAME}"
echo "git_sha=${GITHUB_SHA}"
echo "created_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
} > "${SYMBOL_DIR}/manifest.txt"
if [ -f "${BUILD_DIR}/firmware.bin" ]; then
if ! python ~/.platformio/packages/tool-esptoolpy/esptool.py image_info --version 2 \
"${BUILD_DIR}/firmware.bin" > "${SYMBOL_DIR}/firmware-image-info.txt" 2> "${SYMBOL_DIR}/firmware-image-info.err"; then
{
echo "esptool image_info failed for ${BUILD_DIR}/firmware.bin"
echo "The firmware image is still included; image metadata is best-effort."
cat "${SYMBOL_DIR}/firmware-image-info.err"
} > "${SYMBOL_DIR}/firmware-image-info.txt"
fi
rm -f "${SYMBOL_DIR}/firmware-image-info.err"
fi
(cd "${SYMBOL_DIR}" && sha256sum * > SHA256SUMS)
(cd dist/symbols && python -m zipfile -c "../trail-mate-${{ matrix.env }}-v${{ steps.version.outputs.version }}-symbols.zip" "${{ matrix.env }}")
rm -rf dist/symbols
- name: Upload firmware artifact
uses: actions/upload-artifact@v4
with:
name: trail-mate-${{ matrix.env }}-v${{ steps.version.outputs.version }}
path: dist/*
release:
name: Publish GitHub Release
runs-on: ubuntu-latest
needs:
- boundary
- format
- build
if: startsWith(github.ref, 'refs/tags/v')
permissions:
actions: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download firmware artifacts
uses: actions/download-artifact@v4
with:
path: dist
- name: Verify collected firmware files
run: |
find dist -type f \( -name '*.bin' -o -name '*.hex' -o -name '*.uf2' -o -name '*.zip' \) -print | sort
- name: Extract changelog entry
run: |
VERSION="${GITHUB_REF_NAME#v}"
iconv -f UTF-16LE -t UTF-8 CHANGELOG.md > CHANGELOG.utf8.md
awk -v version="$VERSION" '
$0 ~ "^## \\[" version "\\]" {capture=1}
capture {
if ($0 ~ "^## \\[" && $0 !~ "^## \\[" version "\\]") exit
print
}
' CHANGELOG.utf8.md > release_changelog.md
if [ ! -s release_changelog.md ]; then
echo "Failed to extract changelog entry for version ${VERSION}" >&2
exit 1
fi
cat release_changelog.md
- name: Create or update release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
body_path: release_changelog.md
generate_release_notes: true
prerelease: ${{ contains(github.ref_name, '-alpha') || contains(github.ref_name, '-beta') || contains(github.ref_name, '-rc') }}
overwrite_files: true
files: |
dist/**/*.bin
dist/**/*.hex
dist/**/*.uf2
dist/**/*.zip
- name: Refresh Pages metadata
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
HTTP_STATUS=$(curl -sS -o /tmp/pages-dispatch-response.txt -w "%{http_code}" \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${REPO}/actions/workflows/pages.yml/dispatches" \
-d "{\"ref\":\"${DEFAULT_BRANCH}\"}")
if [ "${HTTP_STATUS}" != "204" ]; then
echo "Pages workflow dispatch failed with HTTP ${HTTP_STATUS}" >&2
cat /tmp/pages-dispatch-response.txt >&2
exit 1
fi