-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added Dockerfile - Integrated with Codecov and Docker Hub - Implement fixes recommended by shellcheck - Updated documentation
- Loading branch information
Dmytro Konstantinov
authored
May 10, 2019
1 parent
f518213
commit 97d53af
Showing
7 changed files
with
164 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.dockerignore | ||
.git* | ||
.git?* | ||
bin/docker | ||
coverage | ||
Dockerfile | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
workflow "Codecov" { | ||
on = "push" | ||
resolves = [ | ||
"Publish coverage report" | ||
] | ||
} | ||
|
||
action "Publish coverage report" { | ||
uses = "./." | ||
secrets = [ | ||
"CODECOV_TOKEN" | ||
] | ||
runs = "/etc/entrypoint.d/login_shell" | ||
args = [ | ||
"bash <(curl -s https://codecov.io/bash) -t ${CODECOV_TOKEN} -R ${GITHUB_WORKSPACE} -s /home/coverage -Z" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
FROM debian:stable-slim AS base | ||
LABEL maintainer="UmkaDK <[email protected]>" | ||
COPY ./docker-fs / | ||
RUN cp /etc/skel/.??* /root \ | ||
RUN apt-get -y update \ | ||
&& apt-get -y install \ | ||
bash \ | ||
bc \ | ||
binutils \ | ||
jq \ | ||
libcurl4-openssl-dev \ | ||
libdw1 \ | ||
libiberty-dev \ | ||
python \ | ||
zlib1g \ | ||
&& apt-get --purge autoremove \ | ||
&& apt-get clean \ | ||
&& cp /etc/skel/.??* /root \ | ||
&& adduser \ | ||
--quiet \ | ||
--disabled-password \ | ||
|
@@ -12,25 +25,15 @@ RUN cp /etc/skel/.??* /root \ | |
--gecos "" \ | ||
payload \ | ||
&& cp /etc/skel/.??* /home \ | ||
&& chown -R payload:payload /home \ | ||
&& apt-get -y update \ | ||
&& apt-get -y install \ | ||
bash \ | ||
binutils \ | ||
libcurl4-openssl-dev \ | ||
libdw1 \ | ||
libiberty-dev \ | ||
python \ | ||
zlib1g \ | ||
&& apt-get --purge autoremove \ | ||
&& apt-get clean | ||
&& chown -R payload:payload /home /mnt | ||
ENTRYPOINT ["/etc/entrypoint.d/login_shell"] | ||
|
||
FROM base AS build | ||
RUN apt-get -y update \ | ||
&& apt-get -y install \ | ||
binutils-dev \ | ||
cmake \ | ||
curl \ | ||
gcc \ | ||
g++ \ | ||
git \ | ||
|
@@ -52,11 +55,27 @@ RUN git clone --depth 1 --branch v36 https://github.com/SimonKagstrom/kcov.git \ | |
&& make install | ||
ENTRYPOINT ["/etc/entrypoint.d/login_shell"] | ||
|
||
FROM base AS latest | ||
COPY --from=build /usr/local /usr/local | ||
COPY --chown=payload . /home | ||
RUN rm -Rf /home/docker-fs \ | ||
&& chown -R payload:payload /mnt | ||
FROM build AS clean | ||
WORKDIR /home | ||
COPY --chown=payload . . | ||
RUN rm -Rf \ | ||
./docker-fs \ | ||
./bats-core \ | ||
./kcov | ||
USER payload | ||
RUN ./bin/test \ | ||
&& TZ=UTC git show \ | ||
--pretty=tformat:"%H%+D%+ad%n%+s" \ | ||
--date=format-local:"%c %Z" \ | ||
| head -5 > ./VERSION \ | ||
&& rm -Rf ./.git | ||
VOLUME ["/mnt"] | ||
ENTRYPOINT ["/etc/entrypoint.d/test_getopts_long"] | ||
|
||
FROM clean AS final | ||
USER root | ||
COPY --from=build --chown=root /usr/local /usr/local | ||
COPY --from=clean --chown=payload /home /home | ||
USER payload | ||
WORKDIR /mnt | ||
VOLUME ["/mnt"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
CONTAINER='umkadk/getopts_long' | ||
CMD="${1}" && shift | ||
|
||
case "${CMD}" in | ||
'b'|'build') | ||
if [[ -z "${*}" ]]; then docker image build --tag "${CONTAINER}" "${PWD}" | ||
else docker image build ${@} --tag "${CONTAINER}" "${PWD}"; fi | ||
;; | ||
'r'|'run') | ||
docker container run --rm --init -it -v "${PWD}:/mnt" "${CONTAINER}" "${@}" | ||
;; | ||
*) | ||
echo "${0}: Unknown command -- ${cmd}" >&2 | ||
exit 1 | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,72 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
TEMP_DIR="$(mktemp -d -t kcov.XXXXXXXXX)" | ||
trap "rm -Rf ${TEMP_DIR}" EXIT | ||
|
||
bats --tap --recursive "${@:-./test}" | ||
: "${GETOPTS_LONG_LIB:=./lib}" | ||
: "${GETOPTS_LONG_TEST:=./test}" | ||
: "${GETOPTS_LONG_COVERAGE:=./coverage}" | ||
|
||
__exit() { | ||
echo "${0}: ${1:?Missing required parameter -- error message}" >&2 | ||
exit "${2:-1}" | ||
} | ||
|
||
path_exists?() { | ||
: "${1:?Missing required argument -- directory path}" | ||
[[ -e "${1}" ]] || __exit "Path not found -- ${1}" | ||
} | ||
|
||
print_coverage_diff() { | ||
: "${1:?Missing required argument -- new code coverage}" | ||
|
||
local commit="$(head -c7 /home/VERSION)" | ||
local coverage="$(jq -r .percent_covered "/home/coverage/coverage.json")" | ||
local diff=$(echo "${coverage} - ${1}" | bc -l) | ||
|
||
local label="%+.2f%% compared to ${commit}" | ||
local color_label="\e[01;%sm%+.2f%%\e[00m compared to ${commit}" | ||
|
||
if tty -s && [[ "${diff}" -gt '0' ]]; then printf "${color_label}" 32 "${diff}" | ||
elif tty -s && [[ "${diff}" -lt '0' ]]; then printf "${color_label}" 31 "${diff}" | ||
elif [[ "${diff}" == '0' ]]; then printf "unchanged compared to ${commit}" | ||
else printf "${label}" "${diff}"; fi | ||
} | ||
|
||
path_exists? "${GETOPTS_LONG_LIB}" | ||
path_exists? "${GETOPTS_LONG_TEST}" | ||
|
||
# Run bats | ||
TEST_DIR="${*:-${GETOPTS_LONG_TEST}}" | ||
echo "Running tests: ${TEST_DIR} " | ||
bats --tap --recursive "${TEST_DIR}" | ||
[ -n "${*}" ] && exit | ||
|
||
echo "Generating coverage report: ./coverage/index.html" | ||
kcov --clean --include-path=./lib ${TEMP_DIR} bats --recursive ./test | ||
# Setup exit trap | ||
TEMP_DIR="$(mktemp -d -t kcov.XXXXXXXXX)" | ||
trap 'rm -Rf ${TEMP_DIR}' EXIT | ||
|
||
# Run kcov | ||
echo "Generating coverage report: ${GETOPTS_LONG_COVERAGE}/index.html" | ||
kcov --clean --include-path="${GETOPTS_LONG_LIB}" \ | ||
"${TEMP_DIR}" \ | ||
bats --recursive "${GETOPTS_LONG_TEST}" | ||
|
||
# Clean up kcov report | ||
rm ${TEMP_DIR}/bats/{bcov.css,amber.png,glass.png} | ||
sed -i 's#"../data/bcov.css"#"data/bcov.css"#g' ${TEMP_DIR}/bats/*.html | ||
rm "${TEMP_DIR}"/bats/{bcov.css,amber.png,glass.png} | ||
sed -i 's#"../data/bcov.css"#"data/bcov.css"#g' "${TEMP_DIR}"/bats/*.html | ||
|
||
# Present kcov report | ||
cp -LR ${TEMP_DIR}/bats ./coverage | ||
rm -Rf "${GETOPTS_LONG_COVERAGE}" | ||
cp -LR "${TEMP_DIR}/bats" "${GETOPTS_LONG_COVERAGE}" | ||
|
||
# Total code coverage | ||
COVERAGE="$(jq -r .percent_covered "${GETOPTS_LONG_COVERAGE}/coverage.json")" | ||
printf "Code covered: %s%% " "${COVERAGE}" | ||
|
||
# Code coverage diff | ||
if [[ -e "/.dockerenv" && "${PWD}" != "/home" ]]; then | ||
printf "(%s)" "$(print_coverage_diff "${COVERAGE}")" | ||
fi | ||
|
||
# Finish code coverage stats with a new line | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters