Skip to content

Commit 412ceac

Browse files
authored
Adds REST-specific kokoro job (GoogleCloudPlatform#925)
1 parent 33654dc commit 412ceac

File tree

7 files changed

+60
-24
lines changed

7 files changed

+60
-24
lines changed

.kokoro/docker/php73/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ RUN apt-get update && \
3333
zlib1g-dev
3434

3535
RUN ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a && \
36-
mkdir ${PHP_DIR} ${PHP_SRC_DIR} && \
36+
mkdir -p ${PHP_DIR} ${PHP_SRC_DIR} ${PHP_DIR}/lib/conf.d && \
3737
cd ${PHP_SRC_DIR} && \
3838
wget http://us1.php.net/get/php-7.3.0.tar.bz2/from/this/mirror \
3939
-O php-7.3.0.tar.bz2 && \
4040
tar jxf php-7.3.0.tar.bz2 && \
4141
cd php-7.3.0 && \
4242
./configure \
4343
--prefix=${PHP_DIR} \
44+
--with-config-file-scan-dir=${PHP_DIR}/lib/conf.d \
4445
--with-pdo-pgsql \
4546
--with-zlib-dir \
4647
--with-freetype-dir \
@@ -92,7 +93,7 @@ RUN ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a && \
9293
pecl install grpc && \
9394
cp php.ini-production ${PHP_DIR}/lib/php.ini && \
9495
echo 'zend_extension=opcache.so' >> ${PHP_DIR}/lib/php.ini && \
95-
echo 'extension=grpc.so' >> ${PHP_DIR}/lib/php.ini && \
96+
echo 'extension=grpc.so' >> ${PHP_DIR}/lib/conf.d/ext-grpc.ini && \
9697
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
9798
php -r "if (hash_file('SHA384', 'composer-setup.php') === rtrim(file_get_contents('https://composer.github.io/installer.sig'))) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
9899
php composer-setup.php --filename=composer --install-dir=/usr/local/bin

.kokoro/php_rest.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/php73"
7+
}
8+
9+
# Set this project to run REST tests only
10+
env_vars: {
11+
key: "RUN_REST_TESTS_ONLY"
12+
value: "true"
13+
}

.kokoro/system_tests.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ fi
2424
cd github/php-docs-samples
2525

2626
export GOOGLE_APPLICATION_CREDENTIALS=$KOKORO_GFILE_DIR/service-account.json
27-
export GOOGLE_ALT_APPLICATION_CREDENTIALS=$KOKORO_GFILE_DIR/$GOOGLE_ALT_CREDENTIALS_FILENAME
27+
if [ -n "$GOOGLE_ALT_CREDENTIALS_FILENAME" ]; then
28+
export GOOGLE_ALT_APPLICATION_CREDENTIALS=$KOKORO_GFILE_DIR/$GOOGLE_ALT_CREDENTIALS_FILENAME
29+
fi
2830

2931
export PATH="$PATH:/opt/composer/vendor/bin:/root/google-cloud-sdk/bin"
3032

@@ -46,7 +48,7 @@ source .kokoro/secrets.sh
4648

4749
mkdir -p build/logs
4850

49-
export IS_PULL_REQUEST=$KOKORO_GITHUB_PULL_REQUEST_COMMIT
51+
export PULL_REQUEST_NUMBER=$KOKORO_GITHUB_PULL_REQUEST_NUMBER
5052

5153
# Run code standards check when appropriate
5254
if [ "${RUN_CS_CHECK}" = "true" ]; then
@@ -55,6 +57,12 @@ if [ "${RUN_CS_CHECK}" = "true" ]; then
5557
bash testing/run_cs_check.sh
5658
fi
5759

60+
# If we are running REST tests, disable gRPC
61+
if [ "${RUN_REST_TESTS_ONLY}" = "true" ]; then
62+
GRPC_INI=$(php -i | grep grpc.ini | sed 's/^Additional .ini files parsed => //g' | sed 's/,*$//g' )
63+
mv $GRPC_INI "${GRPC_INI}.disabled"
64+
fi
65+
5866
# Install global test dependencies
5967
bash testing/composer.sh
6068

bigtable/test/bigtableTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ public function testDeleteTable()
371371

