From 551af7fc349d25d03c25ceccfacf0137e224b1fa Mon Sep 17 00:00:00 2001 From: Marcin Anforowicz Date: Wed, 18 Sep 2024 05:21:16 -0700 Subject: [PATCH] ESP-IDF Component Continuous Integration (#229) This pull request is meant to resolve #227 by adding continuous integration for publishing Libcanard to the [ESP Component Registry](https://components.espressif.com/). Files added: - `idf_component.yml`. This file contains required ESP component metadata. - `Kconfig`. ESP components use this file as a standard way for controlling build options. I've added options for enabling/disabling assertions and the CRC table. - `CMakeLists.txt`. This file is required to register the component with the ESP build system. - `.github/workflows/esp_publish.yml`. This workflow uploads the component to the ESP-IDF registry whenever a new GitHub release is published. - `.github/workflows/esp_dry_run.yml`. This workflow does a dry-run of uploading to the ESP-IDF registry, without publishing anything. It can only be manually triggered. I've tested this in my repository, and it seems to work. The GitHub workflows require `IDF_COMPONENT_API_TOKEN` with an [ESP registry token](https://components.espressif.com/settings/tokens/) to be added to the repository secrets. --------- Co-authored-by: Marcin Anforowicz Co-authored-by: Pavel Kirienko --- .github/workflows/esp_dry_run.yml | 22 ++++++++++++++++++++++ .github/workflows/esp_publish.yml | 22 ++++++++++++++++++++++ esp_metadata/CMakeLists.txt | 18 ++++++++++++++++++ esp_metadata/Kconfig | 24 ++++++++++++++++++++++++ esp_metadata/idf_component.yml | 12 ++++++++++++ esp_metadata/package_esp_component.sh | 26 ++++++++++++++++++++++++++ 6 files changed, 124 insertions(+) create mode 100644 .github/workflows/esp_dry_run.yml create mode 100644 .github/workflows/esp_publish.yml create mode 100644 esp_metadata/CMakeLists.txt create mode 100644 esp_metadata/Kconfig create mode 100644 esp_metadata/idf_component.yml create mode 100644 esp_metadata/package_esp_component.sh diff --git a/.github/workflows/esp_dry_run.yml b/.github/workflows/esp_dry_run.yml new file mode 100644 index 0000000..695e708 --- /dev/null +++ b/.github/workflows/esp_dry_run.yml @@ -0,0 +1,22 @@ +# This workflow only runs when it is manually dispatched using GitHub. +# It does a dry-run of publishing this project to the ESP component registry. +# The project won't actually be published. + +name: Dry-run upload to the ESP component registry +on: + workflow_dispatch: + +jobs: + upload_component: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Dry-run upload to the ESP component registry + run: | + bash esp_metadata/package_esp_component.sh + export IDF_COMPONENT_API_TOKEN="${{ secrets.IDF_COMPONENT_API_TOKEN }}" + cd package/libcanard + compote component upload --namespace opencyphal --name libcanard --version 0.0.0 --dry-run diff --git a/.github/workflows/esp_publish.yml b/.github/workflows/esp_publish.yml new file mode 100644 index 0000000..90b7016 --- /dev/null +++ b/.github/workflows/esp_publish.yml @@ -0,0 +1,22 @@ +# This workflow gets triggered when a GitHub release is published. +# It publishes this project to the public ESP-IDF component registry. + +name: Publish component to the ESP-IDF registry +on: + release: + types: [published] + +jobs: + upload_component: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Publish component to the ESP-IDF registry + run: | + bash esp_metadata/package_esp_component.sh + export IDF_COMPONENT_API_TOKEN="${{ secrets.IDF_COMPONENT_API_TOKEN }}" + cd package/libcanard + compote component upload --namespace opencyphal --name libcanard --version ${{ github.event.release.tag_name }} diff --git a/esp_metadata/CMakeLists.txt b/esp_metadata/CMakeLists.txt new file mode 100644 index 0000000..1593ec9 --- /dev/null +++ b/esp_metadata/CMakeLists.txt @@ -0,0 +1,18 @@ +# This file is used when packaging libcanard +# for the ESP-IDF component registry: +# https://components.espressif.com/ + +idf_component_register(SRCS "canard.c" + INCLUDE_DIRS "include") + +# Apply the Kconfig options to the source file. + +if(NOT CONFIG_CANARD_ASSERTIONS) + target_compile_definitions(${COMPONENT_LIB} PRIVATE "CANARD_ASSERT=(void)") +endif() + +if(CONFIG_CANARD_CRC_TABLE) + target_compile_definitions(${COMPONENT_LIB} PRIVATE CANARD_CRC_TABLE=1) +else() + target_compile_definitions(${COMPONENT_LIB} PRIVATE CANARD_CRC_TABLE=0) +endif() diff --git a/esp_metadata/Kconfig b/esp_metadata/Kconfig new file mode 100644 index 0000000..8e89e7f --- /dev/null +++ b/esp_metadata/Kconfig @@ -0,0 +1,24 @@ +# This file is used when packaging libcanard +# for the ESP-IDF component registry: +# https://components.espressif.com/ + +# This file defines customizable ESP-IDF build options +# that can be configured by running 'idf.py menuconfig'. + +menu "Libcanard" + +config CANARD_ASSERTIONS + bool "Enable libcanard assertions." + default y + help + Set to 'n' to disable libcanard assertions. + +config CANARD_CRC_TABLE + bool "Enable libcanard CRC table" + default y + help + Set to 'n' to use slow but ROM-efficient transfer-CRC computation algorithm. + Doing so is expected to save ca. 500 bytes of ROM and + increase the cost of RX/TX transfer processing by ~half. + +endmenu diff --git a/esp_metadata/idf_component.yml b/esp_metadata/idf_component.yml new file mode 100644 index 0000000..fe3930e --- /dev/null +++ b/esp_metadata/idf_component.yml @@ -0,0 +1,12 @@ +# This file is used when packaging libcanard +# for the ESP-IDF component registry: +# https://components.espressif.com/ + +# Note: Version is not specified in this file, +# because the 'esp_publish.yml' GitHub action +# automatically sets it based on the release version. + +description: "Cyphal/CAN for embedded systems." +license: "MIT" +url: "https://github.com/OpenCyphal/libcanard" +repository: "https://github.com/OpenCyphal/libcanard" diff --git a/esp_metadata/package_esp_component.sh b/esp_metadata/package_esp_component.sh new file mode 100644 index 0000000..1a6dbcb --- /dev/null +++ b/esp_metadata/package_esp_component.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -e + +# This script must be called from the root of this repository. +# It packages up libcanard as an ESP-IDF component in package/libcanard. + +mkdir -p package/libcanard/include + +cp CONTRIBUTING.md package/libcanard/CONTRIBUTING.md +cp LICENSE package/libcanard/LICENSE +cp README.md package/libcanard/README.md + +cp libcanard/canard.c package/libcanard/canard.c +cp libcanard/_canard_cavl.h package/libcanard/_canard_cavl.h +cp libcanard/canard.h package/libcanard/include/canard.h + +cp esp_metadata/CMakeLists.txt package/libcanard/CMakeLists.txt +cp esp_metadata/Kconfig package/libcanard/Kconfig +cp esp_metadata/idf_component.yml package/libcanard/idf_component.yml + +# Install compote, a tool for uploading ESP-IDF components. +python3 -m pip install --upgrade idf-component-manager + +echo "Successfully packaged ESP component into package/libcanard:" +find package/libcanard +echo