Skip to content

Commit 79f790a

Browse files
committed
Add steps to run gbq integration testing to the contributing docs
1 parent 8023029 commit 79f790a

File tree

6 files changed

+95
-9
lines changed

6 files changed

+95
-9
lines changed

.travis.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,8 @@ matrix:
229229
- USE_CACHE=true
230230

231231
before_install:
232-
# gbq secure key
233-
- if [ -n "$encrypted_1d9d7b1f171b_iv" ]; then
234-
openssl aes-256-cbc -K $encrypted_1d9d7b1f171b_key
235-
-iv $encrypted_1d9d7b1f171b_iv -in ci/travis_gbq.json.enc
236-
-out ci/travis_gbq.json -d;
237-
export VALID_GBQ_CREDENTIALS=True;
238-
fi
239232
- echo "before_install"
233+
- source ci/travis_process_gbq_encryption.sh
240234
- echo $VIRTUAL_ENV
241235
- export PATH="$HOME/miniconda/bin:$PATH"
242236
- df -h

ci/travis_encrypt_gbq.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
GBQ_JSON_FILE=$1
4+
GBQ_PROJECT_ID=$2
5+
6+
if [[ $# -ne 2 ]]; then
7+
echo -e "Too few arguments.\nUsage: ./travis_encrypt_gbq.sh "\
8+
"<gbq-json-credentials-file> <gbq-project-id>"
9+
exit 1
10+
fi
11+
12+
if [[ $GBQ_JSON_FILE != *.json ]]; then
13+
echo "ERROR: Expected *.json file"
14+
exit 1
15+
fi
16+
17+
if [[ ! -f $GBQ_JSON_FILE ]]; then
18+
echo "ERROR: File $GBQ_JSON_FILE does not exist"
19+
exit 1
20+
fi
21+
22+
echo "Encrypting $GBQ_JSON_FILE..."
23+
read -d "\n" TRAVIS_KEY TRAVIS_IV <<<$(travis encrypt-file $GBQ_JSON_FILE \
24+
travis_gbq.json.enc -f | grep -o "\w*_iv\|\w*_key");
25+
26+
echo "Adding your secure key and project id to travis_gbq_config.txt ..."
27+
echo -e "TRAVIS_IV_ENV=$TRAVIS_IV\nTRAVIS_KEY_ENV=$TRAVIS_KEY\n"\
28+
"GBQ_PROJECT_ID='$GBQ_PROJECT_ID'" > travis_gbq_config.txt
29+
30+
echo "Done. Removing file $GBQ_JSON_FILE"
31+
rm $GBQ_JSON_FILE
32+
33+
echo -e "Created encrypted credentials file travis_gbq.json.enc.\n"\
34+
"NOTE: Do NOT commit the *.json file containing your unencrypted" \
35+
"private key"

ci/travis_gbq_config.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TRAVIS_IV_ENV=encrypted_1d9d7b1f171b_iv
2+
TRAVIS_KEY_ENV=encrypted_1d9d7b1f171b_key
3+
GBQ_PROJECT_ID='pandas-travis'

ci/travis_process_gbq_encryption.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
source ci/travis_gbq_config.txt
4+
5+
if [[ -n ${!TRAVIS_IV_ENV} ]]; then
6+
openssl aes-256-cbc -K ${!TRAVIS_KEY_ENV} -iv ${!TRAVIS_IV_ENV} \
7+
-in ci/travis_gbq.json.enc -out ci/travis_gbq.json -d;
8+
export GBQ_PROJECT_ID=$GBQ_PROJECT_ID;
9+
echo 'Successfully decrypted gbq credentials'
10+
fi
11+

doc/source/contributing.rst

+43
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,44 @@ This will display stderr from the benchmarks, and use your local
626626
Information on how to write a benchmark and how to use asv can be found in the
627627
`asv documentation <http://asv.readthedocs.org/en/latest/writing_benchmarks.html>`_.
628628

629+
.. _contributing.gbq_integration_tests:
630+
631+
Running Google BigQuery Integration Tests
632+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
633+
634+
You will need to create a Google BigQuery private key in JSON format in
635+
order to run Google BigQuery integration tests on your local machine and
636+
on Travis-CI. The first step is to create a `service account
637+
<https://console.developers.google.com/iam-admin/serviceaccounts/>`__.
638+
639+
Integration tests for ``pandas.io.gbq`` are skipped in pull requests because
640+
the credentials that are required for running Google BigQuery integration
641+
tests are `encrypted <https://docs.travis-ci.com/user/encrypting-files/>`__
642+
on Travis-CI and are only accessible from the pydata/pandas repository. The
643+
credentials won't be available on forks of pandas. Here are the steps to run
644+
gbq integration tests on a forked repository:
645+
646+
#. First, complete all the steps in the `Encrypting Files Prerequisites
647+
<https://docs.travis-ci.com/user/encrypting-files/>`__ section.
648+
#. Sign into `Travis <https://travis-ci.org/>`__ using your GitHub account.
649+
#. Enable your forked repository of pandas for testing in `Travis
650+
<https://travis-ci.org/profile/>`__.
651+
#. Run the following command from terminal where the current working directory
652+
is the ``ci`` folder::
653+
654+
./travis_encrypt_gbq.sh <gbq-json-credentials-file> <gbq-project-id>
655+
656+
#. Create a new branch from the branch used in your pull request. Commit the
657+
encrypted file called ``travis_gbq.json.enc`` as well as the file
658+
``travis_gbq_config.txt``, in an otherwise empty commit. DO NOT commit the
659+
``*.json`` file which contains your unencrypted private key.
660+
#. Your branch should be tested automatically once it is pushed. You can check
661+
the status by visiting your Travis branches page which exists at the
662+
following location: https://travis-ci.org/your-user-name/pandas/branches .
663+
Click on a build job for your branch. Expand the following line in the
664+
build log: ``ci/print_skipped.py /tmp/nosetests.xml`` . Search for the
665+
term ``test_gbq`` and confirm that gbq integration tests are not skipped.
666+
629667
Running the vbench performance test suite (phasing out)
630668
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
631669

@@ -814,6 +852,11 @@ updated. Pushing them to GitHub again is done by::
814852
This will automatically update your pull request with the latest code and restart the
815853
Travis-CI tests.
816854

855+
If your pull request is related to the ``pandas.io.gbq`` module, please see
856+
the section on :ref:`Running Google BigQuery Integration Tests
857+
<contributing.gbq_integration_tests>` to configure a Google BigQuery service
858+
account for your pull request on Travis-CI.
859+
817860
Delete your merged branch (optional)
818861
------------------------------------
819862

pandas/io/tests/test_gbq.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ def _skip_if_no_private_key_contents():
6060

6161
def _in_travis_environment():
6262
return 'TRAVIS_BUILD_DIR' in os.environ and \
63-
'VALID_GBQ_CREDENTIALS' in os.environ
63+
'GBQ_PROJECT_ID' in os.environ
6464

6565

6666
def _get_project_id():
6767
if _in_travis_environment():
68-
return 'pandas-travis'
68+
return os.environ.get('GBQ_PROJECT_ID')
6969
else:
7070
return PROJECT_ID
7171

0 commit comments

Comments
 (0)