Skip to content

Commit

Permalink
gci: Fetch old GCI data from last deploy
Browse files Browse the repository at this point in the history
The cleansed data can be fetched from the production
website if the origin remote is set to be production
repository, as it is on pull requests for Travis CI.
This does not yet allow branch builds on forks,
as their origin will not be the production
repository.

Related to coala#3
  • Loading branch information
jayvdb committed Dec 17, 2017
1 parent 940cce5 commit 731aa97
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
8 changes: 6 additions & 2 deletions .ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ set -e -x

mkdir private _site public

python manage.py fetch_gci_task_data private
python manage.py cleanse_gci_task_data private _site
if [[ -n "$GCI_TOKEN" ]]; then
python manage.py fetch_gci_task_data private
python manage.py cleanse_gci_task_data private _site
else
python manage.py fetch_old_gci_task_data _site || true
fi

python manage.py collectstatic --noinput
python manage.py distill-local public --force
16 changes: 16 additions & 0 deletions community/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,19 @@ def get_owner():
"""
url = get_remote_url()
return url.owner


def get_deploy_url():
"""Obtain the http where deploys appear.
"""
# Use environment variable URL when Netlify detected
if os.environ.get('REPOSITORY_URL'):
return os.environ.get('URL')

url = get_remote_url()
if url.resource != 'github.com':
raise Exception('remotes %s is not supported' % url)

deploy_url = 'https://{url.owner}.github.io/{url.name}'.format(url=url)

return deploy_url
29 changes: 29 additions & 0 deletions gci/management/commands/fetch_old_gci_task_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import requests

from django.core.management.base import BaseCommand

from community.git import get_deploy_url


class Command(BaseCommand):
help = 'Fetch old GCI data'

def add_arguments(self, parser):
parser.add_argument('output_dir', nargs='?', type=str)

def handle(self, *args, **options):
output_dir = options.get('output_dir')

deploy_url = get_deploy_url()

r = requests.get(deploy_url + '/static/tasks.yaml')
r.raise_for_status()

with open(os.path.join(output_dir, 'tasks.yaml'), 'w') as f:
yaml.dump(r.content, f)

r = requests.get(deploy_url + '/static/instances.yaml')
r.raise_for_status()

with open(os.path.join(output_dir, 'instances.yaml'), 'w') as f:
yaml.dump(r.content, f)

0 comments on commit 731aa97

Please sign in to comment.