Skip to content

Commit

Permalink
CI improvements
Browse files Browse the repository at this point in the history
* Setup GitHub Actions
* Add clang builds to HerculesCI
* Remove nix builds from TravisCI
* Add folding to TravisCI
  • Loading branch information
jbboehr committed Jul 1, 2020
1 parent 5b9e05c commit 2770f82
Show file tree
Hide file tree
Showing 35 changed files with 875 additions and 341 deletions.
77 changes: 77 additions & 0 deletions .ci/fold.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env bash

# adapted from: https://gist.github.com/prisis/e050c4da44c6ee7fa1519912eac19563

set -e -o pipefail

nanoseconds() {
local cmd="date"
local format="+%s%N"
local os=$(uname)

if hash gdate > /dev/null 2>&1; then
cmd="gdate"
elif [[ "$os" = Darwin ]]; then
format="+%s000000000"
fi

$cmd -u $format
}

# Arguments:
# $1 fold name
# $2 command to execute
travisfold () (
set -e -o pipefail
local title=$1
shift
local fold=$(echo "$title" | sed -r 's/[^-_A-Za-z\d]+/./g')
local id=$(printf %08x $(( RANDOM * RANDOM )))
local start=$(nanoseconds)

function travisfoldend() {
local end=$(nanoseconds)
echo -e "\\ntravis_time:end:$id:start=$start,finish=$end,duration=$(($end-$start))"
if [ "$1" == "true" ]; then
echo -e "\\e[41mKO\\e[0m $title\\n"
else
echo -e "\\e[32mOK\\e[0m $title\\n\\ntravis_fold:end:$fold"
fi
}

echo -e "travis_fold:start:$fold"
echo -e "travis_time:start:$id"
echo -e "\\e[1;34m$title\\e[0m"

trap "travisfoldend true" EXIT
$*
trap - EXIT
travisfoldend
)

function githubfold () (
set -e -o pipefail
local name=$1
shift

echo "::group::$name"
$*
echo "::endgroup::"
)

function nullfold () (
set -e -o pipefail
shift
$*
)

function cifold () (
set -e -o pipefail
if [[ ! -z "${TRAVIS}" ]]; then
travisfold "$@"
elif [[ ! -z "${GITHUB_RUN_ID}" ]]; then
githubfold "$@"
else
nullfold "$@"
fi
)
12 changes: 0 additions & 12 deletions .ci/travis_env.sh

This file was deleted.

42 changes: 0 additions & 42 deletions .ci/travis_nix.sh

This file was deleted.

89 changes: 57 additions & 32 deletions .ci/travis_php.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

source .ci/vars.sh
source .ci/fold.sh

export COVERAGE=${COVERAGE:-true}
export LIBMUSTACHE_VERSION=${LIBMUSTACHE_VERSION:-master}
export TRAVIS_BUILD_DIR=${TRAVIS_BUILD_DIR:-`pwd`}
Expand All @@ -12,33 +15,34 @@ export REPORT_EXIT_STATUS=1
export TEST_PHP_EXECUTABLE=`which php`

function install_libmustache() (
set -e -o pipefail
set -o errexit -o pipefail -o xtrace

echo "Installing libmustache ${LIBMUSTACHE_VERSION}"

local dir=${INSTALL_PREFIX}/src/libmustache
rm -rf ${dir}
mkdir -p $(dirname ${dir})
git clone -b ${LIBMUSTACHE_VERSION} git://github.com/jbboehr/libmustache.git ${dir}
cd ${dir}
rm -rf libmustache
git clone git://github.com/jbboehr/libmustache.git
cd libmustache
git checkout ${LIBMUSTACHE_VERSION}
autoreconf -fiv
./configure --prefix=${INSTALL_PREFIX} --without-mustache-spec
make all install
)

function install_coveralls_lcov() (
set -o errexit -o pipefail -o xtrace

gem install coveralls-lcov
)

function before_install() (
set -e -o pipefail
set -o errexit -o pipefail

# Don't install this unless we're actually on travis
if [[ "${COVERAGE}" = "true" ]] && [[ "${TRAVIS}" = "true" ]]; then
gem install coveralls-lcov
cifold "install coveralls-lcov" install_coveralls_lcov
fi
)

