Skip to content

Commit

Permalink
added CI package builds (#823)
Browse files Browse the repository at this point in the history
* added travis package builds

* changed travis

* fixed travis

* fixed travis

* updated travis

* removed ci

* update travis

* ut

* updated travis

* updated travis

* removed pip caching

* removed coverage

* flipped dependencies

* ut

* updated essentials

* add back 3.4 test

* updated circle

* commit

* added init

* fixed

* flake8

* 36

* more python

* added masonite validation

* fixed build jobs

* trigger ci build

* trigger builds

* fixed trigger

* added build parameter

* fix for build parameters

* updated for Masonite API

* updated for code coverage

* fixed dependency for code coverage

* fixed for code coverage

* fixed coverage

* updated trigger build

* changed build url
  • Loading branch information
josephmancuso committed Jul 7, 2019
1 parent 5a83bb1 commit 34459d4
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 25 deletions.
68 changes: 68 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
version: 2
jobs:
build:
docker:
- image: circleci/python:3.6 # primary container for the build job
steps:
- checkout
- run: make
- run: make ci
python3.4:
docker:
- image: circleci/python:3.4
steps:
- checkout
- run: make
- run: make ci
python3.5:
docker:
- image: circleci/python:3.5
steps:
- checkout
- run: make
- run: make ci
python3.7:
docker:
- image: circleci/python:3.7
steps:
- checkout
- run: make
- run: make ci
Masonite Validation:
docker:
- image: circleci/python:3.6
steps:
- checkout
- run: python trigger_build.py --repo masoniteframework/validation --branch circle-ci --build MASONITE_DEPENDENT_BRANCH=$CIRCLE_BRANCH
Masonite API:
docker:
- image: circleci/python:3.6
steps:
- checkout
- run: python trigger_build.py --repo masoniteframework/api --branch 2.2 --build MASONITE_DEPENDENT_BRANCH=$CIRCLE_BRANCH
Code Coverage:
docker:
- image: circleci/python:3.6
steps:
- checkout
- run: pip install -r requirements.txt --user
- run: make coverage
- run: make deepsource

workflows:
version: 2
build_and_test:
jobs:
- build
- python3.4
- python3.5
- python3.7
- Masonite Validation:
requires:
- build
- Masonite API:
requires:
- build
- Code Coverage:
requires:
- build
47 changes: 27 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
language: python

install: "make"

cache: pip
jobs:
include:
- stage: test
script:
- make ci
python: '3.4'
- stage: test
script:
- make ci
python: '3.5'
- stage: test
script:
- make ci
# - stage: test
# script:
# - make ci
# python: '3.5'
# - stage: test
# script:
# - make ci
# python: '3.6'
# - stage: test
# script:
# - make ci
# python: '3.7'
# dist: xenial
# - stage: coverage
# python: '3.6'
# script:
# - make coverage
# - coveralls && make deepsource
- stage: Packages
name: "Masonite Validation"
python: '3.6'
- stage: test
script:
- make ci
python: '3.7'
dist: xenial
- stage: coverage
- git clone https://github.com/masoniteframework/validation
- cd validation && pip install -r requirements.txt && pip install -e . && python -m pytest
- stage: Packages
python: '3.6'
script:
- make coverage
- coveralls && make deepsource
name: "Masonite Essentials"
script:
- git clone https://github.com/masoniteframework/essentials
- cd essentials && pip install -e . && pip install -r requirements.txt && pip install hashids && python -m pytest

script:
- make ci

deploy:
provider: pypi
Expand Down
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
init:
pip install masonite_cli
pip install -r requirements.txt
pip install -e .
pip install masonite_cli --user
pip install -r requirements.txt --user
pip install -e . --user
test:
python -m pytest tests
ci:
make test
make lint
lint:
flake8 masonite/ --ignore=E501,F401,E128,E402,E731,F821,E712,W503
python -m flake8 masonite/ --ignore=E501,F401,E128,E402,E731,F821,E712,W503
deepsource:
curl https://deepsource.io/cli | sh
./bin/deepsource report --analyzer test-coverage --key python --value-file ./coverage.xml
coverage:
pytest --cov-report term --cov-report xml --cov=masonite tests/
python -m pytest --cov-report term --cov-report xml --cov=masonite tests/
python -m coveralls
publish:
pip install 'twine>=1.5.0'
python setup.py sdist bdist_wheel
Expand Down
88 changes: 88 additions & 0 deletions trigger_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"""
This is a script to easily execute circle CI jobs from other repository builds.
Useful if you have a dependent build that you need to run to ensure the latest code is up to date with the parent build.
This script will:
- Fire a build in another circle CI repository
- Loop and call the build_url to continuously get the status
- Wait until the job finishes
- If the job fails this script will exit 1 which will fail the job.
- Else it will exit 0 which will pass the job.
**You will need to download this script and put it in the base of your repository**
Usage:
- python trigger_build.py --repo user/repo --branch branch_name --token CIRCLE_TOKEN --build ENV_VARIABLE=value --build ENV_VARIABLE2=value2
Example:
- python trigger_build.py --repo masoniteframework/validation --branch circle-ci --token $CIRCLE_TOKEN --build MASONITE_BRANCH=$CIRCLE_BRANCH
NOTE: You can get your CircleCI access token via your dashboard. If no token is specified it will use the CIRCLE_TOKEN in your job dashboard.
So if you don't want to pass in the token then put it in the environment variable in your job's dashboard.
Example config:
version: 2
jobs:
Masonite Validation:
docker:
- image: circleci/python:3.6
steps:
- checkout
- run: python trigger_build.py --repo masoniteframework/validation --branch circle-ci --build MASONITE_DEPENDENT_BRANCH=$CIRCLE_BRANCH
"""

import requests
import time
import os
import argparse
parser = argparse.ArgumentParser()

parser.add_argument("-r", "--repo", help="Repository name")
parser.add_argument("-b", "--branch", help="Branch name")
parser.add_argument("-t", "--token", help="Circle CI Token")
parser.add_argument('-a', '--build', action='append', help='Set Build Arguments')
parser.add_argument('-p', '--poll', help='How long the script should sleep before checking status')
args = parser.parse_args()

repo = args.repo
branch = args.branch or 'master'
token = args.token or os.getenv('CIRCLE_TOKEN')
poll = args.poll or 5

if os.getenv('CIRCLE_PR_NUMBER'):
repo = os.getenv('CIRCLE_PR_USERNAME') + '/' + os.getenv('CIRCLE_PR_REPONAME')
branch = os.getenv('CIRCLE_BRANCH')
print('Pull Request #{} Detected. Changing build repo to: {} and branch to {}'.format(os.getenv('CIRCLE_PR_NUMBER'), repo, branch))

parameters = {}
for argument in args.build or []:
if not '=' in argument:
print("ERROR: '--build' argument must contain a '=' sign. Got '{}'".format(argument))
exit(1)
key = argument.split('=')[0]
value = argument.split('=')[1]

parameters.update({key: value})

build_parameters = {'build_parameters': parameters}

r = requests.post('https://circleci.com/api/v1/project/{}/tree/{}?circle-token={}'.format(repo, branch, token), json=build_parameters)

if 'build_num' not in r.json():
print('ERROR: Could not find repository {} or with the branch {}'.format(repo, branch))
print(r.json())
exit(1)

print('Building: ', r.json()['build_num'])

status = requests.get('https://circleci.com/api/v1.1/project/github/{}/{}?circle-token={}'.format(repo, r.json()['build_num'], token))
print('Build Status: ', status.json()['lifecycle'])
while status.json()['lifecycle'] != 'finished':
time.sleep(poll)
print('Build Status: ', status.json()['lifecycle'])
status = requests.get('https://circleci.com/api/v1.1/project/github/{}/{}?circle-token={}'.format(repo, r.json()['build_num'], token))

print('Finished. Failed? ', status.json()['failed'])
if status.json()['failed']:
exit(1)

0 comments on commit 34459d4

Please sign in to comment.