Add option output_action (#178)

This commit is contained in:
Simon Lecoq
2021-03-08 23:38:40 +01:00
committed by GitHub
parent 64fe0c8ef0
commit e0bfbf62fd
5 changed files with 145 additions and 29 deletions

View File

@@ -182,12 +182,11 @@ inputs:
description: Use mocked data instead of live APIs
default: no
# Use a pre-built image from GitHub registry when using unreleased versions of "lowlighter/metrics"
# This option has no effect on forks (images will always be rebuilt from Dockerfile)
# Use a pre-built image from GitHub registry (experimental)
# See https://github.com/users/lowlighter/packages/container/package/metrics for more information
use_prebuilt_image:
description: Use pre-built image from GitHub registry
default: yes
default: ""
# ====================================================================================
# 📰 Recent activity
@@ -847,7 +846,6 @@ runs:
steps:
- run: |
# Create environment file from inputs and GitHub variables
echo "::group::Metrics docker image setup"
cd $METRICS_ACTION_PATH
touch .env
for INPUT in $(echo $INPUTS | jq -r 'to_entries|map("INPUT_\(.key|ascii_upcase)=\(.value|@uri)")|.[]'); do
@@ -866,11 +864,20 @@ runs:
# Image tag (extracted from version or from env)
METRICS_TAG=v$(echo $METRICS_VERSION | sed -r 's/^([0-9]+[.][0-9]+).*/\1/')
if [[ $METRICS_USE_PREBUILT_IMAGE ]]; then
METRICS_TAG=$METRICS_USE_PREBUILT_IMAGE
echo "Pre-built image: yes"
fi
echo "Image tag: $METRICS_TAG"
# Image name
# Pre-built image
if [[ $METRICS_USE_PREBUILT_IMAGE ]]; then
echo "Using pre-built version $METRICS_TAG, will pull docker image from GitHub registry"
METRICS_IMAGE=ghcr.io/lowlighter/metrics:$METRICS_TAG
docker image pull $METRICS_IMAGE > /dev/null
# Official action
if [[ $METRICS_SOURCE == "lowlighter" ]]; then
elif [[ $METRICS_SOURCE == "lowlighter" ]]; then
# Is released version
set +e
METRICS_IS_RELEASED=$(expr $(expr match $METRICS_VERSION .*-beta) == 0)
@@ -880,14 +887,7 @@ runs:
if [[ "$METRICS_IS_RELEASED" -gt "0" ]]; then
echo "Using released version $METRICS_TAG, will pull docker image from GitHub registry"
METRICS_IMAGE=ghcr.io/lowlighter/metrics:$METRICS_TAG
docker image pull $METRICS_IMAGE
# Use registry for unreleased version with pre-built images
elif [[ ! $METRICS_USE_PREBUILT_IMAGE =~ ^([Ff]alse|[Oo]ff|[Nn]o|0)$ ]]; then
METRICS_TAG="$METRICS_TAG-beta"
echo "Image tag (updated): $METRICS_TAG"
echo "Using pre-built version $METRICS_TAG, will pull docker image from GitHub registry"
METRICS_IMAGE=ghcr.io/lowlighter/metrics:$METRICS_TAG
docker image pull $METRICS_IMAGE
docker image pull $METRICS_IMAGE > /dev/null
# Rebuild image for unreleased version
else
echo "Using an unreleased version ($METRICS_VERSION)"
@@ -902,16 +902,15 @@ runs:
# Build image if necessary
set +e
docker image inspect $METRICS_IMAGE
docker image inspect $METRICS_IMAGE > /dev/null
METRICS_IMAGE_NEEDS_BUILD="$?"
set -e
if [[ "$METRICS_IMAGE_NEEDS_BUILD" -gt "0" ]]; then
echo "Image $METRICS_IMAGE is not present locally, rebuilding it from Dockerfile"
docker build -t $METRICS_IMAGE .
docker build -t $METRICS_IMAGE . > /dev/null
else
echo "Image $METRICS_IMAGE is present locally"
fi
echo "::endgroup::"
# Run docker image with current environment
docker run --init --volume $GITHUB_EVENT_PATH:$GITHUB_EVENT_PATH --env-file .env $METRICS_IMAGE