function install() (
set -e -o pipefail

install_libmustache
function build_php_mustache() (
set -o errexit -o pipefail -o xtrace

phpize
if [[ "${COVERAGE}" = "true" ]]; then
Expand All @@ -53,42 +57,63 @@ function install() (
make clean all
)

function install() (
set -o errexit -o pipefail

cifold "install libmustache" install_libmustache
cifold "main build step" build_php_mustache
)

function initialize_coverage() (
set -o errexit -o pipefail -o xtrace

lcov --directory . --zerocounters
lcov --directory . --capture --compat-libtool --initial --output-file coverage.info
)

function before_script() (
set -e -o pipefail

if [[ "${COVERAGE}" = "true" ]]; then
echo "Initializing coverage"
lcov --directory . --zerocounters
lcov --directory . --capture --compat-libtool --initial --output-file coverage.info
cifold "initialize coverage" initialize_coverage
fi
)

function script() (
set -e -o pipefail
function test_php_mustache() (
set -o errexit -o pipefail -o xtrace

echo "Running main test suite"
${TEST_PHP_EXECUTABLE} run-tests.php -n -d extension=modules/mustache.so ./tests/*.phpt
)

function script() (
set -o errexit -o pipefail

cifold "main test suite" test_php_mustache
)

function upload_coverage() (
set -o errexit -o pipefail -o xtrace

lcov --no-checksum --directory . --capture --compat-libtool --output-file coverage.info
lcov --remove coverage.info "/usr*" \
--remove coverage.info "*/.phpenv/*" \
--remove coverage.info "/home/travis/build/include/*" \
--compat-libtool \
--output-file coverage.info

coveralls-lcov coverage.info
)

function after_success() (
set -e -o pipefail
set -o errexit -o pipefail

if [[ "${COVERAGE}" = "true" ]]; then
echo "Processing coverage"
lcov --no-checksum --directory . --capture --compat-libtool --output-file coverage.info
lcov --remove coverage.info "/usr*" \
--remove coverage.info "*/.phpenv/*" \
--remove coverage.info "/home/travis/build/include/*" \
--compat-libtool \
--output-file coverage.info

echo "Uploading coverage"
coveralls-lcov coverage.info
cifold "upload coverage" upload_coverage
fi
)

function after_failure() (
set -e -o pipefail
# set -o errexit -o pipefail

for i in `find tests -name "*.out" 2>/dev/null`; do
echo "-- START ${i}";
Expand Down
2 changes: 2 additions & 0 deletions .ci/vars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export PS4=' \e[33m$(date +"%H:%M:%S"): $BASH_SOURCE@$LINENO ${FUNCNAME[0]} -> \e[0m'
export LIBMUSTACHE_VERSION=1761e260bbd2247891aa49cb04318b40206b9a4b
60 changes: 60 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.git/
**/*~
**/*.a
**/acinclude.m4
**/aclocal.m4
**/autom4te.cache
**/build
**/cmake-build-debug
**/CMakeLists.txt
**/config.guess
**/config.h
**/config.h.in
**/config.log
**/config.nice
**/config.status
**/config.sub
**/configure
**/configure.ac
**/configure.in
**/coverage.info
**/.deps
**/.dirstamp
**/gmon*
**/.idea
**/install-sh
**/*.la
**/.libs
**/libtool
**/*.lo
**/*.log
**/ltmain.sh
**/ltmain.sh.backup
**/Makefile
**/Makefile.fragments
**/Makefile.global
**/Makefile.objects
**/missing
**/mkinstalldirs
**/modules
**/nbproject
**/*.o
**/*.out
**/.*project
**/run-tests.php
**/specs
**/test_coverage
**/test.php
**/tests/*.diff
**/tests/*.exp
**/tests/*.php
**/tests/*.sh
**/tmp-php.ini

# ci and docker
.github
.travis.*
**/*.nix
**/*Dockerfile
**/.dockerignore
**/result*/**
44 changes: 44 additions & 0 deletions .github/php-alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ARG PHP_VERSION=7.4
ARG PHP_TYPE=alpine
ARG BASE_IMAGE=php:${PHP_VERSION}-${PHP_TYPE}
ARG LIBMUSTACHE_VERSION=master

# image0
FROM ${BASE_IMAGE}
ARG LIBMUSTACHE_VERSION
WORKDIR /build

RUN apk update && \
apk --no-cache add alpine-sdk automake autoconf libtool json-c-dev yaml-dev

# libmustache
RUN git clone https://github.com/jbboehr/libmustache.git
WORKDIR /build/libmustache
RUN git checkout $LIBMUSTACHE_VERSION && git submodule update --init
RUN autoreconf -fiv
RUN ./configure \
--prefix /usr/local/ \
--enable-static \
--disable-shared \
CXXFLAGS="-O3 -fPIC -DPIC -flto" \
RANLIB=gcc-ranlib \
AR=gcc-ar \
NM=gcc-nm \
LD=gcc
RUN make
RUN make install

# php-mustache
WORKDIR /build/php-mustache
ADD . .
RUN phpize
RUN ./configure CXXFLAGS="-O3 -fPIC -DPIC"
RUN make
RUN make install

# image1
FROM ${BASE_IMAGE}
RUN apk --no-cache add json-c yaml libstdc++
COPY --from=0 /usr/local/lib/php/extensions /usr/local/lib/php/extensions
RUN docker-php-ext-enable mustache
ENTRYPOINT ["docker-php-entrypoint"]
Loading

0 comments on commit 2770f82

Please sign in to comment.