Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add info around reporting custom PR status to GitHub #259

Open
dacharyc opened this issue Oct 27, 2020 · 2 comments
Open

Add info around reporting custom PR status to GitHub #259

dacharyc opened this issue Oct 27, 2020 · 2 comments

Comments

@dacharyc
Copy link
Contributor

dacharyc commented Oct 27, 2020

A Tugboat user in the Support Slack asked about creating a custom PR status for running PHPUnit functional tests in the online phase.

@bchavet suggested this:

Catch the error & report it using a curl to GitHub’s API. An example like this should work:
curl -H "Authorization: token $GHTOKEN" -X POST -d '{"state": "failure", "context": "Custom Check"}' https://api.github.com/repos/$TUGBOAT_GITHUB_OWNER/$TUGBOAT_GITHUB_REPO/statuses/$TUGBOAT_PREVIEW_SHA

Where $GHTOKEN is an environment variable you define on the Tugboat repo with a GitHub API token.

If tests are done with a single command, this example should work:

your-command-here && \ curl -H "Authorization: token $GHTOKEN" -X POST -d '{"state": "success", "context": "Custom Check"}' \ https://api.github.com/repos/$TUGBOAT_GITHUB_OWNER/$TUGBOAT_GITHUB_REPO/statuses/$TUGBOAT_PREVIEW_SHA || \ curl -H "Authorization: token $GHTOKEN" -X POST -d '{"state": "failure", "context": "Custom Check"}' \ https://api.github.com/repos/$TUGBOAT_GITHUB_OWNER/$TUGBOAT_GITHUB_REPO/statuses/$TUGBOAT_PREVIEW_SHA

Ben pulled the info for this from these resources:

@longwave
Copy link

longwave commented Oct 27, 2020

For reference this is the online phase YAML I use to get Drupal 9 PHPUnit tests running on Tugboat and reporting back to GitHub. This also includes setting the status as "pending" before the test run.

online:
  - >
    curl -s -H "Authorization: token $GHTOKEN" -X POST -d '{"state": "pending", "context": "PHPUnit"}' https://api.github.com/repos/$TUGBOAT_GITHUB_OWNER/$TUGBOAT_GITHUB_REPO/statuses/$TUGBOAT_PREVIEW_SHA
  - >
    cd ${TUGBOAT_ROOT}/web
    && SIMPLETEST_BASE_URL=${TUGBOAT_SERVICE_URL}  SIMPLETEST_DB="mysql://tugboat:tugboat@mysql/tugboat" SYMFONY_DEPRECATIONS_HELPER=disabled ../vendor/bin/phpunit
    && curl -s -H "Authorization: token $GHTOKEN" -X POST -d '{"state": "success", "context": "PHPUnit"}' https://api.github.com/repos/$TUGBOAT_GITHUB_OWNER/$TUGBOAT_GITHUB_REPO/statuses/$TUGBOAT_PREVIEW_SHA
    || curl -s -H "Authorization: token $GHTOKEN" -X POST -d '{"state": "failure", "context": "PHPUnit"}' https://api.github.com/repos/$TUGBOAT_GITHUB_OWNER/$TUGBOAT_GITHUB_REPO/statuses/$TUGBOAT_PREVIEW_SHA

@dacharyc
Copy link
Contributor Author

Thanks, @longwave ! That's excellent. I'll incorporate that into the new doc 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants