This post will be about continuous integration between [Open Build Service] and [GitHub].

Tokens and webhooks

  1. Create a personal access token in GitHub with the “repo” scope. In large repositories, that should be done in a service account.

  2. Create token in OBS with the following parameters:

    • Type: Workflow
    • Name: GitHub
    • SCM token: GITHUB_PERSONAL_TOKEN
  3. Create WebHook in the GitHub repository with the following parameters:

The .obs/workflows.yml file

This file needs to go to the Git repository:

---
pr:
  steps:
  - branch_package:
      source_project: home:pdostal
      source_package: helloworldpackage
      target_project: home:pdostal:releases
  filters:
    event: pull_request
master:
  steps:
  - trigger_services:
      project: home:pdostal
      package: helloworldpackage
  filters:
    event: push
    branches:
      only:
      - master

The OBS _service file

The corresponding _service:

<services>
  <service name="obs_scm">
    <param name="url">https://github.com/pdostal/helloworldpackage.git</param>
    <param name="scm">git</param>
    <param name="revision">master</param>
    <param name="versionformat">@PARENT_TAG@.%h</param>
    <param name="versionrewrite-pattern">v(.*)</param>
  </service>
  <service name="set_version" mode="buildtime"/>
  <service name="tar" mode="buildtime"/>
</services>

The obs_scm service fetches the master from git. The package version is determined using the versionformat parameter and then set to the spec file using the set_version.

Debugging:

Github

In the Webhooks section of project settings, open the OBS webhook and then select the “Recent deliveries” tab. Here you can see the recent triggers and their request & response bodies.

OBS

You can see the recent events as well as their Artifacts in “My profile” -> Tokens -> Token ID -> Workflow Runs.

Sources: