Integrating Continuous Integration
Install GitHub App
Install the following GitHub App only on the repositories you want to automatically run workflows.
Create a new sensor
Create a sensor in manifests/system/argo-events/sensors. You can use whatever workflow template from manifests/system/argo-events/workflow-templates you want.
Check the official documentation for more information. As an example, here is the sensor for deploying this documentation automatically when changes are pushed to the main branch.
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
name: docs-apps-deploy # (1)!
namespace: argo-events
spec:
revisionHistoryLimit: 3
template:
serviceAccountName: operate-workflow-sa
dependencies:
- name: github-webhook
eventSourceName: github-app-argo-events
eventName: argo-events-hook
filters: # (2)!
dataLogicalOperator: and
data:
- path: body.repository.full_name
type: string
value: # (3)!
- AgrospAI/apps-deploy
- path: headers.X-Github-Event
type: string
valueLogicalOperator: or
value: # (4)!
- push
- merge
- path: body.ref
type: string
value: # (5)!
- refs/heads/main
- path: '[body.commits.#.modified.#()#,body.commits.#.added.#()#,body.commits.#.removed.#()#]'
type: string
value: # (6)!
- 'docs/.*'
triggers:
- template:
name: ci-cd-github-docker-hash # (7)!
argoWorkflow:
operation: submit
source:
resource:
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
generateName: webhook-
spec:
workflowTemplateRef:
name: ci-cd-github-docker-hash
arguments:
parameters: # (8)!
- name: repository-full-name
- name: ref
- name: image-name
value: 'agrospai/docs-apps-deploy'
- name: manifests-path
value: 'manifests/agrospai/docs-apps-deploy'
- name: patterns
value: '/docs/*'
- name: docker-context
value: '/docs'
- name: docker-path
value: 'Dockerfile.prod'
parameters: # (9)!
- src:
dependencyName: github-webhook
dataKey: body.repository.full_name
dest: spec.arguments.parameters.0.value
- src:
dependencyName: github-webhook
dataKey: body.ref
dest: spec.arguments.parameters.1.value
- The name of the sensor must be unique.
- Only run the workflow if the following conditions are met.
- The full name of the repository in the format
owner/repo. - The type of event that will trigger the sensor.
- The branch that will trigger the sensor. Notice that the branch name is prefixed with
refs/heads/. - Use regular expression to detect the files that were modified, added, or removed (source).
- The name of the workflow template to run, it should be in
manifests/system/argo-events/workflow-templates. - Pass the parameters that you want to customize in the workflow template.
- Some parameters can be automatically filled with the data from the event.
Note: The
eventSourceNameandeventName(combined) reference an EventSource where the events of the repositories that have the GitHub App installed are received. This EventSource should be inmanifests/system/argo-events/event-sources.Note: Check the GitHub Webhook Payloads for more information on the payload structure.