Page MenuHomec4science

Unit Tests
Updated 2,684 Days AgoPublic

Version 26 of 35: You are viewing an older version of this document, as it appeared on Dec 21 2016, 12:00.
WARNING: Jenkins only works for public repositories for now (Credentials are global), we're working on it

How to do continuous integration

There are two ways of doing unit testing in c4science

Using Arcanist on your local machine

We'll be using a community extensions to integrate your custom unit test engine with Phabricator. This extensions allows any TAP compatible engine to be used. You can also write your own engine, take a look at the documentation.

  • In your repository
  • Add the lib as a submodule
git submodule add https://github.com/tagview/arcanist-extensions.git .arcanist-extensions
git submodule update --init
  • Create an .arcconfig file with the following content
{
  "load": [
    ".arcanist-extensions/tap_test_engine"
  ],

  "unit.engine": "TAPTestEngine",
  "unit.engine.tap.command": "your_unit_test_script.sh"
}
  • Replace your_unit_test_script.sh by a script in your repository that do the unit testing and returns the result in a TAP format
  • For instance if your code is in python, you can use tap.py, see the example in rPHTEST

Using Jenkins and Harbormaster on c4science

Here are the step that you have to setup, detailed in the following sections.

  • Create a Jenkins Job with parameters
  • Create a Build Plan on Harbormaster which will trigger the Job
  • Create an Herald rule which will trigger the Build Plan

Create a new Job

  • Create a new Item of type "Freestyle project", give it a name

  • If you want to trigger the build from Herald on a new Diffusion or Commit: choose "This build is parameterized" and add a new String Parameter with the name PHID

  • Select Git as source code management and put the URL of the repository
    • If your repository is private, you have to create a new Creadential for it, for instance using an SSH key with your Phabricator username, You'll add the public key to your phabricator profile: https://c4science.ch/settings/panel/ssh/

  • If you want to periodically build the project, select the option under Build triggers and use this syntax H/30 * * * * to build every 30 mn. See complete documentation about the syntax by clicking on the question mark on the right of the field

  • To run your unit test, add a Build step, select Execute Shell and provide the command to run your tests

  • If you want to specify the docker image, you can choose on by clicking on "Restrict where this project can be run" with the following values
    • ubuntu:trusty Ubuntu Trusty 14.04.4 LTS x86_64
    • centos:7 Centos 7.2 x86_64
    • More to come

  • If you want to trigger the build from Phabricator, under Build Triggers, tick "Trigger builds remotely" and create a token.
    • The best would be some random string, you can generate one like this on a linux shell: head -c 16 /dev/urandom | md5sum
  • To have the status reported back to Phabricator, add the "Post to Phabricator" post-build step
Trigger build on commit
  • You can trigger a build from Phabricator using Harbormaster and Herald applications, either on commit or on differential
Harbormaster (run build)

NOTE: This is a hack and potentially gives access to other users to your build plan. Only use Jenkins for public projects for now
  • Add a new Build Step of type "Make HTTP Request"

  • Add the following URL, https://jenkins.c4science.ch/buildByToken/buildWithParameters?PHID=${target.phid}&token=<your token>&job=<your job name>
  • Select "GET" on the HTTP Method field
  • Select "Wait For Message" on the When Complete field.
  • Save your step

Herald (Notification and action)
  • Go to Herald, https://c4science.ch/herald/
  • Create a new Rule on Commits of type Object
  • Put the reference of your object, the repository ID (rXX) or callsign (rCALLSIGN)
  • Give it a name and select the condition as "Repository is any of <your repository>"
  • Then select the "Run build plans" action with your newly created Build plan
  • Save the rule
  • Now when a commit is pushed on your repository, a build will be generated on your Jenkins job and the result will be reported back to phabricator.
  • You can access the jenkins job build in the harbormaster build, under artifacts, as shown on this image

Last Author
aubort
Last Edited
Dec 21 2016, 12:00

Event Timeline

admin moved this document from Restricted Phriction Wiki DocumentFeb 20 2016, 13:45
admin edited the content of this document. (Show Details)Mar 8 2016, 13:19
admin changed the title from Unit Tests with arcanist to Unit Tests and Lint.Mar 8 2016, 14:53
admin edited the content of this document. (Show Details)Mar 11 2016, 12:50
admin changed the title from Unit Tests and Lint to Unit Tests.
admin edited the content of this document. (Show Details)
admin edited the content of this document. (Show Details)
admin edited the content of this document. (Show Details)Mar 11 2016, 16:55
admin edited the content of this document. (Show Details)Mar 11 2016, 17:10
admin edited the content of this document. (Show Details)Mar 11 2016, 17:12
admin edited the content of this document. (Show Details)Mar 12 2016, 00:41
aubort edited the content of this document. (Show Details)Apr 7 2016, 17:31
aubort edited the content of this document. (Show Details)Apr 8 2016, 09:42
aubort edited the content of this document. (Show Details)Apr 8 2016, 10:05
aubort edited the content of this document. (Show Details)Jun 2 2016, 16:39
aubort edited the content of this document. (Show Details)
aubort edited the content of this document. (Show Details)Jun 3 2016, 16:36
aubort added a subscriber: jenkins.
aubort changed the visibility from "All Users" to "Public (No Login Required)".Jun 7 2016, 12:46
aubort edited the content of this document. (Show Details)Sep 2 2016, 10:10
aubort edited the content of this document. (Show Details)
aubort edited the content of this document. (Show Details)Oct 7 2016, 15:45
aubort edited the content of this document. (Show Details)Oct 7 2016, 15:53
aubort edited the content of this document. (Show Details)Oct 9 2016, 16:54
aubort edited the content of this document. (Show Details)Oct 9 2016, 17:57
aubort edited the content of this document. (Show Details)
aubort edited the content of this document. (Show Details)Oct 13 2016, 15:36
aubort changed the edit policy from "c4science (Project)" to "Restricted Project (Project)".Dec 16 2016, 16:50
aubort edited the content of this document. (Show Details)Dec 21 2016, 11:59
aubort edited the content of this document. (Show Details)
aubort edited the content of this document. (Show Details)Dec 21 2016, 12:01
aubort edited the content of this document. (Show Details)Mar 13 2017, 15:25
aubort added a project: c4science.
aubort removed a subscriber: jenkins.
aubort edited the content of this document. (Show Details)Nov 8 2017, 11:18
aubort added a subscriber: jenkins.
aubort edited the content of this document. (Show Details)Apr 3 2018, 12:52
aubort edited the content of this document. (Show Details)
aubort edited the content of this document. (Show Details)
aubort removed a subscriber: jenkins.
aubort edited the content of this document. (Show Details)Oct 31 2018, 16:41
aubort edited the content of this document. (Show Details)Dec 4 2018, 11:29
aubort edited the content of this document. (Show Details)