Skip to content

Commit

Permalink
gh-actions/github/run: Add action (#894)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Northey <ryan@synca.io>
  • Loading branch information
phlax committed Oct 26, 2023
1 parent 7a77284 commit 565e3c0
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions gh-actions/github/run/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

inputs:
command:
type: string
required: true
command-prefix:
type: string
default:
container-command:
type: string
default:
catch-errors:
type: boolean
default: false
error-match:
type: string
default: ERROR
warn-on-error:
type: boolean
default: false

env:
type: string


runs:
using: composite
steps:
- id: set_env
name: 'Set CI env ${{ inputs.target }}'
run: |
if [[ "${#INPUT_ENV}" -ne 0 ]]; then
SOURCETMP="$(mktemp)"
# TODO(phlax): Fix escaping
echo "${{ inputs.env }}" > "$SOURCETMP"
. "$SOURCETMP"
rm -rf "$SOURCETMP"
fi
shell: bash
env:
INPUT_ENV: ${{ inputs.env }}
- run: |
COMMAND=()
if [[ -n "${{ inputs.container-command }}" ]]; then
COMMAND+=(${{ inputs.container-command }})
fi
if [[ -n "${{ inputs.container-command }}" && -n "${{ inputs.command-prefix }}" ]]; then
COMMAND+=('${{ inputs.command-prefix }} ${{ inputs.command }}')
else
COMMAND+=(
${{ inputs.command-prefix }}
${{ inputs.command }})
fi
TMP_OUTPUT=$(mktemp)
"${COMMAND[@]}" 2> >(tee "$TMP_OUTPUT") || {
OUTPUT="$(grep ${{ inputs.error-match }} "$TMP_OUTPUT" | tail -n 1)"
rm -rf "$TMP_OUTPUT"
echo "${OUTPUT_PREFIX} ${OUTPUT}"
if [[ "${{ inputs.catch-errors }}" != "true" && "${{ inputs.warn-on-error }}" != "true" ]]; then
exit 1
fi
}
rm -rf "$TMP_OUTPUT"
shell: bash
env:
OUTPUT_PREFIX: ${{ inputs.warn-on-error == 'true' && '::warn::' || '::error::' }}

0 comments on commit 565e3c0

Please sign in to comment.