Skip to content

Commit

Permalink
feat: add coverage command
Browse files Browse the repository at this point in the history
  • Loading branch information
zeriyoshi committed Aug 22, 2024
1 parent 5b636a1 commit eba5753
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodule: true
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodule: true
- name: Setup buildx
uses: docker/setup-buildx-action@v3
- name: Build container
run: |
docker compose build --pull --no-cache --build-arg PLATFORM="linux/amd64" --build-arg IMAGE="php" --build-arg TAG="${{ matrix.version }}-${{ matrix.type }}-${{ matrix.distro }}"
- name: Test with gcov
run: |
docker compose run -v "$(pwd)/ext:/ext" --rm shell /bin/sh -c 'pskel test gcov && lcov --capture --directory "/ext" --output-file "/ext/lcov.info" --exclude "/usr/local/include/*" --exclude "third_party/*" && lcov --list "/ext/lcov.info"'
docker compose run -v "$(pwd)/ext:/ext" --rm shell pskel coverage'
- name: Upload coverage to artifact
uses: actions/upload-artifact@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG PLATFORM=${BUILDPLATFORM:-linux/amd64}
ARG IMAGE=php
ARG TAG=8.3-zts-bookworm
ARG TAG=8.3-cli-bookworm

FROM --platform=${PLATFORM} ${IMAGE}:${TAG}

Expand All @@ -9,6 +9,7 @@ COPY ./pskel.sh /usr/local/bin/pskel
ENV USE_ZEND_ALLOC=0
ENV USE_TRACKED_ALLOC=1
ENV ZEND_DONT_UNLOAD_MODULES=1
ENV LC_ALL="C"

RUN docker-php-source extract \
&& if test -f "/etc/debian_version"; then \
Expand Down
60 changes: 36 additions & 24 deletions pskel.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
#!/bin/sh -e

get_ext_dir() {
PSKEL_EXT_DIR="/ext"

if test -d "${CODESPACE_VSCODE_FOLDER}"; then
echo "[Pskel] GitHub Codespace workspace detected, use \"${CODESPACE_VSCODE_FOLDER}/ext\"." >&2
PSKEL_EXT_DIR="${CODESPACE_VSCODE_FOLDER}/ext"
elif test -d "/workspaces/pskel/ext"; then
echo "[Pskel] Development Containers workspace detected, use \"/workspaces/pskel/ext\"." >&2
PSKEL_EXT_DIR="/workspaces/pskel/ext"
else
if test -f "/ext/.gitkeep" && test $(cat "/ext/.gitkeep") = "pskel_uninitialized"; then
echo "[Pskel] Uninitialized project detected, initialize default skeleton." >&2
cmd_init "skeleton"
fi
fi

if test -f "${PSKEL_EXT_DIR}/.gitkeep" && test $(cat "${PSKEL_EXT_DIR}/.gitkeep") = "pskel_uninitialized"; then
echo "[Pskel] Project not initialized! Please run \"pskel init\"" >&2
exit 1
fi

echo "${PSKEL_EXT_DIR}"
}

cmd_usage() {
cat << EOF
Usage: ${0} [task] ...
Expand All @@ -19,16 +43,7 @@ EOF
return 0
fi

PSKEL_EXT_DIR="/ext"

if test -d "${CODESPACE_VSCODE_FOLDER}"; then
echo "[Pskel] GitHub Codespace workspace detected, use \"${CODESPACE_VSCODE_FOLDER}/ext\"." >&2
PSKEL_EXT_DIR="${CODESPACE_VSCODE_FOLDER}/ext"
elif test -d "/workspaces/pskel/ext"; then
echo "[Pskel] Development Containers workspace detected, use \"/workspaces/pskel/ext\"." >&2
PSKEL_EXT_DIR="/workspaces/pskel/ext"
fi

PSKEL_EXT_DIR="$(get_ext_dir)"
/usr/local/bin/php "/usr/src/php/ext/ext_skel.php" --ext "${1}" --dir "/tmp" ${@}
rm "${PSKEL_EXT_DIR}/.gitkeep"
rsync -av "/tmp/${1}/" "${PSKEL_EXT_DIR}/"
Expand Down Expand Up @@ -91,20 +106,7 @@ EOF
fi
done

PSKEL_EXT_DIR="/ext"

if test -d "${CODESPACE_VSCODE_FOLDER}"; then
echo "[Pskel] GitHub Codespace workspace detected, use \"${CODESPACE_VSCODE_FOLDER}/ext\"." >&2
PSKEL_EXT_DIR="${CODESPACE_VSCODE_FOLDER}/ext"
elif test -d "/workspaces/pskel/ext"; then
echo "[Pskel] Development Containers workspace detected, use \"/workspaces/pskel/ext\"." >&2
PSKEL_EXT_DIR="/workspaces/pskel/ext"
else
if test -f "/ext/.gitkeep" && test $(cat "/ext/.gitkeep") = "pskel_uninitialized"; then
echo "[Pskel] Uninitialized project detected, initialize default skeleton." >&2
cmd_init "skeleton"
fi
fi
PSKEL_EXT_DIR="$(get_ext_dir)"

cd "${PSKEL_EXT_DIR}"
"${CMD}ize"
Expand Down Expand Up @@ -144,6 +146,15 @@ EOF
cd -
}

cmd_coverage() {
cmd_test "gcov"

PSKEL_EXT_DIR="$(get_ext_dir)"

lcov --capture --directory "${PSKEL_EXT_DIR}" ${LCOV_OPTIONS} --exclude "/usr/local/include/*" --output-file "${PSKEL_EXT_DIR}/lcov.info"
lcov --list "${PSKEL_EXT_DIR}/lcov.info"
}

if [ $# -eq 0 ]; then
cmd_usage
exit 1
Expand All @@ -154,6 +165,7 @@ case "${1}" in
init) shift && cmd_init "${@}";;
test) shift && cmd_test "${@}";;
build) shift && cmd_build "${@}";;
coverage) shift && cmd_coverage "${@}";;
*)
echo "${0} error: invalid command: '${1}'" >&2
cmd_usage
Expand Down

0 comments on commit eba5753

Please sign in to comment.