Skip to content

Instantly share code, notes, and snippets.

@username0x0a
Last active November 22, 2020 18:12
Show Gist options
  • Save username0x0a/26b9bf647abcacbffb3f51e4529b1ce8 to your computer and use it in GitHub Desktop.
Save username0x0a/26b9bf647abcacbffb3f51e4529b1ce8 to your computer and use it in GitHub Desktop.
Xcode Server post-integration script allowing commit status updates on Github using Github Statuses API
#!/usr/bin/env ruby
require 'fileutils'
require 'json'
result = ENV["XCS_INTEGRATION_RESULT"].to_s
exit if result == 'canceled'
path = ENV["XCS_SOURCE_DIR"].to_s + '<<repo_name>>'
FileUtils.cd path
commit = `git rev-parse HEAD`.strip
errors = ENV["XCS_ERROR_COUNT"].to_i
warnings = ENV["XCS_WARNING_COUNT"].to_i
analysis = ENV["XCS_ANALYZER_WARNING_COUNT"].to_i
tests = ENV["XCS_TEST_FAILURE_COUNT"].to_i
all = errors + warnings + analysis + tests
status = (all == 0) ? "success":"error"
description = "Deploy successful"
description = "Errors during tests" if tests > 0
description = "Errors during analysis" if analysis > 0
description = "Warnings during compilation" if warnings > 0
description = "Errors during compilation" if errors > 0
json = {
:state => status,
:description => description,
:context => "Xcode Server Bot",
:target_url => "<<url_to_integration_details>>",
}.to_json
`curl -s -H "Content-Type: application/json" -X POST -d '#{json}' "https://api.github.com/repos/<<username>>/<<repo_name>>/statuses/#{commit}" -u <<username>>:<<client_password>>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment