Skip to content

Commit

Permalink
ESP-IDF Component Continuous Integration (#229)
Browse files Browse the repository at this point in the history
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 <marcin.anforowicz@wibotic.com>
Co-authored-by: Pavel Kirienko <pavel.kirienko@gmail.com>
  • Loading branch information
3 people committed Sep 18, 2024
1 parent 00f9d5c commit 551af7f
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/esp_dry_run.yml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions .github/workflows/esp_publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
18 changes: 18 additions & 0 deletions esp_metadata/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
24 changes: 24 additions & 0 deletions esp_metadata/Kconfig
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions esp_metadata/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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"
26 changes: 26 additions & 0 deletions esp_metadata/package_esp_component.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 551af7f

Please sign in to comment.