Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6e114c9
Test what the value of $TRAVIS_SECURE_ENV_VARS is on Travis on a fork
asmeurer Oct 18, 2018
688db82
Trigger build
asmeurer Oct 18, 2018
28ba6e4
Check if a repo is a fork on Travis
asmeurer Oct 18, 2018
82381b7
Remove test echo from .travis.yml
asmeurer Oct 18, 2018
e910c8f
Assume a repo is not a fork if the GitHub API doesn't have the fork key
asmeurer Oct 18, 2018
969243d
Don't run test_guess_github_repo() on fork builds
asmeurer Nov 27, 2018
77d0bac
Use pytest to skip test_guess_github_repo
asmeurer Nov 27, 2018
40fe8ee
Run py.test with verbose mode on Travis
asmeurer Nov 27, 2018
4f34324
Fix skipif order
asmeurer Nov 27, 2018
ab7713c
Show the skip reasons on Travis
asmeurer Nov 27, 2018
0cffa6a
Fix check if we are on a Travis fork build for test_guess_github_repo
asmeurer Nov 27, 2018
c929ffc
Make sure stash-test is a directory
asmeurer Nov 27, 2018
47b473e
Merge branch 'master' into forks
asmeurer Nov 27, 2018
d84ae9b
See if things are failing because the request failed
asmeurer Nov 27, 2018
4ddbe4a
Merge branch 'forks' of github.com:drdoctr/doctr into forks
asmeurer Nov 27, 2018
a552efb
isdir only returns True if the directory already exists
asmeurer Nov 27, 2018
5d8d2a2
Improve handling of syncing single files
asmeurer Nov 27, 2018
47395f2
Debug print
asmeurer Nov 27, 2018
61ba79a
Debug print
asmeurer Nov 27, 2018
a35d7e6
Debug: remove raise_for_status on fork check
asmeurer Nov 27, 2018
f1827ee
Print a warning message if the fork test failed because of rate limits
asmeurer Nov 27, 2018
1bdf65c
Fix the API check warning message
asmeurer Nov 27, 2018
9edb5cd
Print the warning to stderr
asmeurer Nov 27, 2018
2629f24
Debugging
asmeurer Nov 27, 2018
4eebca1
Better wording in the warning message
asmeurer Nov 27, 2018
d7292d9
Test syncing a file to a file on Travis
asmeurer Nov 27, 2018
8ec3ed8
Print the debug message to standard error
asmeurer Nov 27, 2018
282f92f
Fix handling of absolute vs. relative paths for single file sync in s…
asmeurer Nov 27, 2018
14e49f7
Remove debug print
asmeurer Nov 27, 2018
504580b
Correct test if dst is a directory
asmeurer Nov 27, 2018
a9fcc2e
Revert logic for syncing a file to a file
asmeurer Nov 27, 2018
fd41c09
Merge branch 'master' into forks
asmeurer Nov 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ script:
echo `date` >> test
python -m doctr deploy --key-path deploy_key.enc --no-require-master docs;
# Test syncing a tracked file with a change
python -m doctr deploy --sync --key-path deploy_key.enc stash-test --built-docs test;
python -m doctr deploy --sync --key-path deploy_key.enc stash-test/ --built-docs test;
# Test syncing a single file
echo `date` >> test-file
python -m doctr deploy --sync --key-path deploy_key.enc . --built-docs test-file;
# Test deploy branch creation. Delete the branch gh-pages-testing on drdoctr/doctr whenever you want to test this.
python -m doctr deploy --sync --key-path deploy_key.enc --no-require-master --deploy-branch gh-pages-testing docs;
# Test pushing to .github.io
Expand All @@ -64,7 +67,7 @@ script:
fi
- if [[ "${TESTS}" == "true" ]]; then
pyflakes doctr;
py.test doctr;
py.test doctr -v -rs;
fi

doctr:
Expand Down
7 changes: 4 additions & 3 deletions doctr/tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ def test_GIT_URL():

assert not GIT_URL.fullmatch('https://gitlab.com/drdoctr/doctr.git')

@pytest.mark.skipif(os.environ.get('TRAVIS_REPO_SLUG', '') != 'drdoctr/doctr', reason="Not run on Travis fork builds")
@pytest.mark.skipif(not on_travis(), reason="Not on Travis")
def test_guess_github_repo():
"""
Only works if run in this repo, and if cloned from origin. For safety,
only run on Travis
only run on Travis and not run on fork builds.
"""
if on_travis():
assert guess_github_repo() == 'drdoctr/doctr'
assert guess_github_repo() == 'drdoctr/doctr'
112 changes: 79 additions & 33 deletions doctr/tests/test_travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,53 +221,99 @@ def test_sync_from_log(src, dst):
os.chdir(old_curdir)


