[ops] use build stages in travis (#3810)
This commit is contained in:
committed by
Florent Vilmart
parent
88de01f3d8
commit
391ac97494
74
.travis.yml
74
.travis.yml
@@ -11,21 +11,6 @@ addons:
|
|||||||
postgresql: '9.5'
|
postgresql: '9.5'
|
||||||
apt_packages:
|
apt_packages:
|
||||||
- postgresql-9.5-postgis-2.3
|
- postgresql-9.5-postgis-2.3
|
||||||
before_script:
|
|
||||||
- node -e 'require("./lib/index.js")'
|
|
||||||
- psql -c 'create database parse_server_postgres_adapter_test_database;' -U postgres
|
|
||||||
- psql -c 'CREATE EXTENSION postgis;' -U postgres -d parse_server_postgres_adapter_test_database
|
|
||||||
- psql -c 'CREATE EXTENSION postgis_topology;' -U postgres -d parse_server_postgres_adapter_test_database
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- COVERAGE_OPTION='./node_modules/.bin/nyc'
|
|
||||||
matrix:
|
|
||||||
- MONGODB_VERSION=3.0.8
|
|
||||||
- MONGODB_VERSION=3.2.6
|
|
||||||
- PARSE_SERVER_TEST_DB=postgres
|
|
||||||
- PARSE_SERVER_TEST_CACHE=redis
|
|
||||||
matrix:
|
|
||||||
fast_finish: true
|
|
||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
@@ -35,14 +20,47 @@ cache:
|
|||||||
directories:
|
directories:
|
||||||
- node_modules
|
- node_modules
|
||||||
- "$HOME/.mongodb/versions"
|
- "$HOME/.mongodb/versions"
|
||||||
|
|
||||||
|
# Test stage
|
||||||
|
stage: test
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- COVERAGE_OPTION='./node_modules/.bin/nyc'
|
||||||
|
matrix:
|
||||||
|
- MONGODB_VERSION=3.0.8
|
||||||
|
- MONGODB_VERSION=3.2.6
|
||||||
|
- PARSE_SERVER_TEST_DB=postgres
|
||||||
|
- PARSE_SERVER_TEST_CACHE=redis
|
||||||
|
before_script:
|
||||||
|
- node -e 'require("./lib/index.js")'
|
||||||
|
- psql -c 'create database parse_server_postgres_adapter_test_database;' -U postgres
|
||||||
|
- psql -c 'CREATE EXTENSION postgis;' -U postgres -d parse_server_postgres_adapter_test_database
|
||||||
|
- psql -c 'CREATE EXTENSION postgis_topology;' -U postgres -d parse_server_postgres_adapter_test_database
|
||||||
after_script:
|
after_script:
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
after_failure:
|
|
||||||
- (cd resources; python travis_after_all.py)
|
|
||||||
after_success:
|
|
||||||
- (cd resources; python travis_after_all.py)
|
|
||||||
- export $(cat resources/.to_export_back)
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
include:
|
||||||
|
# release on github latest branch
|
||||||
|
- stage: release
|
||||||
|
node_js: '6.1'
|
||||||
|
env: RELEASE=github-latest
|
||||||
|
before_script: skip
|
||||||
|
after_script: skip
|
||||||
|
script: skip
|
||||||
|
deploy:
|
||||||
|
- provider: script
|
||||||
|
skip_cleanup: true
|
||||||
|
script: ./resources/npm-git.sh
|
||||||
|
on:
|
||||||
|
branch: master
|
||||||
|
# release on npm
|
||||||
|
- stage: release
|
||||||
|
before_script: skip
|
||||||
|
after_script: skip
|
||||||
|
script: skip
|
||||||
|
node_js: '6.1'
|
||||||
|
env: RELEASE=npm
|
||||||
deploy:
|
deploy:
|
||||||
- provider: npm
|
- provider: npm
|
||||||
skip_cleanup: true
|
skip_cleanup: true
|
||||||
@@ -53,18 +71,18 @@ deploy:
|
|||||||
on:
|
on:
|
||||||
tags: true
|
tags: true
|
||||||
all_branches: true
|
all_branches: true
|
||||||
condition: "$BUILD_LEADER$BUILD_AGGREGATE_STATUS = YESothers_succeeded"
|
|
||||||
repo: parse-community/parse-server
|
repo: parse-community/parse-server
|
||||||
- provider: script
|
# publish on docker
|
||||||
skip_cleanup: true
|
- stage: release
|
||||||
script: ./resources/npm-git.sh
|
before_script: skip
|
||||||
on:
|
after_script: skip
|
||||||
branch: master
|
script: skip
|
||||||
condition: "$BUILD_LEADER$BUILD_AGGREGATE_STATUS = YESothers_succeeded"
|
node_js: '6.1'
|
||||||
|
env: RELEASE=docker
|
||||||
|
deploy:
|
||||||
- provider: script
|
- provider: script
|
||||||
skip_cleanup: true
|
skip_cleanup: true
|
||||||
script: ./resources/docker-hub.sh
|
script: ./resources/docker-hub.sh
|
||||||
on:
|
on:
|
||||||
tags: true
|
tags: true
|
||||||
all_branches: true
|
all_branches: true
|
||||||
condition: "$BUILD_LEADER$BUILD_AGGREGATE_STATUS = YESothers_succeeded"
|
|
||||||
|
|||||||
@@ -30,4 +30,4 @@ git config user.name "Travis CI"
|
|||||||
git config user.email "github@fb.com"
|
git config user.email "github@fb.com"
|
||||||
git add .
|
git add .
|
||||||
git commit -m "Deploy master to LATEST branch"
|
git commit -m "Deploy master to LATEST branch"
|
||||||
git push --force --quiet "https://${GH_TOKEN}@github.com/parseplatform/parse-server.git" master:latest
|
git push --force --quiet "https://${GH_TOKEN}@github.com/parse-community/parse-server.git" master:latest
|
||||||
|
|||||||
@@ -1,102 +0,0 @@
|
|||||||
"""
|
|
||||||
https://github.com/dmakhno/travis_after_all/blob/master/travis_after_all.py
|
|
||||||
https://github.com/graphql/graphql-js/blob/master/resources/travis_after_all.py
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import time
|
|
||||||
import logging
|
|
||||||
|
|
||||||
try:
|
|
||||||
import urllib.request as urllib2
|
|
||||||
except ImportError:
|
|
||||||
import urllib2
|
|
||||||
|
|
||||||
log = logging.getLogger("travis.leader")
|
|
||||||
log.addHandler(logging.StreamHandler())
|
|
||||||
log.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
TRAVIS_JOB_NUMBER = 'TRAVIS_JOB_NUMBER'
|
|
||||||
TRAVIS_BUILD_ID = 'TRAVIS_BUILD_ID'
|
|
||||||
POLLING_INTERVAL = 'LEADER_POLLING_INTERVAL'
|
|
||||||
|
|
||||||
build_id = os.getenv(TRAVIS_BUILD_ID)
|
|
||||||
polling_interval = int(os.getenv(POLLING_INTERVAL, '5'))
|
|
||||||
|
|
||||||
#assume, first job is the leader
|
|
||||||
is_leader = lambda job_number: job_number.endswith('.1')
|
|
||||||
|
|
||||||
if not os.getenv(TRAVIS_JOB_NUMBER):
|
|
||||||
# seems even for builds with only one job, this won't get here
|
|
||||||
log.fatal("Don't use defining leader for build without matrix")
|
|
||||||
exit(1)
|
|
||||||
elif is_leader(os.getenv(TRAVIS_JOB_NUMBER)):
|
|
||||||
log.info("This is a leader")
|
|
||||||
else:
|
|
||||||
#since python is subprocess, env variables are exported back via file
|
|
||||||
with open(".to_export_back", "w") as export_var:
|
|
||||||
export_var.write("BUILD_MINION=YES")
|
|
||||||
log.info("This is a minion")
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
class MatrixElement(object):
|
|
||||||
def __init__(self, json_raw):
|
|
||||||
self.is_finished = json_raw['finished_at'] is not None
|
|
||||||
self.is_succeeded = json_raw['result'] == 0
|
|
||||||
self.number = json_raw['number']
|
|
||||||
self.is_leader = is_leader(self.number)
|
|
||||||
|
|
||||||
|
|
||||||
def matrix_snapshot():
|
|
||||||
"""
|
|
||||||
:return: Matrix List
|
|
||||||
"""
|
|
||||||
response = urllib2.build_opener().open("https://api.travis-ci.org/builds/{0}".format(build_id)).read()
|
|
||||||
raw_json = json.loads(response)
|
|
||||||
matrix_without_leader = [MatrixElement(element) for element in raw_json["matrix"]]
|
|
||||||
return matrix_without_leader
|
|
||||||
|
|
||||||
|
|
||||||
def wait_others_to_finish():
|
|
||||||
def others_finished():
|
|
||||||
"""
|
|
||||||
Dumps others to finish
|
|
||||||
Leader cannot finish, it is working now
|
|
||||||
:return: tuple(True or False, List of not finished jobs)
|
|
||||||
"""
|
|
||||||
snapshot = matrix_snapshot()
|
|
||||||
finished = [el.is_finished for el in snapshot if not el.is_leader]
|
|
||||||
return reduce(lambda a, b: a and b, finished), [el.number for el in snapshot if
|
|
||||||
not el.is_leader and not el.is_finished]
|
|
||||||
|
|
||||||
while True:
|
|
||||||
finished, waiting_list = others_finished()
|
|
||||||
if finished: break
|
|
||||||
log.info("Leader waits for minions {0}...".format(waiting_list)) # just in case do not get "silence timeout"
|
|
||||||
time.sleep(polling_interval)
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
wait_others_to_finish()
|
|
||||||
|
|
||||||
final_snapshot = matrix_snapshot()
|
|
||||||
log.info("Final Results: {0}".format([(e.number, e.is_succeeded) for e in final_snapshot]))
|
|
||||||
|
|
||||||
BUILD_AGGREGATE_STATUS = 'BUILD_AGGREGATE_STATUS'
|
|
||||||
others_snapshot = [el for el in final_snapshot if not el.is_leader]
|
|
||||||
if reduce(lambda a, b: a and b, [e.is_succeeded for e in others_snapshot]):
|
|
||||||
os.environ[BUILD_AGGREGATE_STATUS] = "others_succeeded"
|
|
||||||
elif reduce(lambda a, b: a and b, [not e.is_succeeded for e in others_snapshot]):
|
|
||||||
log.error("Others Failed")
|
|
||||||
os.environ[BUILD_AGGREGATE_STATUS] = "others_failed"
|
|
||||||
else:
|
|
||||||
log.warn("Others Unknown")
|
|
||||||
os.environ[BUILD_AGGREGATE_STATUS] = "unknown"
|
|
||||||
#since python is subprocess, env variables are exported back via file
|
|
||||||
with open(".to_export_back", "w") as export_var:
|
|
||||||
export_var.write("BUILD_LEADER=YES {0}={1}".format(BUILD_AGGREGATE_STATUS, os.environ[BUILD_AGGREGATE_STATUS]))
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
log.fatal(e)
|
|
||||||
Reference in New Issue
Block a user