Sunday, 28 December 2014

Building Apps with MerOBS and Github using Webhooks


So you've heard about this OBS thing and it sounds like a good idea but how do you use it? If you already use Github then getting the MerOBS to work for you is really easy, and will automatically build release RPMs for your tagged Github releases.

What is MerOBS?
build.merproject.org is an Open Build Service useful for compiling programs in a standardised and repeatable way for SailfishOS. Using MerOBS to build your app for release is a good idea, and allows it to be added into other community distribution repositories like Chum.

Sounds cool, how do I set it up?
I am assuming you are already set up with your project on Github, as it seems to be the most popular of source control SaaS platforms out there.

1. Get yourself a MerOBS login
To register for the OBS you need to get yourself a Mer Bugzilla login and wait a few minutes after creation to allow it to sync across to the OBS.

2. Create your home project
Once you've logged into the MerOBS you will need to set up your home project. This is your own personal area on the OBS which you can develop your build packages as well as distribute apps for testing by direct download or adding your repository URL into pkcon/zypper on your SailfishOS device.

3. Add SailfishOS repository to your Home Project
Once you're in your Home Project, go to the Repositories tab and add SailfishOS Latest. This tells all packages in your Home Project that you want to build them for SailfishOS.

4. Create a Package for your App
Back on the home screen for your Home Project, give it the name of your Sailfish App package and a brief description.

5. Add user cibot to your package maintainers
In your Package, go to the Users Tab and add user cibot to your package with the role maintainer. This is the user which receives Webhook events from Github and makes the magic happen.

6. Add _service file
Create a file on your computer with your favourite text editor named _service (be careful to remove any file extentions on windows).

in this file we will insert some XML, using the Github URL for your Sailfish App repository.

 <services>
   <service name="webhook">
     <param name="repourl">https://github.com/[your_user]/[your_app_repository].git</param>
     <param name="branch">master</param>
   </service>
 </services>

 and upload this _service file into your MerOBS package using the 'Add File' menu.

7. Configure Webhooks in Github
We need to configure Github to send Webhooks to the MerOBS when a new release is tagged. To do this open up your Github repository and go to Settings > Webhooks & Services > Add a Webhook.

Use https://webhook.merproject.org/webhook/ as the Payload URL

These following items should be set to default, but just check:
  1. Content type should be application/json
  2. Enable SSL verification
  3. Enable Just the push event
  4. Enable Active

8. Tag a release and watch it build!
By this point if you have already tagged a release on your Github project, then the latest release should be building on MerOBS. Otherwise create a release in Github using the releases menu and once that's completed have a look back at your package in MerOBS and there should be extra files there now and a build status on the right side.

9. So it says it built successfully, now what?

You can add your MerOBS repository to your SailfishOS device through Terminal
ssu ar merobs-[your_user] http://repo.merproject.org/obs/home:/[your-user]/sailfish_latest_armv7hl/
pkcon refresh

and from there you should be able to install your newly built app using:
pkcon install [your-package-name]

10. Enjoy your automatic MerOBS Builds!
Now whenever you tag a new release MerOBS will build it for you, and from there you can download it and release on OpenRepos, install it using pkcon from your Home Project, upload it onto your Github, whatever you want really!

If you need help with the MerOBS best place is to pop into #mer on irc.freenode.net