From 1e25473e609e4b205eeaa86814cdf6bedd861f35 Mon Sep 17 00:00:00 2001 From: lizheming Date: Mon, 10 Dec 2018 00:03:07 +0800 Subject: [PATCH] add entrypoint init --- Dockerfile | 13 +++++++++++ entrypoint.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 Dockerfile create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6a1457c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node:lts-alpine +LABEL maintainer="lizheming " +RUN apk upgrade --no-cache && apk add --no-cache bash + +ENV ROOT /usr/src/app +WORKDIR ${ROOT} + +RUN npm install coveralls + +ADD ./entrypoint.sh . +RUN chmod +x ./entrypoint.sh + +ENTRYPOINT ["/usr/src/app/entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..84fb232 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +set -e + +start_time=$(date +%s.%N) +files="${FILES:-$PLUGIN_FILES}" + +echo "-- Pushing coverage to Coveralls.io..." + +# check coveralls token exist. +if [[ -n $PLUGIN_TOKEN ]]; then + COVERALLS_REPO_TOKEN=$PLUGIN_TOKEN +fi +if [[ -z $COVERALLS_REPO_TOKEN ]]; then + echo "-- Error: missing coveralls token" + exit 1 +fi + +vfiles="" +for file in $(echo $files | tr -d '[[:space:]]' | tr "," "\n"); do + if [[ -f $PWD/$file ]]; then + vfiles="$vfiles -f $PWD/$file" + + echo "-- Sending $file to Coveralls.io --" + eval 'cat $PWD/$file | ./node_modules/coveralls/bin/coveralls.js' + fi +done + +token="-t $COVERALLS_REPO_TOKEN" +branch="" +commit="" +pr="" +buildnum="" +tag="" +if [[ -n $DRONE_BRANCH ]]; then + branch="-B $DRONE_BRANCH" +fi +if [[ -n $DRONE_COMMIT ]]; then + commit="-C $DRONE_COMMIT" +fi +if [[ -n $DRONE_PULL_REQUEST ]]; then + pr="-P $DRONE_PULL_REQUEST" +fi +if [[ -n $DRONE_BUILD_NUMBER ]]; then + buildnum="-b $DRONE_BUILD_NUMBER" +fi +if [[ -n $DRONE_TAG ]]; then + tag="-T $DRONE_TAG" +fi + +if [[ $PLUGIN_DEBUG = "true" ]]; then + echo "-- DEBUG: running following command..." + echo "-- DEBUG: coveralls $token $vfiles $branch $commit $pr $buildnum $tag" +fi + +end_time=$(date +%s.%N) +echo "duration: $(echo "$end_time $start_titme" | awk '{printf "%f", $1 - $2}')s" + +if [[ $exitcode -eq 0 ]]; then + echo "-- Coverage successfully pushed to Coveralls!" +else + echo "-- Coverage failed to push to Coveralls!" +fi \ No newline at end of file