Skip to content

Commit

Permalink
Merge branch 'develop' into info-manages-path
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanC authored Dec 13, 2018
2 parents 6fa3c68 + c9a0a8a commit 5265779
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 33 deletions.
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/Bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ about: Create a report to help us improve OpenShot

---

**Please fill out this template**

**Describe the bug**
A clear and concise description of what the bug is.

**System Details (please complete the following information):**
- Operating System / Distro: [e.g. Windows 10, Linux Mint 17.1]
- OpenShot Version [e.g. 2.4.1]
- OpenShot Version [e.g. 2.4.3]

**To Reproduce**
Steps to reproduce the behavior:
Expand Down
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/Feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ about: Suggest an idea for OpenShot

---

**Please fill out this template**

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Expand Down
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/i-have-a-question.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ about: Ask a question about obtaining, installing, or using OpenShot

---

**Please fill out this template**

<!--Give your question a descriptive title so that others will be able to understand at a glance how they can help. Then, explain in more detail under "My Question" below -->

**My Question:**
Expand All @@ -15,7 +17,7 @@ about: Ask a question about obtaining, installing, or using OpenShot

**System Details**
- Operating System / Distro: [e.g. Windows 10, Linux Mint 17.1]
- OpenShot Version [e.g. 2.4.1]
- OpenShot Version [e.g. 2.4.3]

**Screenshots**
<!-- If applicable, add screenshots to help illustrate your question. You can include screenshots by copy/pasting them here, dragging-and-dropping into this form, or clicking below and loading images saved to your computer. All images are public, so please don't post screenshots containing personal information. -->
73 changes: 42 additions & 31 deletions installer/build-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import datetime
import platform
import shutil
from slacker import Slacker
import re
import stat
import subprocess
Expand All @@ -42,6 +41,8 @@
import time
import traceback
from github3 import login
from requests.auth import HTTPBasicAuth
from requests import post

# Access info class (for version info)
sys.path.append(os.path.join(PATH, 'src', 'classes'))
Expand All @@ -50,8 +51,7 @@
freeze_command = None
errors_detected = []
make_command = "make"
slack_token = None
slack_object = None
zulip_token = None
s3_access_key = None
s3_secret_key = None
s3_connection = None
Expand All @@ -75,6 +75,7 @@ def run_command(command, working_dir=None):
stderr=subprocess.STDOUT)
return iter(p.stdout.readline, b"")


def output(line):
"""Append output to list and print it"""
print(line)
Expand All @@ -86,6 +87,7 @@ def output(line):
line += "\n"
log.write(line)


def error(line):
"""Append error output to list and print it"""
print("Error: %s" % line)
Expand All @@ -95,43 +97,53 @@ def error(line):
else:
log.write(line)


def truncate(message, max=256):
"""Truncate the message with ellipses"""
if len(message) < max:
return message
else:
return "%s..." % message[:max]

def slack(message):
"""Append a message to slack #build-server channel"""
print("Slack: %s" % message)
if slack_object:
slack_object.chat.post_message("#build-server", truncate(message[:256]))

def slack_upload_log(log, title, comment=None):
"""Upload a file to slack and notify a slack channel"""
def zulip_upload_log(log, title, comment=None):
"""Upload a file to zulip and notify a zulip channel"""
output("Zulip Upload: %s" % log_path)

# Close log file
log.close()

print("Slack Upload: %s" % log_path)
if slack_object:
for attempt in range(3):
try:
# Upload build log to slack (and append platform icon to comment [:linux:, :windows:, or :darwin:])
slack_object.files.upload(log_path, filetype="txt", filename="%s-build-server.txt" % platform.system(),
title=title, initial_comment=':%s: %s' % (platform.system().lower(), comment), channels="#build-server")
# Successfully uploaded!
break
except Exception as ex:
# Quietly fail, and try again
if attempt < 2:
output("Upload log to Slack failed... trying again")
else:
# Throw loud exception
raise Exception('Log upload to Slack failed: %s' % log_path, ex)
# Authentication for Zulip
zulip_auth = HTTPBasicAuth('builder-bot@openshot.zulipchat.com', zulip_token)
filename = "%s-build-server.txt" % platform.system()

# Upload file to Zulip
zulip_url = 'https://openshot.zulipchat.com/api/v1/user_uploads'
zulip_upload_url = ''
resp = post(zulip_url, data={}, auth=zulip_auth, files={filename: (filename, open(log_path, "rb"))})
if resp.ok:
zulip_upload_url = resp.json().get("uri", "")
print(resp)

# Determine topic
topic = "Successful Builds"
if "skull" in comment:
topic = "Failed Builds"

# SEND MESSAGE
zulip_url = 'https://openshot.zulipchat.com/api/v1/messages'
zulip_data = {
"type": "stream",
"to": "build-server",
"subject": topic,
"content": ':%s: %s [Build Log](%s)' % (platform.system().lower(), comment, zulip_upload_url)
}

resp = post(zulip_url, data=zulip_data, auth=zulip_auth)

# Re-open the log (for append)
log = open(log_path, "a")
print(resp)

def get_release(repo, tag_name):
"""Fetch the GitHub release tagged with the given tag and return it
Expand Down Expand Up @@ -191,8 +203,7 @@ def parse_version_info(version_path):
try:
# Validate command-line arguments
if len(sys.argv) >= 2:
slack_token = sys.argv[1]
slack_object = Slacker(slack_token)
zulip_token = sys.argv[1]
if len(sys.argv) >= 4:
s3_access_key = sys.argv[2]
s3_secret_key = sys.argv[3]
Expand Down Expand Up @@ -492,8 +503,8 @@ def parse_version_info(version_path):
# Torrent succeeded! Upload the torrent to github
url = upload(torrent_path, github_release)

# Notify Slack
slack_upload_log(log, "%s: Build logs for %s" % (platform.system(), app_name), "Successful *%s* build: %s" % (git_branch_name, download_url))
# Notify Zulip
zulip_upload_log(log, "%s: Build logs for %s" % (platform.system(), app_name), "Successful *%s* build: %s" % (git_branch_name, download_url))

except Exception as ex:
tb = traceback.format_exc()
Expand All @@ -502,6 +513,6 @@ def parse_version_info(version_path):

# Report any errors detected
if errors_detected:
slack_upload_log(log, "%s: Error log for *%s* build" % (platform.system(), git_branch_name), ":skull_and_crossbones: %s" % truncate(errors_detected[0], 150))
zulip_upload_log(log, "%s: Error log for *%s* build" % (platform.system(), git_branch_name), ":skull_and_crossbones: %s" % truncate(errors_detected[0], 100))
exit(1)

0 comments on commit 5265779

Please sign in to comment.