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

206 lines
6.7 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 repository root has no build artifacts
run: python3 scripts/check_root_build_artifacts.py
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:
env:
- tlora_pager_sx1262
- tlora_pager_lr1121
- tdeck
- lilygo_twatch_s3
- gat562_mesh_evb_pro
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') }}
- name: Install PlatformIO
run: python -m pip install --upgrade platformio
- name: Build (${{ matrix.env }})
run: pio run -e ${{ matrix.env }}
- name: Validate OTA slot size
run: |
if [ -f ".pio/build/${{ matrix.env }}/firmware.bin" ]; then
SIZE=$(stat -c%s ".pio/build/${{ matrix.env }}/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: Collect firmware
run: |
mkdir -p dist
if [ "${{ matrix.env }}" = "gat562_mesh_evb_pro" ]; then
cp .pio/build/${{ matrix.env }}/firmware.hex dist/trail-mate-${{ matrix.env }}-v${{ steps.version.outputs.version }}.hex
cp .pio/build/${{ matrix.env }}/firmware.zip dist/trail-mate-${{ matrix.env }}-v${{ steps.version.outputs.version }}.zip
else
cp .pio/build/${{ matrix.env }}/firmware.bin dist/trail-mate-${{ matrix.env }}-v${{ steps.version.outputs.version }}.bin
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 .pio/build \
--dist dist \
--boot-app0 ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin \
--esptool ~/.platformio/packages/tool-esptoolpy/esptool.py
- 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 '*.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/**/*.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