From 93f92bba0845068aa443d252c50db9d7f08b38e5 Mon Sep 17 00:00:00 2001 From: Tobias Megies Date: Sun, 19 Jun 2016 13:12:47 +0200 Subject: [PATCH] PR docs buildbot: check free space/inodes, only build PR docs on request * docs build for PRs can be requested by putting "+DOCS" somewhere in the github comments * current docs buildbot server has relatively low inode quota, avoid again using up all inodes see #1357 --- misc/scripts/docs_buildbot/update-docs-pr.sh | 22 +++++++++++++++++++ .../update_pull_request_metadata.py | 17 ++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/misc/scripts/docs_buildbot/update-docs-pr.sh b/misc/scripts/docs_buildbot/update-docs-pr.sh index 05f220ec7ae..aa0c6892321 100644 --- a/misc/scripts/docs_buildbot/update-docs-pr.sh +++ b/misc/scripts/docs_buildbot/update-docs-pr.sh @@ -1,6 +1,28 @@ #!/bin/bash + cd $HOME anaconda3/bin/python update_pull_request_metadata.py + +# check free space and free inodes (current docs server has relatively low +# inode quota) +## `df` on docs server doesn't have "output" option +## FREE_INODES = `df . --output="iavail" | tail -1` +FREE_INODES = `df $HOME/htdocs -i | tail -1 | awk '{print $4}'` +INODE_CRITICAL = "300000" # 300k +if [ "$FREE_INODES" -lt "$INODE_CRITICAL" ] +then + echo "Aborting PR docs build, low inodes: $FREE_INODES" + exit 1 +fi +FREE_SPACE = `df $HOME/htdocs/ | tail -1 | awk '{print $4}'` +SPACE_CRITICAL = "10000000" # 10G +if [ "$FREE_SPACE" -lt "$SPACE_CRITICAL" ] +then + echo "Aborting PR docs build, low disk space: $FREE_INODES" + exit 1 +fi + + for FILE in `ls pull_request_docs/*.todo 2> /dev/null` do PR=${FILE##*/} diff --git a/misc/scripts/docs_buildbot/update_pull_request_metadata.py b/misc/scripts/docs_buildbot/update_pull_request_metadata.py index 26aeb9b90b7..6d3c7a7fc1e 100644 --- a/misc/scripts/docs_buildbot/update_pull_request_metadata.py +++ b/misc/scripts/docs_buildbot/update_pull_request_metadata.py @@ -1,8 +1,23 @@ import os +import re import requests from obspy import UTCDateTime +def check_docs_build_requested(issue_number): + """ + Check if a docs build was requested for given issue number (by magic string + '+DOCS' anywhere in issue comments). + + :rtype: bool + """ + url = "https://api.github.com/repos/obspy/obspy/issues/{:d}/comments" + data = requests.get(url.format(issue_number), params={"per_page": 100}) + comments = [x["body"] for x in data.json()] + pattern = r'\+DOCS' + return any(re.search(pattern, comment) for comment in comments) + + try: # github API token with "repo.status" access right token = os.environ["OBSPY_COMMIT_STATUS_TOKEN"] @@ -27,6 +42,8 @@ for d in data: # extract the pieces we need from the PR data number = d['number'] + if not check_docs_build_requested(number): + continue fork = d['head']['user']['login'] branch = d['head']['ref'] commit = d['head']['sha']