xcodegitcontinuous-integrationxcode-botsxcode-server

How to get SHA of commit for Xcode Bot "Run Script" Trigger? Updating status of tests on Github


I have created an Xcode Bot that integrates on each commit.

In the "Run Script" Trigger I would like to update the current GitHub commit with the integration status of Tests that were run. Pretty standard CI stuff.

Xcode Bot Run Script

I'll then be running a script like the below:

curl -i -X POST -H "Content-type: application/json"
-H 'Authorization: token TOKEN_HERE' -d 
'{
"state": "success",
"target_url": "https://example.com/build/status",
"description": "The build succeeded!",
"context": "continuous-integration/jenkins"
}' 
https://api.github.com/repos/ORGANIZATION_HERE/REPO_HERE/statuses/SHA_HERE

It looks like I'll be able to get the success or failure states from the Xcode Bot Environment variables:

Access build folder in Xcode Server CI bot run (env variables?)

However, the SHA of the current commit is not listed. How am I able to get the SHA of the commit used for the Integration at this point, to be used in the GitHub Status API request?


Solution

  • XCS_OUTPUT_DIR has a file called sourceControl.log. This file has logs like the following:

    "DVTSourceControlLocationRevisionKey" : "3787c0d9e5107861a8b8d4c7300b2d414ad41dbb",
    

    You can parse that log to find the SHA.

    Perhaps more practically, CaveJohnson can pull the SHA:

    PATH=/Library/Frameworks/Python.framework/Versions/3.4/bin:$PATH
    SHA=`cavejohnson getSha`
    

    Or it can just go ahead and set the GitHub status as a one-liner:

    #!/bin/bash
    PATH=/Library/Frameworks/Python.framework/Versions/3.4/bin:$PATH
    cavejohnson setGithubStatus
    

    Notably, there are more statuses than just success and failure, there are at least 6 that I'm aware of. You can read more about them in my Xcode 6 CI Missing Manual.