Browse Source

drone: coverage and posting to mattermost

deb_package
Sebastian Heimann 1 year ago
parent
commit
da38e581b6
3 changed files with 199 additions and 10 deletions
  1. +14
    -0
      .coveragerc
  2. +95
    -10
      .drone.yml
  3. +90
    -0
      maintenance/drone-matterpost.py

+ 14
- 0
.coveragerc View File

@ -0,0 +1,14 @@
[run]
source = pyrocko
[report]
exclude_lines =
def __repr__
def __str__
raise AssertionError
raise NotImplementedError
raise ValueError
raise
if __name__ == .__main__.:
logger.error
if pyrocko.grumpy:

+ 95
- 10
.drone.yml View File

@ -26,7 +26,7 @@ steps:
image: pyrocko-aux
pull: never
commands:
- maintenance/drone-rsync.sh doc/build/html/ ${DRONE_COMMIT}/doc/
- maintenance/drone-rsync.sh doc/build/html/ ${DRONE_COMMIT}/docs/
environment:
RSYNC_HOST:
from_secret: rsync-host
@ -92,7 +92,21 @@ steps:
- pip3 install utm
- pip3 install git+https://github.com/pyrocko/kite
- pip3 install obspy
- python3 -m nose test.base
- python3 -m coverage run --parallel-mode -m nose test.base
- for x in .coverage.* ; do mv $x $${x#.} ; done
- name: stage
image: pyrocko-aux
pull: never
commands:
- maintenance/drone-rsync.sh coverage.* ${DRONE_COMMIT}/coverage/data/
environment:
RSYNC_HOST:
from_secret: rsync-host
RSYNC_USER:
from_secret: rsync-user
RSYNC_KEY:
from_secret: rsync-key
---
@ -109,7 +123,21 @@ steps:
- pip3 install utm
- pip3 install git+https://github.com/pyrocko/kite
- pip3 install obspy
- python3 -m nose test.gf
- python3 -m coverage run --parallel-mode -m nose test.gf
- for x in .coverage.* ; do mv $x $${x#.} ; done
- name: stage
image: pyrocko-aux
pull: never
commands:
- maintenance/drone-rsync.sh coverage.* ${DRONE_COMMIT}/coverage/data/
environment:
RSYNC_HOST:
from_secret: rsync-host
RSYNC_USER:
from_secret: rsync-user
RSYNC_KEY:
from_secret: rsync-key
---
@ -126,7 +154,21 @@ steps:
- pip3 install utm
- pip3 install git+https://github.com/pyrocko/kite
- pip3 install obspy
- python3 -m nose test.examples
- python3 -m coverage run --parallel-mode -m nose test.examples
- for x in .coverage.* ; do mv $x $${x#.} ; done
- name: stage
image: pyrocko-aux
pull: never
commands:
- maintenance/drone-rsync.sh coverage.* ${DRONE_COMMIT}/coverage/data/
environment:
RSYNC_HOST:
from_secret: rsync-host
RSYNC_USER:
from_secret: rsync-user
RSYNC_KEY:
from_secret: rsync-key
---
@ -141,7 +183,21 @@ steps:
commands:
- python3 setup.py install -f
- pip3 install obspy
- xvfb-run -s '-screen 0 640x480x24' python3 -m nose test.gui test.base.test_obspy_compat:ObsPyCompatTestCase.test_obspy_fiddle test.base.test_obspy_compat:ObsPyCompatTestCase.test_obspy_snuffle
- xvfb-run -s '-screen 0 640x480x24' python3 -m coverage run --parallel-mode -m nose test.gui test.base.test_obspy_compat:ObsPyCompatTestCase.test_obspy_fiddle test.base.test_obspy_compat:ObsPyCompatTestCase.test_obspy_snuffle
- for x in .coverage.* ; do mv $x $${x#.} ; done
- name: stage
image: pyrocko-aux
pull: never
commands:
- maintenance/drone-rsync.sh coverage.* ${DRONE_COMMIT}/coverage/data/
environment:
RSYNC_HOST:
from_secret: rsync-host
RSYNC_USER:
from_secret: rsync-user
RSYNC_KEY:
from_secret: rsync-key
---
@ -149,10 +205,11 @@ kind: pipeline
type: docker
name: coverage
trigger:
branch:
- candidate
- coverage
depends_on:
- tests-base
- tests-gf
- tests-examples
- tests-gui
steps:
- name: build
@ -163,7 +220,8 @@ steps:
- pip3 install utm
- pip3 install git+https://github.com/pyrocko/kite
- pip3 install obspy
- xvfb-run -s '-screen 0 640x480x24' python3 -m nose --with-coverage test
- wget -r -nH --cut-dirs=2 --no-parent --reject="index.html*" https://data.pyrocko.org/builds/${DRONE_COMMIT}/coverage/data/
- python3 -m coverage combine coverage/data/coverage.*
- python3 -m coverage html
- name: stage
@ -178,3 +236,30 @@ steps:
from_secret: rsync-user
RSYNC_KEY:
from_secret: rsync-key
---
kind: pipeline
type: docker
name: publish
depends_on:
- coverage
- flake8
- docs
- pip-wheels
trigger:
status:
- success
- failure
steps:
- name: post
image: pyrocko-nest
pull: never
commands:
- maintenance/drone-matterpost.py
environment:
WEBHOOK:
from_secret: hive-webhook

+ 90
- 0
maintenance/drone-matterpost.py View File

@ -0,0 +1,90 @@
#!/usr/bin/env python3
import os
import random
import requests
def quoteliteral(s):
s = '\n'.join(' '+x for x in s.splitlines())
return '''```
%s
```
''' % s
def to_message():
message = {
'username': 'Pyrocko Build Factory',
'icon_url': 'https://pyrocko.org/_static/pyrocko.svg',
'attachments': [],
}
text = '\n'.join(
'%s: %s' % (k, os.environ[k]) for k in sorted(os.environ.keys()))
env = os.environ
keys = '''
commit commit_message
commit_author commit_author_name commit_author_email commit_link
build_number build_link build_status
'''.split()
env = dict((k, os.environ['DRONE_' + k.upper()]) for k in keys)
emos_success = [':%s:' % s for s in '''
sunny star hatched_chick hamster dog butterfly sunglasses smile
heart_eyes stuck_out_tongue smile_cat muscle +1 ok_hand clap rainbow
beer champagne clinking_glasses medal_sports medal_military
man_cartwheeling woman_cartwheeling fireworks'''.split()]
emos_failure = [':%s:' % s for s in '''
frowning_face weary skull skull_and_crossbones cold_sweat -1
middle_finger scream_cat hankey tornado cloud_with_rain fire 8ball
boxing_glove hocho bomb rage1'''.split()]
env['emo'] = random.choice(
emos_success if env['build_status'] == 'success' else emos_failure)
artifacts = []
for name, link in [
('docs', 'https://data.pyrocko.org/builds/%s/docs/'),
('coverage', 'https://data.pyrocko.org/builds/%s/coverage/'),
('wheels', 'https://data.pyrocko.org/builds/%s/wheels/')]:
link = link % env['commit']
r = requests.get(link)
if r.status_code == 200:
artifacts.append((name, link))
env['artifacts'] = ' '.join(
'[%s](%s)' % (name, link) for (name, link) in artifacts)
text = '''{emo} **Build [{build_number}]({build_link}): {build_status}**
Commit: [{commit}]({commit_link}) by {commit_author} ([{commit_author_name}](mailto:{commit_author_email}))
{commit_message}
Artifacts: {artifacts}
'''.format(**env) # noqa
attachment = {
'fallback': 'test',
'color': '#33CC33' if env['build_status'] == 'success' else '#CC3333',
'text': text,
}
message['attachments'].append(attachment)
return message
def mattermost_post(webhook, message):
requests.post(webhook, json=message)
if __name__ == '__main__':
webhook = os.environ.get('WEBHOOK', None)
message = to_message()
if webhook:
mattermost_post(webhook, message)
else:
print(message)

Loading…
Cancel
Save