372372
public function testWritingRows()
373373
{
374+
$this->requireGrpc();
375+
374376
$tableId = uniqid(self::TABLE_ID_PREFIX);
375377
$tableName = self::$tableAdminClient->tableName(self::$projectId, self::$instanceId, $tableId);
376378

@@ -400,6 +402,8 @@ public function testWritingRows()
400402

401403
public function testGettingARow()
402404
{
405+
$this->requireGrpc();
406+
403407
$tableId = uniqid(self::TABLE_ID_PREFIX);
404408
$tableName = self::$tableAdminClient->tableName(self::$projectId, self::$instanceId, $tableId);
405409

@@ -426,6 +430,8 @@ public function testGettingARow()
426430

427431
public function testScanningAllRows()
428432
{
433+
$this->requireGrpc();
434+
429435
$tableId = uniqid(self::TABLE_ID_PREFIX);
430436
$tableName = self::$tableAdminClient->tableName(self::$projectId, self::$instanceId, $tableId);
431437

bigtable/test/writeTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public function testWriteIncrement()
110110

111111
public function testWriteBatch()
112112
{
113+
$this->requireGrpc();
114+
113115
$output = $this->runSnippet('writes/write_batch', [
114116
self::$projectId,
115117
self::$instanceId,

testing/RUN_ALL_TESTS

Lines changed: 0 additions & 3 deletions
This file was deleted.

testing/run_test_suite.sh

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ FLAKES=(
2828

2929
# tests to run with grpc.so disabled
3030
REST_TESTS=(
31+
asset
3132
bigquerydatatransfer
32-
error_reporting
33+
bigtable
3334
dialogflow
3435
dlp
36+
error_reporting
37+
iot
3538
monitoring
3639
video
40+
vision
3741
)
3842

3943
# These tests run in a different project, determined by GOOGLE_ALT_PROJECT_ID
@@ -58,8 +62,6 @@ ALT_PROJECT_TESTS=(
5862
vision
5963
)
6064

61-
GRPC_INI=$(php -i | grep grpc.ini | sed 's/,*$//g')
62-
6365
TMP_REPORT_DIR=$(mktemp -d)
6466

6567
SUCCEEDED_FILE=${TMP_REPORT_DIR}/succeeded
@@ -72,11 +74,17 @@ FILES_CHANGED=$(git diff --name-only HEAD $(git merge-base HEAD master))
7274

7375
# If the file RUN_ALL_TESTS is modified, or if we were not triggered from a Pull
7476
# Request, run the whole test suite.
75-
if grep -q ^testing\/RUN_ALL_TESTS$ <<< "$FILES_CHANGED" || \
76-
[ -z "$IS_PULL_REQUEST" ]; then
77+
if [ -z "$PULL_REQUEST_NUMBER" ]; then
7778
RUN_ALL_TESTS=1
7879
else
79-
RUN_ALL_TESTS=0
80+
# Check to see if the repo includes the "kokoro:run-all" label
81+
if curl "https://api.github.com/repos/GoogleCloudPlatform/php-docs-samples/issues/$PULL_REQUEST_NUMBER/labels" \
82+
| grep -q "kokoro:run-all"; then
83+
RUN_ALL_TESTS=1
84+
else
85+
RUN_ALL_TESTS=0
86+
fi
87+
8088
fi
8189

8290
if [ "${TEST_DIRECTORIES}" = "" ]; then
@@ -118,10 +126,19 @@ do
118126
# Only run tests for samples that have changed.
119127
if [ "$RUN_ALL_TESTS" -ne "1" ]; then
120128
if ! grep -q ^$DIR <<< "$FILES_CHANGED" ; then
121-
echo "Skipping tests in $DIR"
129+
echo "Skipping tests in $DIR (unchanged)"
122130
continue
123131
fi
124132
fi
133+
if [ "${RUN_REST_TESTS_ONLY}" = "true" ] && [[ ! "${REST_TESTS[@]}" =~ "${DIR}" ]]; then
134+
echo "Skipping tests in $DIR (no REST tests)"
135+
continue
136+
fi
137+
if [ "$RUN_DEPLOYMENT_TESTS" != "true" ] &&
138+
[[ -z $(find $DIR/test/ -type f -name *Test.php -not -name Deploy*Test.php) ]]; then
139+
echo "Skipping tests in $DIR (Deployment tests only)"
140+
continue
141+
fi
125142
pushd ${DIR}
126143
mkdir -p build/logs
127144
# Temporarily allowing error
@@ -133,23 +150,15 @@ do
133150
if [ $? != 0 ]; then
134151
# If the PHP required version is too low, skip the test
135152
if composer check-platform-reqs | grep "__root__ requires php" | grep failed ; then
136-
echo "Skipping tests in $DIR"
153+
echo "Skipping tests in $DIR (incompatible PHP version)"
137154
else
138155
# Run composer without "-q"
139156
composer install
140157
echo "${DIR}: failed" >> "${FAILED_FILE}"
141158
fi
142159
else
143160
echo "running phpunit in ${DIR}"
144-
if [[ "${REST_TESTS[@]}" =~ "${DIR}" ]]; then
145-
run_tests "${DIR} (grpc)"
146-
# disable gRPC to test using REST only, then re-enable it
147-
mv $GRPC_INI "${GRPC_INI}.disabled"
148-
run_tests "${DIR} (rest)"
149-
mv "${GRPC_INI}.disabled" $GRPC_INI
150-
else
151-
run_tests $DIR
152-
fi
161+
run_tests $DIR
153162
set -e
154163
if [ "$RUN_ALL_TESTS" -eq "1" ] && [ -f build/logs/clover.xml ]; then
155164
cp build/logs/clover.xml \

0 commit comments

Comments
 (0)