Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit d29bc59

Browse files
authored
Add circle ci config for running tests across PHP versions (#2)
* Add circle ci config for running tests across PHP versions * Fix test namespaces * Add PHP code sniffer to tests * Fix Dockerfile for running php tests * Fix directory for testing the extension
1 parent 7adc32c commit d29bc59

21 files changed

Lines changed: 225 additions & 14 deletions

Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2017 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
ARG BASE_IMAGE
16+
FROM $BASE_IMAGE
17+
18+
RUN mkdir -p /build && \
19+
apt-get update -y && \
20+
apt-get install -y -q --no-install-recommends \
21+
build-essential \
22+
g++ \
23+
gcc \
24+
libc-dev \
25+
make \
26+
autoconf
27+
28+
COPY . /build/
29+
30+
WORKDIR /build/ext
31+
32+
ENV TEST_PHP_ARGS="-q" \
33+
REPORT_EXIT_STATUS=1
34+
35+
RUN phpize && \
36+
./configure --enable-stackdriver-trace && \
37+
make clean && \
38+
make && \
39+
make test && \
40+
make install
41+
42+
WORKDIR /build
43+
44+
RUN composer install && \
45+
vendor/bin/phpcs --standard=./phpcs-ruleset.xml && \
46+
vendor/bin/phpunit

circle.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
machine:
2+
timezone: America/Los_Angeles
3+
environment:
4+
GCLOUD_DIR: ${HOME}/gcloud
5+
PATH: ${GCLOUD_DIR}/google-cloud-sdk/bin:${PATH}
6+
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
7+
CLOUDSDK_ACTIVE_CONFIG_NAME: opencensus-php
8+
TEST_BUILD_DIR: ${HOME}
9+
PHP_DOCKER_GOOGLE_CREDENTIALS: ${HOME}/credentials.json
10+
GOOGLE_PROJECT_ID: php-stackdriver
11+
TAG: circle-${CIRCLE_BUILD_NUM}
12+
13+
dependencies:
14+
override:
15+
- scripts/install_test_dependencies.sh
16+
17+
test:
18+
override:
19+
- scripts/run_test_suite.sh

cloudbuild.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This cloudbuild.yaml is used to test the php extension against multiple versions of php
2+
steps:
3+
- name: gcr.io/cloud-builders/docker
4+
args: ['build', '--build-arg', 'BASE_IMAGE=gcr.io/google-appengine/php71', '.']
5+
waitFor: ['-']
6+
id: php71
7+
- name: gcr.io/cloud-builders/docker
8+
args: ['build', '--build-arg', 'BASE_IMAGE=gcr.io/google-appengine/php70', '.']
9+
waitFor: ['-']
10+
id: php70
11+
- name: gcr.io/cloud-builders/docker
12+
args: ['build', '--build-arg', 'BASE_IMAGE=gcr.io/php-mvm-a/php72:alpha3', '.']
13+
waitFor: ['-']
14+
id: php72

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"cache/adapter-common": "^1.0"
1212
},
1313
"require-dev": {
14-
"phpunit/phpunit": "4.8.*"
14+
"phpunit/phpunit": "4.8.*",
15+
"squizlabs/php_codesniffer": "2.*"
1516
},
1617
"suggest": {
1718
"cache/apcu-adapter": "Enable QpsSampler to use apcu cache.",

phpcs-ruleset.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Google-Cloud-PHP-PSR2">
3+
<rule ref="PSR2" />
4+
<file>src</file>
5+
</ruleset>

scripts/dump_credentials.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright 2015 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* Dumps the contents of the environment variable GOOGLE_CREDENTIALS_BASE64 to
20+
* a file.
21+
*
22+
* To setup Travis to run on your fork, read TRAVIS.md.
23+
*/
24+
if (getenv('GOOGLE_CREDENTIALS_BASE64') === false) {
25+
exit(0);
26+
}
27+
file_put_contents(
28+
getenv('PHP_DOCKER_GOOGLE_CREDENTIALS'),
29+
base64_decode(getenv('GOOGLE_CREDENTIALS_BASE64'))
30+
);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2017 Google Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# A script for installing necessary software on CI systems.
17+
18+
set -ex
19+
20+
if [ "${INSTALL_GCLOUD}" == "true" ]; then
21+
# Install gcloud
22+
if [ ! -d ${HOME}/gcloud/google-cloud-sdk ]; then
23+
mkdir -p ${HOME}/gcloud &&
24+
wget https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz --directory-prefix=${HOME}/gcloud &&
25+
cd "${HOME}/gcloud" &&
26+
tar xzf google-cloud-sdk.tar.gz &&
27+
./google-cloud-sdk/install.sh --usage-reporting false --path-update false --command-completion false &&
28+
cd "${TEST_BUILD_DIR}";
29+
fi
30+
fi
31+
32+
if [ -z "${CLOUDSDK_ACTIVE_CONFIG_NAME}" ]; then
33+
echo "You need to set CLOUDSDK_ACTIVE_CONFIG_NAME envvar."
34+
exit 1
35+
fi
36+
37+
if [ -z "${GOOGLE_PROJECT_ID}" ]; then
38+
echo "You need to set GOOGLE_PROJECT_ID envvar."
39+
exit 1
40+
fi
41+
42+
if [ -z "${CLOUDSDK_VERBOSITY}" ]; then
43+
CLOUDSDK_VERBOSITY='none'
44+
fi
45+
46+
# gcloud configurations
47+
gcloud config configurations create ${CLOUDSDK_ACTIVE_CONFIG_NAME} || /bin/true # ignore failure
48+
gcloud config set project ${GOOGLE_PROJECT_ID}
49+
gcloud config set app/promote_by_default false
50+
gcloud config set verbosity ${CLOUDSDK_VERBOSITY}
51+
52+
# Dump the credentials from the environment variable.
53+
php scripts/dump_credentials.php
54+
55+
# Set the timeout
56+
gcloud config set container/build_timeout 3600
57+
58+
if [ ! -f "${PHP_DOCKER_GOOGLE_CREDENTIALS}" ]; then
59+
echo 'Please set PHP_DOCKER_GOOGLE_CREDENTIALS envvar.'
60+
exit 1
61+
fi
62+
63+
# Use the service account for gcloud operations.
64+
gcloud auth activate-service-account \
65+
--key-file "${PHP_DOCKER_GOOGLE_CREDENTIALS}"
66+
67+
if [ "${CIRCLECI}" == "true" ]; then
68+
# Need sudo on circleci:
69+
# https://discuss.circleci.com/t/gcloud-components-update-version-restriction/3725
70+
# They also overrides the PATH to use
71+
# /opt/google-cloud-sdk/bin/gcloud so we can not easily use our
72+
# own gcloud
73+
sudo /opt/google-cloud-sdk/bin/gcloud -q components update beta
74+
else
75+
gcloud -q components update beta
76+
fi

scripts/run_test_suite.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2017 Google Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# A script for installing necessary software on CI systems.
17+
18+
set -ex
19+
20+
gcloud container builds submit --config=cloudbuild.yaml .

tests/unit/Trace/Reporter/EchoReporterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
namespace Google\Cloud\Tests\Unit\Trace\Reporter;
18+
namespace OpenCensus\Tests\Unit\Trace\Reporter;
1919

2020
use OpenCensus\Trace\Reporter\EchoReporter;
2121
use OpenCensus\Trace\TraceContext;

tests/unit/Trace/Reporter/FileReporterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
namespace Google\Cloud\Tests\Unit\Trace\Reporter;
18+
namespace OpenCensus\Tests\Unit\Trace\Reporter;
1919

2020
use OpenCensus\Trace\Reporter\FileReporter;
2121
use OpenCensus\Trace\TraceContext;

0 commit comments

Comments
 (0)