From 297920dcc1fa9a690388b362221ee7ef8986cbc1 Mon Sep 17 00:00:00 2001 From: Petro Protsakh Date: Mon, 13 Jan 2020 17:55:22 +0200 Subject: [PATCH] Detailed run control with entrypoint script (#1) --- Dockerfile | 8 ++++++++ action.yml | 17 ++++++++--------- entrypoint.sh | 21 +++++++++++++++++++++ 3 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 Dockerfile create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d033635 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM ubuntu:18.04 +RUN apt-get update && apt-get install -y curl +RUN curl -L -o /opa https://openpolicyagent.org/downloads/latest/opa_linux_amd64 +RUN chmod 755 /opa +RUN /opa version +COPY entrypoint.sh / +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/action.yml b/action.yml index aea4480..87b0b64 100644 --- a/action.yml +++ b/action.yml @@ -1,18 +1,17 @@ -name: OPA Test -description: Run Open Policy Agent tests -author: Petro Protsakh +name: "OPA Test" +description: "Run Open Policy Agent tests" +author: "Petro Protsakh" branding: icon: check-square color: green inputs: tests: - description: Rego file or directory path where to discover tests. Defaults to repository root. + description: "Rego file or directory path where to discover tests. Defaults to repository root." required: false default: ./ + options: + description: "Additional OPA command line flags. Example: `--verbose --timeout 3`. See `opa test --help` for more." + required: false runs: using: docker - image: docker://openpolicyagent/opa:latest - args: - - test - - ${{ inputs.tests }} - - -v + image: Dockerfile diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..7b7f340 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +printf "\n\n" +echo "# Open Policy Agent" +/opa version +printf "\n\n" + +IFS=';' +mapfile -t lines < <(echo "$INPUT_TESTS" | grep -v "^$") + +e_code=0 +for line in "${lines[@]}"; do + read -r -a args <<< "$line" + cmd="/opa test ${args[*]} $INPUT_OPTIONS" + echo " 🚀 Running: $cmd" + printf "\n" + eval "$cmd" || e_code=1 + printf "\n\n" +done + +exit $e_code