-
Notifications
You must be signed in to change notification settings - Fork 442
Better SCM CI Integration Overview
NOTE: For now we only support local packages.
SCM CI Integration helps you to collaborate between OBS and the source code management (SCM) systems like GitHub, GitLab or Gitea. It helps to handle your package sources with those systems. This section describes the integration between SCMs and OBS.
- SCM triggers a webhook pointing to our
trigger/workflow
endpoint (someone opened or updated a PR). - Inside
TriggerWorkflowController
:- Extract the event, SCM, and payload from the incoming request.
- Create a
WorkflowRun
- Create a
ScmWebhook
which contains a new payload created after the payload coming from the request. - Call
Token::Workflow
model passing one instance ofWorkflowRun
andScmWebhook
.
-
Token::Workflow
model- Download the
.obs/workflows.yml
file from the target branch, not from the Pull request, using theWorkflows::YAMLDownloader
. - Call the
Workflows::YAMLToWorkflowsService
which returns a collection ofWorkflow
objects for each workflow defined in the configuration file. - Send the initial report back to the SCM with "pending" state. Using
ScmInitialStatusReporter
. - Call each workflow.
- Send the initial report back to the SCM with "success" state. Using
ScmInitialStatusReporter
.
- Download the
-
Workflow
model- Destroy the existing project in case the SCM closes a PR.
- Restore a previously existing project in case the SCM re-opens a PR.
- Handle the steps in other cases:
- Extract the steps from the workflow (
Workflow::Step::BranchPackageStep
,Workflow::Step::LinkPackageStep
andWorkflow::Step::ConfigureRepositoriesStep
etc.) - Call every step.
- Collects the artifacts of each step with
Workflows::ArtifactsCollector
.
- Extract the steps from the workflow (
-
Workflow::Step
model (and its inherited Workflow::Step::*)- Perform the step.
- Create two
Event::Subscription
(storing the token ID in theevent_subscriptions.token_id
column) and in thatEvent::Subscription
, we store the required information to be able to report back to the SCM (repository owner, etc... see below in Reporting Back to SCM).
NOTE: To make the service run on a linked package (link_package
step) we had to make it a "project service" by adding a package named _project
into the target project. The package contains a _service
file with a correct definition of a service.
- Whenever a build finishes in the Backend, a new
Event::BuildFail
orEvent::BuildSuccess
is created and a newReportToScmJob
is queued inscm
queue. Follow this link for a better understanding of the Events system.-
ReportToScmJob
inherits fromCreateJob
. -
CreateJob
is only for jobs dealing with events, since itsperform
method expects anevent_id
. - For the jobs to be created, event classes like
Event::BuildFail
andEvent::BuildSuccess
need to have the following code:create_jobs :report_to_scm_job
. This will then be picked up in theafter_create :perform_create_jobs
callback in theEvent::Base
model. - If the provided symbol in the
create_jobs
method is a valid job inheriting fromCreateJob
, then the corresponding job will be queued. - The
scm
queue service is defined insystemd/obs-delayedjob-queue-scm.service
- We pass the
event_id
to theReportToScmJob
. Using theevent_id
we are fetching the event object, we search for the event subscriptions that match the given event object (eventtype
and package), loop over them and callGitlabStatusReporter
/GithubStatusReporter
/GiteaStatusReporter
(depending on the SCM) for each one.
-
-
GitlabStatusReporter
/GithubStatusReporter
/GiteaStatusReporter
service, called byReportToScmJob
,- Report status back to the SCM for the corresponding commit
- Create an instance of
ScmStatusReport
, which represents the communication between OBS and the SCM. It stores the status (success or fail) and the error message in case of failure. It's associated with the workflow run.
We use Octokit as client for GitHub API.
We use this wrapper for the GitLab API.
For Gitea we created our own module: GiteaAPI::V1::Client (app/apis/gitea_api/v1/client.rb).
Whenever a workflow token is triggered by an incoming webhook, a workflow run is created to track what is happening, thus helping users understand how their workflow behaves. In addition to the headers and payload of the incoming webhook, workflow runs store the response we send back to the SCM and to which URL it is sent. Finally, the status is saved, so users know if the workflow run succeeded or potentially failed due to an error.
- Development Environment Overview
- Development Environment Tips & Tricks
- Spec-Tips
- Code Style
- Rubocop
- Testing with VCR
- Authentication
- Authorization
- Autocomplete
- BS Requests
- Events
- ProjectLog
- Notifications
- Feature Toggles
- Build Results
- Attrib classes
- Flags
- The BackendPackage Cache
- Maintenance classes
- Cloud uploader
- Delayed Jobs
- Staging Workflow
- StatusHistory
- OBS API
- Owner Search
- Search
- Links
- Distributions
- Repository
- Data Migrations
- next_rails
- Ruby Update
- Rails Profiling
- Installing a local LDAP-server
- Remote Pairing Setup Guide
- Factory Dashboard
- osc
- Setup an OBS Development Environment on macOS
- Run OpenQA smoketest locally
- Responsive Guidelines
- Importing database dumps
- Problem Statement & Solution
- Kickoff New Stuff
- New Swagger API doc
- Documentation and Communication
- GitHub Actions
- How to Introduce Software Design Patterns
- Query Objects
- Services
- View Components
- RFC: Core Components
- RFC: Decorator Pattern
- RFC: Backend models