@pytest.mark.parametrize("dst", ['dst', 'dst/'])
def test_sync_from_log_file_to_dir(dst):
with tempfile.TemporaryDirectory() as dir:
try:
old_curdir = os.path.abspath(os.curdir)
os.chdir(dir)

src = 'file'

with open(src, 'w') as f:
f.write('test1')

# Test that the sync happens
added, removed = sync_from_log(src, dst, 'logfile')

assert added == [
os.path.join('dst', 'file'),
'logfile',
]

assert removed == []

assert os.path.isdir(dst)
# Make sure dst is a file
with open(os.path.join('dst', 'file')) as f:
assert f.read() == 'test1'


with open('logfile') as f:
assert f.read() == '\n'.join([
os.path.join('dst', 'file')
])

finally:
os.chdir(old_curdir)


@pytest.mark.parametrize("""branch_whitelist, TRAVIS_BRANCH,
TRAVIS_PULL_REQUEST, TRAVIS_TAG, build_tags,
TRAVIS_PULL_REQUEST, TRAVIS_TAG, fork, build_tags,
canpush""",
[

('master', 'doctr', 'true', "", False, False),
('master', 'doctr', 'false', "", False, False),
('master', 'master', 'true', "", False, False),
('master', 'master', 'false', "", False, True),
('doctr', 'doctr', 'True', "", False, False),
('doctr', 'doctr', 'false', "", False, True),
('set()', 'doctr', 'false', "", False, False),

('master', 'doctr', 'true', "tagname", False, False),
('master', 'doctr', 'false', "tagname", False, False),
('master', 'master', 'true', "tagname", False, False),
('master', 'master', 'false', "tagname", False, False),
('doctr', 'doctr', 'True', "tagname", False, False),
('doctr', 'doctr', 'false', "tagname", False, False),
('set()', 'doctr', 'false', "tagname", False, False),

('master', 'doctr', 'true', "", True, False),
('master', 'doctr', 'false', "", True, False),
('master', 'master', 'true', "", True, False),
('master', 'master', 'false', "", True, True),
('doctr', 'doctr', 'True', "", True, False),
('doctr', 'doctr', 'false', "", True, True),
('set()', 'doctr', 'false', "", True, False),

('master', 'doctr', 'true', "tagname", True, True),
('master', 'doctr', 'false', "tagname", True, True),
('master', 'master', 'true', "tagname", True, True),
('master', 'master', 'false', "tagname", True, True),
('doctr', 'doctr', 'True', "tagname", True, True),
('doctr', 'doctr', 'false', "tagname", True, True),
('set()', 'doctr', 'false', "tagname", True, True),
('master', 'doctr', 'true', "", False, False, False),
('master', 'doctr', 'false', "", False, False, False),
('master', 'master', 'true', "", False, False, False),
('master', 'master', 'false', "", False, False, True),
('doctr', 'doctr', 'True', "", False, False, False),
('doctr', 'doctr', 'false', "", False, False, True),
('set()', 'doctr', 'false', "", False, False, False),

('master', 'doctr', 'true', "tagname", False, False, False),
('master', 'doctr', 'false', "tagname", False, False, False),
('master', 'master', 'true', "tagname", False, False, False),
('master', 'master', 'false', "tagname", False, False, False),
('doctr', 'doctr', 'True', "tagname", False, False, False),
('doctr', 'doctr', 'false', "tagname", False, False, False),
('set()', 'doctr', 'false', "tagname", False, False, False),

('master', 'doctr', 'true', "", False, True, False),
('master', 'doctr', 'false', "", False, True, False),
('master', 'master', 'true', "", False, True, False),
('master', 'master', 'false', "", False, True, True),
('doctr', 'doctr', 'True', "", False, True, False),
('doctr', 'doctr', 'false', "", False, True, True),
('set()', 'doctr', 'false', "", False, True, False),

('master', 'doctr', 'true', "tagname", False, True, True),
('master', 'doctr', 'false', "tagname", False, True, True),
('master', 'master', 'true', "tagname", False, True, True),
('master', 'master', 'false', "tagname", False, True, True),
('doctr', 'doctr', 'True', "tagname", False, True, True),
('doctr', 'doctr', 'false', "tagname", False, True, True),
('set()', 'doctr', 'false', "tagname", False, True, True),

('master', 'doctr', 'true', "", True, False, False),
('master', 'doctr', 'false', "", True, False, False),
('master', 'master', 'true', "", True, False, False),
('master', 'master', 'false', "", True, False, False),
('doctr', 'doctr', 'True', "", True, False, False),
('doctr', 'doctr', 'false', "", True, False, False),
('set()', 'doctr', 'false', "", True, False, False),

])
def test_determine_push_rights(branch_whitelist, TRAVIS_BRANCH,
TRAVIS_PULL_REQUEST, TRAVIS_TAG, build_tags, canpush, monkeypatch):
TRAVIS_PULL_REQUEST, TRAVIS_TAG, build_tags, fork, canpush, monkeypatch):
branch_whitelist = {branch_whitelist}

