use github actions

This commit is contained in:
nerdyscout 2020-09-27 08:48:49 +00:00
parent 659ae27e7b
commit 00b93cb6e7
4 changed files with 252 additions and 1 deletions

10
Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM setsoft/kicad_auto:latest
LABEL AUTHOR Salvador E. Tropea <set@ieee.org>
LABEL Description="export various files from KiCad projects"
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
WORKDIR /mnt
ENTRYPOINT [ "/entrypoint.sh" ]

View File

@ -17,6 +17,7 @@ To learn more about KiBot variants visit the [example repo](https://inti-cmnb.gi
* [Usage](#usage)
* [Installation](#installation)
* [Usage for CI/CD](#usage-for-cicd)
* [Github Actions](#usage-of-github-actions)
* [Credits](#credits)
## Introduction
@ -1193,6 +1194,44 @@ In order to run KiBot on these environments you need a lot of software installed
For more information about the docker images visit [kicad_debian](https://github.com/INTI-CMNB/kicad_debian) and [kicad_auto](https://github.com/INTI-CMNB/kicad_auto).
### Usage of Github Actions
You need to put a [config.kibot.yaml](#configuration) file into the KiCad project folder.
```yaml
name: example
on:
push:
paths:
- '**.sch'
- '**.kicad_pcb'
pull_request:
paths:
- '**.sch'
- '**.kicad_pcb'
jobs:
example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: INTI-CMNB/KiBot@v0.7.0
with:
# Required - kibot config file
config: config.kibot.yaml
# optional - prefix to output defined in config
dir: output
# optional - schematic file
schema: '*.sch'
# optional - PCB design file
board: '*.kicad_pcb'
- name: upload results
uses: actions/upload-artifact@v2.0
with:
name: output
path: output
```
## Credits
@ -1204,6 +1243,6 @@ For more information about the docker images visit [kicad_debian](https://github
- **PcbDraw**: Jan Mrázek (@yaqwsx)
- **Contributors**:
- **Error filters ideas**: Leandro Heck (@leoheck)
- **SVG output**: @nerdyscout
- **GitHub Actions Integration**: @nerdyscout
- **Others**:
- **Robot in the logo**: Christian Plaza (from pixabay)

32
action.yml Normal file
View File

@ -0,0 +1,32 @@
name: 'KiBot'
description: 'auto generate exports (schematics, gerbers, plots) for any KiCAD project.'
author: 'Salvador E. Tropea'
inputs:
config:
description: 'The plotting config file to use'
required: true
dir:
description: 'The output directory [default: .]'
required: false
default: '.'
board:
description: 'The PCB .kicad-pcb board file [default: first *.kicad_pcb found]'
required: false
# TODO: fix default 'first *.kicad_pcb file found'
# default: '$(ls *.kicad_pcb | head -n1)'
schema:
description: 'The schematic file (.sch) [default: first *.sch found]'
required: false
# TODO: fix default 'first *.sch file found'
# default: '$(ls *.sch | head -n1)'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- -c ${{ inputs.config }}
- -d ${{ inputs.dir }}
- -b ${{ inputs.board }}
- -e ${{ inputs.schema }}
branding:
icon: 'cpu'
color: 'green'

170
entrypoint.sh Executable file
View File

@ -0,0 +1,170 @@
#!/bin/bash
# Script configurations
SCRIPT="KiBot"
# Mandatory arguments
margs=1
# Arguments and their default values
CONFIG=""
BOARD=""
SCHEMA=""
SKIP=""
DIR=""
# Exit error code
EXIT_ERROR=1
function msg_example {
echo -e "example: $SCRIPT -d docs -b example.kicad_pcb -e example.sch -c docs.kibot.yaml"
}
function msg_usage {
echo -e "usage: $SCRIPT [OPTIONS]... -c <yaml-config-file>"
}
function msg_disclaimer {
echo -e "This is free software: you are free to change and redistribute it"
echo -e "There is NO WARRANTY, to the extent permitted by law.\n"
echo -e "See <https://github.com/INTI-CMNB/KiBot>."
}
function msg_illegal_arg {
echo -e "$SCRIPT: illegal option $@"
}
function msg_help {
echo -e "Mandatory arguments:"
echo -e " -c, --config FILE .kibot.yaml config file"
echo -e "\nOptional control arguments:"
echo -e " -d, --dir DIR output path. Default: current dir, will be used as prefix of dir configured in config file"
echo -e " -b, --board FILE .kicad_pcb board file. Default: first board file found in current folder."
echo -e " -e, --schema FILE .sch schematic file. Default: first schematic file found in current folder."
echo -e " -s, --skip Skip preflights, comma separated or 'all'"
echo -e "\nMiscellaneous:"
echo -e " -v, --verbose annotate program execution"
echo -e " -h, --help display this message and exit"
}
function msg_more_info {
echo -e "Try '$SCRIPT --help' for more information."
}
function help {
msg_usage
echo ""
msg_help
echo ""
msg_example
echo ""
msg_disclaimer
}
function illegal_arg {
msg_illegal_arg "$@"
echo ""
msg_usage
echo ""
msg_example
echo ""
msg_more_info
}
function usage {
msg_usage
echo ""
msg_more_info
}
# Ensures that the number of passed args are at least equals
# to the declared number of mandatory args.
# It also handles the special case of the -h or --help arg.
function margs_precheck {
if [ "$1" -lt "$margs" ]; then
if [ "$2" == "--help" ] || [ "$2" == "-h" ]; then
help
else
usage
fi
exit $EXIT_ERROR
fi
}
# Ensures that all the mandatory args are not empty
function margs_check {
if [ "$#" -lt "$margs" ]; then
usage
exit $EXIT_ERROR
fi
}
function args_process {
while [ "$1" != "" ];
do
case "$1" in
-c | --config ) shift
CONFIG="$1"
;;
-b | --board ) shift
BOARD="-b $1"
;;
-e | --schematic ) shift
SCHEMA="-e $1"
;;
-d | --dir) shift
DIR="-d $1"
;;
-s | --skip) shift
SKIP="-s $1"
;;
-v | --verbose )
VERBOSE="-v"
;;
-h | --help )
help
exit
;;
*)
illegal_arg "$@"
exit $EXIT_ERROR
;;
esac
shift
done
}
function run {
CONFIG="$(echo "$CONFIG" | tr -d '[:space:]')"
if [ -d .git ]; then
/usr/bin/kicad-git-filters.py
fi
if [ -f $CONFIG ]; then
kibot -c $CONFIG $DIR $BOARD $SCHEMA $SKIP $VERBOSE
else
echo "config file '$CONFIG' not found!"
exit $EXIT_ERROR
fi
}
function main {
margs_precheck "$#" "$1"
args_process "$@"
run
}
# Removes quotes
args=$(xargs <<<"$@")
# Arguments as an array
IFS=' ' read -a args <<< "$args"
# Run main
main "${args[@]}"