Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/containerised-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,26 @@ on:
type: boolean
default: false

env:
CRYSTAL_VERSION: 1.4.1

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run docker-compose test environment
run: ./test --coverage
timeout-minutes: 25
env:
CRYSTAL_VERSION: ${{ env.CRYSTAL_VERSION }}
- name: Upload coverage report
if: ${{ always() }}
uses: codecov/codecov-action@v2
with:
directory: coverage
fail_ci_if_error: true

todo-issues:
if: ${{ inputs.todo_issues }}
name: TODOs → GitHub Issues
Expand Down
108 changes: 47 additions & 61 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,72 @@ ARG CRYSTAL_VERSION=1.4.1
###############################################################################
# using 3.12 to match the version used by crystal
FROM alpine:3.12 as kcov
SHELL ["/bin/ash", "-euo", "pipefail", "-c"]

SHELL ["/bin/ash", "-eo", "pipefail", "-c"]

RUN apk update && \
apk add --no-cache \
curl \
# hadolint ignore=DL3018
RUN apk upgrade --no-cache apk \
&& apk add --update --no-cache \
build-base \
cmake \
make \
gcc \
g++ \
ninja \
python3 \
binutils-dev \
zlib-dev \
curl-dev \
elfutils-dev \
python3
elfutils-dev

WORKDIR /kcov
ENV KCOV_VERSION=40 CXXFLAGS="-D__ptrace_request=int"
RUN mkdir -p kcov-$KCOV_VERSION/build bin && \
curl --location https://github.com/SimonKagstrom/kcov/archive/v$KCOV_VERSION.tar.gz \
| tar xzC ./ && \
cd kcov-$KCOV_VERSION/build && \
cmake \
-Wno-dev \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/local \
.. && \
make --jobs 2 || exit 1 && \
make install DESTDIR=/usr || exit 1

# Extract binary dependencies
RUN for binary in "/usr/local/bin/kcov"; do \
ldd "$binary" | \
tr -s '[:blank:]' '\n' | \
grep '^/' | \
xargs -I % sh -c 'mkdir -p $(dirname deps%); cp % deps%;'; \
done
ENV KCOV_VERSION=40
# hadolint ignore=DL3003
RUN wget -q "https://github.com/SimonKagstrom/kcov/archive/v$KCOV_VERSION.tar.gz" -O - | tar xz -C ./ --strip-components 1 \
&& mkdir build \
&& cd build \
&& CXXFLAGS="-D__ptrace_request=int" cmake -G Ninja .. \
&& cmake --build . --target install

# Test Container
###############################################################################
FROM crystallang/crystal:${CRYSTAL_VERSION}-alpine as test
SHELL ["/bin/ash", "-euo", "pipefail", "-c"]

# - Add kcov dependencies
# - Add trusted CAs for communicating with external services
# - Add watchexec for running tests on change
# hadolint ignore=DL3018
RUN apk upgrade --no-cache apk \
&& apk add --update --no-cache \
bash \
python3 \
binutils-dev \
curl-dev \
elfutils-libelf \
ca-certificates \
curl \
iputils \
libelf \
libssh2-static \
lz4-dev \
lz4-static \
yaml-static \
&& apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing \
watchexec \
&& update-ca-certificates

# Add kcov
COPY --from=kcov /kcov/deps /
COPY --from=kcov /usr/local/bin/kcov /usr/bin/kcov
COPY --from=kcov /usr/local/bin/kcov* /usr/local/bin/
COPY --from=kcov /usr/local/share/doc/kcov /usr/local/share/doc/kcov

# Build crystal kcov tool
WORKDIR /app
RUN git clone --depth=1 https://github.com/Vici37/crystal-kcov
WORKDIR /app/crystal-kcov
RUN shards build && \
mv bin/crkcov /usr/bin/crkcov
# Build crystal-coverage tool
WORKDIR /crystal-coverage
RUN git clone --depth=1 https://github.com/lbguilherme/crystal-coverage . \
&& shards build --production --release \
&& mv bin/crystal-coverage /usr/bin/

WORKDIR /app

RUN rm -rf crystal-kcov
RUN rm -rf /crystal-coverage

# Set the commit through a build arg
ARG PLACE_COMMIT="DEV"

# - Add trusted CAs for communicating with external services
# - Add watchexec for running tests on change
RUN apk upgrade --no-cache apk \
&& \
apk add --no-cache \
bash \
ca-certificates \
curl \
iputils \
libelf \
libssh2-static \
lz4-dev \
lz4-static \
yaml-static \
&& \
apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing \
watchexec \
&& \
update-ca-certificates

COPY test-scripts /app/scripts

# Create a non-privileged user
Expand Down
2 changes: 1 addition & 1 deletion test-scripts/test-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ shards check --ignore-crystal-version -q &> /dev/null || shards install --ignore
if [[ "$watch" == "true" ]]; then
CRYSTAL_WORKERS=$(nproc) watchexec -e cr -c -r -w shard.lock -w src -w spec -- scripts/crystal-spec.sh -v $PARAMS
elif [[ "$coverage" == "true" ]]; then
CRYSTAL_WORKERS=$(nproc) crkcov --verbose --output --executable-args "$PARAMS"
CRYSTAL_WORKERS=$(nproc) crystal-coverage --print-only | crystal eval "$PARAMS"
else
CRYSTAL_WORKERS=$(nproc) scripts/crystal-spec.sh -v $PARAMS
fi