Last active
April 9, 2024 20:50
-
-
Save dctrwatson/4534408 to your computer and use it in GitHub Desktop.
Update Phabricator diff depending on build status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BASE_COMMIT=$(echo {\"diff_id\": ${DIFF_ID}} | arc call-conduit differential.getdiff | awk -v RS=',' -v FS=':' '$1~/\"sourceControlBaseRevision\"/ {print $2}' | tr -d \") | |
# Update repo (can be taken care of by jenkins too) | |
git fetch --all | |
git remote prune origin | |
# We only want to test the diff so reset to base | |
git reset --hard ${BASE_COMMIT} | |
git clean -fdx | |
# Get diff patch | |
arc patch --nobranch --no-ansi --diff ${DIFF_ID} --nocommit | |
# Commit patch (issues occur sometimes with arc patch committing) | |
git commit -m "Applied Diff Id: ${DIFF_ID}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import os | |
import sys | |
import urllib | |
from phabricator import Phabricator | |
# This script is to be run as a PostBuild step by jenkins for *all* builds. | |
# This script assumes the following: | |
# 1. The build machine has an .arcconfig for the jenkins user. | |
# | |
# This script will check the result of the disqus-phabricator job and leave a | |
# message on the differential in phabricator indicating the diff in review will | |
# break tests or not. | |
if __name__ == '__main__': | |
jenkins_url = os.environ["JENKINS_URL"] | |
jenkins_build_url = os.environ["BUILD_URL"] | |
jenkins_job = os.environ["JOB_NAME"] | |
jenkins_build_num = os.environ["BUILD_NUMBER"] | |
console_output_url = jenkins_build_url + "/console" | |
test_report_url = jenkins_build_url + "/aggregatedTestReport/" | |
p = Phabricator() | |
diff_id = os.environ["DIFF_ID"] | |
differential = p.differential.getdiff(diff_id=diff_id) | |
differential_id = differential["revisionID"] | |
build_data_url = jenkins_build_url + "/api/json" | |
print "Reading Jenkins Status..." | |
data = json.load(urllib.urlopen(build_data_url)) | |
result = data["result"] | |
if result == "FAILURE": | |
actions = data['actions'] | |
num_failures = 0 | |
for a in actions: | |
if 'failCount' in a: | |
num_failures = a['failCount'] | |
print "D%s failed tests on diff id %s" % (differential_id, diff_id) | |
if int(num_failures) == 0: | |
message = "Jenkins is unable to run tests with this patch. See %s to see why." % console_output_url | |
else: | |
message = "This patch causes %s tests to fail! See %s to see which tests are failing." % (num_failures, test_report_url) | |
action = "reject" | |
silent = False | |
elif result == "SUCCESS": | |
print "D%s passed all tests with diff id %s" % (differential_id, diff_id) | |
message = "This patch does not break any tests. +1. See the passing build here: %s" % test_report_url | |
action = "none" | |
# This comment should not email everyone. | |
silent = True | |
# If the jenkins job was ABORTED or any other state. | |
else: | |
print "Jenkins status is: %s. Exiting." % result | |
sys.exit(0) | |
print "Creating comment: %s" % message | |
print "Comment has type: %s" % action | |
# This will fail if the differential has been closed already or if | |
# phabricator is not working correctly. We should silently fail and print | |
# out the exception for debugging. By catching the exception we prevent the | |
# error code of the script from being not 0. | |
try: | |
print "Creating Comment..." | |
p.differential.createcomment(revision_id=int(differential_id), message=message, action=action, silent=silent) | |
except BaseException as e: | |
print "Exception When Trying to Create Comment" | |
print e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment