Bonfire.Common.TriggerCI (Bonfire v1.0.0-social-rc.1.19)
View SourceWIP: 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
- Create a Personal Access Token
- Add
repository_dispatch: types: [push]
to your workflow triggers - Use the token with TriggerCI
GitHub
- Create a Personal Access Token with
repo
scope - Add
repository_dispatch: types: [push]
to your workflow triggers - Use the token with TriggerCI
GitLab
- Go to Project Settings > CI/CD > Pipeline triggers
- Create a new trigger token
- Use the token with TriggerCI (works immediately with existing pipelines)
Drone
- Create a user token in your Drone settings
- Use the token with TriggerCI (works immediately with existing pipelines)
Summary
Functions
Triggers a CI rebuild with explicit provider specification.
Types
Functions
@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/organizationrepo_name
- Repository nametoken
- Authentication token for the CI provideroptions
- Optional keyword list with configuration (seetrigger_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"}