From 6f5bb3259d68d6065b735791e7e80154ab0aa4e5 Mon Sep 17 00:00:00 2001 From: Leon Kiefer Date: Thu, 15 Aug 2019 17:23:42 +0200 Subject: [PATCH] Actions v2 (#1) Updated to github action v2 Updated the action to use the action.yml file and input parameter. Updated Readme to show new workflow syntax. Added hardware input parameter --- Dockerfile | 9 +-------- README.md | 38 +++++++++++++++++++++----------------- action.yml | 27 +++++++++++++++++++++++++++ entrypoint.sh | 47 +++++++++++++++++++++++++++-------------------- 4 files changed, 76 insertions(+), 45 deletions(-) create mode 100644 action.yml diff --git a/Dockerfile b/Dockerfile index 7926271..3acf868 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,4 @@ FROM hexeo/arduino-builder -LABEL "com.github.actions.name"="Run arduino-builder" -LABEL "com.github.actions.description"="Run the arduino-builder for all sketches and see if they compile" -LABEL "com.github.actions.icon"="server" -LABEL "com.github.actions.color"="blue" - -LABEL "repository"="https://github.com/Legion2/arduino-builder-action" - -ADD entrypoint.sh /entrypoint.sh +COPY entrypoint.sh /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 2fcfd74..4ff54ef 100644 --- a/README.md +++ b/README.md @@ -3,27 +3,31 @@ Github Action to run arduino-builder for sketches and see if they compile. Used Arduino IDE version is `1.8.3`. ## Usage -``` -action "Build examples" { - uses = "Legion2/arduino-builder-action@master" - env = { - BOARD_NAME = "arduino:avr:leonardo" - } -} +See [action.yml](action.yml) for comprehensive list of parameters. + +Basic: +```yaml +name: Build examples +on: push +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Build all example sketches + uses: Legion2/arduino-builder-action@v2.0.0 + with: + board: "arduino:avr:leonardo" ``` ### Arguments -Specified arguments override any default arguments passed to arduino-builder, with the exception of the sketch parameter. -The default arguments set all mandatory parameters. -Use the [Environment variables](#environment-variables) to change some of the parameters. +Specified arguments override any input parameters passed to arduino-builder, with the exception of the sketch input parameter. +Only use arguments if the input parameters don't provide the feature you need. +See the the [action.yml](action.yml) for comprehensive list of input parameters. -### Environment variables -* **`SKETCH_PATH`** *(optional)* : Path to a single sketch -* **`SKETCH_DIRECTORY_PATH`** *(optional)* : Directory in which to search for sketches (default: `examples/`) -* **`BOARD_NAME`** *(optional)* : Fully Qualified Board Name (default: `arduino:avr:uno`) -* **`LIBRARIES_PATH`** *(optional)* : Folder containing Arduino libraries. -Use this folder to install required 3rd-party libraries. -Libraries SHOULD be installed by a parent action e.g. [Download GitHub Release](https://github.com/marketplace/actions/download-github-release) (default: `libraries/`) +### Install Libraries +Libraries SHOULD be installed by a previous step in the job in `libraries/`. +You can use [Download GitHub Release Action](https://github.com/marketplace/actions/download-github-release) to install a library form a GitHub Release. ## License The Dockerfile and associated scripts and documentation in this project are released under the [Apache-2.0 License](LICENSE). diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..019f9bf --- /dev/null +++ b/action.yml @@ -0,0 +1,27 @@ +name: 'Run arduino-builder' +description: 'Run the arduino-builder for all sketches and see if they compile' +author: 'Leon Kiefer' +inputs: + sketch: + description: 'Path to a single sketch' + required: false + sketchDirectory: + description: 'Directory in which to search for sketches' + default: 'examples' + board: + description: 'Fully Qualified Board Name' + default: 'arduino:avr:uno' + libraries: + description: | + Directory containing Arduino libraries. + Use this directory to install required 3rd-party libraries. + default: 'libraries' + hardware: + description: 'Directory containing Arduino platforms' + default: 'hardware' +runs: + using: 'docker' + image: 'Dockerfile' +branding: + icon: 'server' + color: 'blue' \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index 0a10d1d..c0ce914 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,37 +1,44 @@ #!/bin/sh set -e -if [ -z "$BOARD_NAME" ]; then - BOARD_NAME="arduino:avr:uno" +BUILDER_PATH="/opt/arduino" +LIBRARIES_PATH="$BUILDER_PATH/libraries:$GITHUB_WORKSPACE/../" + +SKETCH_PATH="$INPUT_SKETCH" +BOARD_NAME="$INPUT_BOARD" +SKETCH_DIRECTORY_PATH="$INPUT_SKETCHDIRECTORY" + +if [ -d "$INPUT_LIBRARIES" ]; then + LIBRARIES_PATH="$LIBRARIES_PATH:$INPUT_LIBRARIES" fi -if [ -z "$LIBRARIES_PATH" ]; then - LIBRARIES_PATH="${GITHUB_WORKSPACE}/libraries/" - if [ ! -d "$LIBRARIES_PATH" ]; then - LIBRARIES_PATH=$GITHUB_WORKSPACE - fi +getLibraryOptions() { + local IFS=":" + for library in $1 + do + echo -n " -libraries $library" + done +} + +BUILDER_OPTIONS="-hardware $BUILDER_PATH/hardware -tools $BUILDER_PATH/hardware/tools/avr -tools $BUILDER_PATH/tools-builder `getLibraryOptions $LIBRARIES_PATH` -fqbn $BOARD_NAME" + +if [ -d "$INPUT_HARDWARE" ]; then + BUILDER_OPTIONS="$BUILDER_OPTIONS -hardware $INPUT_HARDWARE" fi -if [ ! -z "$SKETCH_PATH" ]; then - SKETCH_PATH=$(readlink -f "$SKETCH_PATH") - cd /opt/arduino +if [ -n "$SKETCH_PATH" ]; then if [ -z "$1" ]; then - ./arduino-builder -hardware ./hardware -tools ./hardware/tools/avr -tools ./tools-builder -libraries ./libraries -libraries $LIBRARIES_PATH -libraries $GITHUB_WORKSPACE/../ -fqbn $BOARD_NAME "$SKETCH_PATH" + arduino-builder $BUILDER_OPTIONS "$SKETCH_PATH" else - ./arduino-builder "$@" "$SKETCH_PATH" + arduino-builder "$@" "$SKETCH_PATH" fi else - if [ -z "$SKETCH_DIRECTORY_PATH" ]; then - SKETCH_DIRECTORY_PATH="${GITHUB_WORKSPACE}/examples/" - fi - - cd /opt/arduino - for sketch in `find "${SKETCH_DIRECTORY_PATH}" -name '*.ino'` + for sketch in `find "$SKETCH_DIRECTORY_PATH" -name '*.ino'` do if [ -z "$1" ]; then - ./arduino-builder -hardware ./hardware -tools ./hardware/tools/avr -tools ./tools-builder -libraries ./libraries -libraries $LIBRARIES_PATH -libraries $GITHUB_WORKSPACE/../ -fqbn $BOARD_NAME $sketch + arduino-builder $BUILDER_OPTIONS "$sketch" else - ./arduino-builder "$@" $sketch + arduino-builder "$@" "$sketch" fi done fi