diff --git a/README.md b/README.md index 59b3e721..41e7f8e8 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,7 @@ available to your Workflows. * [setup-taskfile](./setup-taskfile) makes [`task`](https://taskfile.dev/#/) available to your Workflows. + +* [libraries/compile-examples](./libraries/compile-examples) compile all the examples in an Arduino Library + +* [libraries/spell-check](./libraries/spell-check) run spell checker on Arduino Library source and examples diff --git a/libraries/compile-examples/Dockerfile b/libraries/compile-examples/Dockerfile new file mode 100644 index 00000000..2c378f54 --- /dev/null +++ b/libraries/compile-examples/Dockerfile @@ -0,0 +1,12 @@ +# Container image that runs your code +FROM ubuntu:latest + +# Install prerequisites +RUN apt-get update && apt-get install -y wget +CMD /bin/bash + +# Copies your code file from your action repository to the filesystem path `/` of the container +COPY entrypoint.sh /entrypoint.sh + +# Code file to execute when the docker container starts up (`entrypoint.sh`) +ENTRYPOINT ["/entrypoint.sh"] diff --git a/libraries/compile-examples/README.md b/libraries/compile-examples/README.md new file mode 100644 index 00000000..ce2d3826 --- /dev/null +++ b/libraries/compile-examples/README.md @@ -0,0 +1,25 @@ +# libraries/compile-examples action + +This action compiles all of the examples contained in the library. + +## Inputs + +### `cli-version` + +The version of `arduino-cli` to use. Default `"latest"`. + +### `fqbn` + +**Required** The fully qualified board name to use when compiling. Default `"arduino:avr:uno"`. + +### `libraries` + +List of library dependencies to install (space separated). Default `""`. + +## Example usage + +```yaml +uses: arduino/actions/libraries/compile-examples@master +with: + fqbn: 'arduino:avr:uno' +``` diff --git a/libraries/compile-examples/action.yml b/libraries/compile-examples/action.yml new file mode 100644 index 00000000..1357bcfa --- /dev/null +++ b/libraries/compile-examples/action.yml @@ -0,0 +1,20 @@ +name: 'Arduino Libraries - Compile Examples' +description: 'Compiles all the examples included in the library' +inputs: + cli-version: + description: 'Version of arduino-cli to use when builing' + default: 'latest' + fqbn: + description: 'Full qualified board name' + required: true + default: 'arduino:avr:uno' + libraries: + description: 'List of library dependencies to install (space separated)' + default: '' +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.cli-version }} + - ${{ inputs.fqbn }} + - ${{ inputs.libraries }} diff --git a/libraries/compile-examples/entrypoint.sh b/libraries/compile-examples/entrypoint.sh new file mode 100755 index 00000000..7d49b5ac --- /dev/null +++ b/libraries/compile-examples/entrypoint.sh @@ -0,0 +1,45 @@ +#!/bin/bash -x + +CLI_VERSION=$1 +FQBN=$2 +LIBRARIES=$3 + +# Determine cli archive +CLI_ARCHIVE=arduino-cli_${CLI_VERSION}_Linux_64bit.tar.gz + +# Extract the core name from the FQBN +# for example arduino:avr:uno => arduino:avr +CORE=`echo "$FQBN" | cut -d':' -f1,2` + +# Download the arduino-cli +wget -P $HOME https://downloads.arduino.cc/arduino-cli/$CLI_ARCHIVE + +# Extract the arduino-cli to $HOME/bin +mkdir $HOME/bin +tar xf $HOME/$CLI_ARCHIVE -C $HOME/bin + +# Add arduino-cli to the PATH +export PATH=$PATH:$HOME/bin + +# Update the code index and install the required CORE +arduino-cli core update-index +arduino-cli core install $CORE + +# Install libraries if needed +if [ -z "$LIBRARIES" ] +then + echo "No libraries to install" +else + arduino-cli lib install $LIBRARIES +fi + +# Symlink the library that needs to be built in the sketchbook +mkdir -p $HOME/Arduino/libraries +ln -s $PWD $HOME/Arduino/libraries/. + +# Find all the examples and loop build each +EXAMPLES=`find examples/ -name '*.ino' | xargs dirname | uniq` +for EXAMPLE in $EXAMPLES; do + echo Building example $EXAMPLE + arduino-cli compile --verbose --warnings all --fqbn $FQBN $EXAMPLE +done || exit 1 \ No newline at end of file diff --git a/libraries/spell-check/Dockerfile b/libraries/spell-check/Dockerfile new file mode 100644 index 00000000..f5a0baf0 --- /dev/null +++ b/libraries/spell-check/Dockerfile @@ -0,0 +1,15 @@ +# Container image that runs your code +FROM ubuntu:latest + +# Install prerequisites +RUN apt-get update && apt-get install -y python3 python3-pip +CMD /bin/bash + +RUN pip3 install codespell +CMD /bin/bash + +# Copies your code file from your action repository to the filesystem path `/` of the container +COPY entrypoint.sh /entrypoint.sh + +# Code file to execute when the docker container starts up (`entrypoint.sh`) +ENTRYPOINT ["/entrypoint.sh"] diff --git a/libraries/spell-check/README.md b/libraries/spell-check/README.md new file mode 100644 index 00000000..8a0fb31b --- /dev/null +++ b/libraries/spell-check/README.md @@ -0,0 +1,15 @@ +# libraries/spell-check action + +Runs codespell on library source code and examples contained in the library. + +## Inputs + +### `ignore-words-list` + +File path of list of words to ignore. + +## Example usage + +```yaml +uses: arduino/actions/libraries/spell-check@master +``` diff --git a/libraries/spell-check/action.yml b/libraries/spell-check/action.yml new file mode 100644 index 00000000..66daf08a --- /dev/null +++ b/libraries/spell-check/action.yml @@ -0,0 +1,11 @@ +name: 'Arduino Libraries - Spell Check' +description: 'Runs codespell on library source code and examples contained in the library' +inputs: + ignore-words-list: + description: 'File path of list of words to ignore' + default: '' +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.ignore-words-list }} diff --git a/libraries/spell-check/entrypoint.sh b/libraries/spell-check/entrypoint.sh new file mode 100755 index 00000000..4732807d --- /dev/null +++ b/libraries/spell-check/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash -x + +IGNORE_WORDS_LIST=$1 + +CODE_SPELL_ARGS="--skip=.git" + +if test -f "$IGNORE_WORDS_LIST"; then + CODE_SPELL_ARGS="${CODE_SPELL_ARGS} --ignore-words=${IGNORE_WORDS_LIST}" +fi + +codespell ${CODE_SPELL_ARGS} .