add entrypoint init

This commit is contained in:
lizheming 2018-12-10 00:03:07 +08:00
parent 39c66c7433
commit 1e25473e60
2 changed files with 75 additions and 0 deletions

13
Dockerfile Normal file
View File

@ -0,0 +1,13 @@
FROM node:lts-alpine
LABEL maintainer="lizheming <i@imnerd.org>"
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"]

62
entrypoint.sh Normal file
View File

@ -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