Bonfire.Common.TriggerCI (Bonfire v1.0.0-social-rc.1.19)

View Source

WIP: A module for triggering CI/CD rebuilds across different providers. Requires explicit provider specification for reliable operation.

Provider Compatibility

GitHub Actions

Requires adding repository_dispatch trigger to your workflow:

name: Deploy
on:
  push:
    branches: [main]
  repository_dispatch:    # Add this line
    types: [push]         # Add this line

Gitea Actions

Similar to GitHub Actions - requires adding repository_dispatch trigger.

Drone CI

Works with existing .drone.yml files without modification. Triggers a new build on the specified branch.

GitLab CI

Works with existing .gitlab-ci.yml files without modification. Uses pipeline trigger API to simulate a push event.

Examples

# GitHub 
trigger_rebuild(:github, "mayel", "my-website", "ghp_token123")
#=> {:ok, %{provider: :github, method: :repository_dispatch, status: :success}}

# GitLab 
trigger_rebuild(:gitlab, "mayel", "my-site", "glpat-token123")
#=> {:ok, %{provider: :gitlab, method: :pipeline_trigger, status: :success, response: %{...}}}

# GitLab - with a self-hosted instance
trigger_rebuild(:gitlab, "gitlab.project.org", "mayel", "my-site", "glpat-token123")

# Drone - works with any Drone instance
trigger_rebuild(:drone, "drone.project.org", "mayel", "api", "drone_token123")
#=> {:ok, %{provider: :drone, method: :build_trigger, status: :success, response: %{...}}}

# Gitea - works with any Gitea instance  
trigger_rebuild(:gitea, "git.project.org", "mayel", "project", "gitea_token123")
#=> {:ok, %{provider: :gitea, method: :repository_dispatch, status: :success}}

Setup Instructions

Gitea

  1. Create a Personal Access Token
  2. Add repository_dispatch: types: [push] to your workflow triggers
  3. Use the token with TriggerCI

GitHub

  1. Create a Personal Access Token with repo scope
  2. Add repository_dispatch: types: [push] to your workflow triggers
  3. Use the token with TriggerCI

GitLab

  1. Go to Project Settings > CI/CD > Pipeline triggers
  2. Create a new trigger token
  3. Use the token with TriggerCI (works immediately with existing pipelines)

Drone

  1. Create a user token in your Drone settings
  2. Use the token with TriggerCI (works immediately with existing pipelines)

Summary

Types

provider()

@type provider() :: :github | :gitlab | :drone | :gitea

repo_info()

@type repo_info() :: %{
  host: String.t(),
  owner: String.t(),
  name: String.t(),
  provider: provider()
}

trigger_options()

@type trigger_options() :: Keyword.t()

Functions

req_options()

trigger_rebuild(provider, host \\ nil, owner, repo_name, token, options \\ [])

@spec trigger_rebuild(
  provider(),
  String.t(),
  String.t(),
  String.t(),
  String.t(),
  trigger_options()
) :: {:ok, any()} | {:error, any()}

Triggers a CI rebuild with explicit provider specification.

Parameters

  • provider - CI provider atom (:github, :gitlab, :drone, :gitea)
  • host - Git host (e.g., "github.com", "gitlab.example.com", "drone.company.com")
  • owner - Repository owner/organization
  • repo_name - Repository name
  • token - Authentication token for the CI provider
  • options - Optional keyword list with configuration (see trigger_options/0)

Examples

iex> trigger_rebuild(:github, "github.com", "mayel", "test", "token")
{:ok, %{provider: :github, method: :repository_dispatch, status: :success}}

iex> trigger_rebuild(:gitlab, "gitlab.com", "mayel", "test", "token", branch: "develop")
{:ok, %{provider: :gitlab, method: :pipeline_trigger, status: :success, response: %{}}}

iex> trigger_rebuild(:unknown, "example.com", "owner", "repo", "token")
{:error, "Unsupported provider: unknown"}