assert determine_push_rights(
branch_whitelist=branch_whitelist,
TRAVIS_BRANCH=TRAVIS_BRANCH,
TRAVIS_PULL_REQUEST=TRAVIS_PULL_REQUEST,
TRAVIS_TAG=TRAVIS_TAG,
fork=fork,
build_tags=build_tags) == canpush

@pytest.mark.parametrize("src", ["src", "."])
Expand Down
26 changes: 23 additions & 3 deletions doctr/travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import tempfile
import time

import requests

from cryptography.fernet import Fernet

from .common import red, blue
Expand Down Expand Up @@ -214,10 +216,21 @@ def setup_GitHub_push(deploy_repo, *, auth_type='deploy_key',
TRAVIS_BRANCH = os.environ.get("TRAVIS_BRANCH", "")
TRAVIS_PULL_REQUEST = os.environ.get("TRAVIS_PULL_REQUEST", "")

# Check if the repo is a fork
TRAVIS_REPO_SLUG = os.environ["TRAVIS_REPO_SLUG"]
REPO_URL = 'https://api.github.com/repos/{slug}'
r = requests.get(REPO_URL.format(slug=TRAVIS_REPO_SLUG))
fork = r.json().get('fork', False)
# Rate limits prevent this check from working every time. By default, we
# assume it isn't a fork so that things just work on non-fork builds.
if r.status_code == 403:
print(red("Warning: GitHub's API rate limits prevented doctr from detecting if this build is a fork. If it is, doctr will fail with an error like 'DOCTR_DEPLOY_ENCRYPTION_KEY environment variable is not set'. This error can be safely ignored. If this is not a fork build, you can ignore this warning."), file=sys.stderr)

canpush = determine_push_rights(
branch_whitelist=branch_whitelist,
TRAVIS_BRANCH=TRAVIS_BRANCH,
TRAVIS_PULL_REQUEST=TRAVIS_PULL_REQUEST,
fork=fork,
TRAVIS_TAG=TRAVIS_TAG,
build_tags=build_tags)

Expand Down Expand Up @@ -434,14 +447,17 @@ def sync_from_log(src, dst, log_file, exclude=()):
files = glob.iglob(join(src, '**'), recursive=True)
else:
files = [src]
src = os.path.dirname(src) + os.sep
src = os.path.dirname(src) + os.sep if os.sep in src else ''

os.makedirs(dst, exist_ok=True)

# sorted makes this easier to test
for f in sorted(files):
if any(is_subdir(f, os.path.join(src, i)) for i in exclude):
continue
new_f = join(dst, f[len(src):])
if isdir(f):

if isdir(f) or f.endswith(os.sep):
os.makedirs(new_f, exist_ok=True)
else:
shutil.copy2(f, new_f)
Expand Down Expand Up @@ -549,7 +565,7 @@ def last_commit_by_doctr():
return False

def determine_push_rights(*, branch_whitelist, TRAVIS_BRANCH,
TRAVIS_PULL_REQUEST, TRAVIS_TAG, build_tags):
TRAVIS_PULL_REQUEST, TRAVIS_TAG, build_tags, fork):
"""Check if Travis is running on ``master`` (or a whitelisted branch) to
determine if we can/should push the docs to the deploy repo
"""
Expand All @@ -570,6 +586,10 @@ def determine_push_rights(*, branch_whitelist, TRAVIS_BRANCH,
print("The website and docs are not pushed to gh-pages on pull requests", file=sys.stderr)
canpush = False

if fork:
print("The website and docs are not pushed to gh-pages on fork builds.", file=sys.stderr)
canpush = False

if last_commit_by_doctr():
print(red("The last commit on this branch was pushed by doctr. Not pushing to "
"avoid an infinite build-loop."), file=sys.stderr)
Expand Down