Trigger a GitHub Actions workflow¶
Iter8 provides a github
task that can be used in a performance test to send a repository_dispatch
event to trigger workflows in the default branch of a GitHub repository.
Example¶
In this example, you will run the Your first performance test but at the end of the performance test, Iter8 will trigger a workflow on GitHub.
In this simple example, the workflow will simply print out a test summary that it will receive with the repository_dispatch
. In a more sophisticated scenario, the workflow could, for example, read from the test summary and determine what to do next.
To summarize what will happen, you will create a new GitHub repository, add a workflow that will respond to the github
task, set up and run a performance test, and check if the workflow was triggered.
The github
task requires the name of a repository, the name of the owner, as well as an authentication token in order to send the repository_dispatch
. To see a full list of the github
task parameters, see here.
- Create a new repository on GitHub.
- Add the following workflow.
name: iter8 `github` task test
on:
repository_dispatch:
types: iter8
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- run: 'echo "payload: ${{ toJson(github.event.client_payload) }}"'
Note that this workflow has one job that will print out the client_payload
. The default github
task payload is configured with client_payload
set to .Report
, a summary of the performance test.
Also note that the on.repository_dispatch.types
is set to iter8
. The default github
task payload is configured with event_type
set to iter8
. This indicates that once the repository_dispatch
has been sent, only workflows on the default branch with on.repository_dispatch.types
set to iter8
will be triggered.
- Create a GitHub personal access token for the
token
parameter. - Ensure that you have a Kubernetes cluster and the
kubectl
CLI. You can create a local Kubernetes cluster using tools like Kind or Minikube. -
Install the Iter8 controller
Iter8 can be installed and configured to watch resources either in a single namespace (namespace-scoped) or in the whole cluster (cluster-scoped).
helm install --repo https://iter8-tools.github.io/iter8 --version 1.1 iter8 controller
helm install --repo https://iter8-tools.github.io/iter8 --version 1.1 iter8 controller \ --set clusterScoped=true
For additional install options, see Iter8 Installation.
-
Deploy the sample HTTP service in the Kubernetes cluster.
kubectl create deploy httpbin --image=kennethreitz/httpbin --port=80 kubectl expose deploy httpbin --port=80
- Launch the performance test using the
github
task with the appropriate values.helm upgrade --install \ --repo https://iter8-tools.github.io/iter8 --version 1.1 httpbin-test iter8 \ --set "tasks={http,github}" \ --set http.url=http://httpbin.default/get \ --set github.owner=<GitHub owner> \ --set github.repo=<GitHub repository> \ --set github.token=<GitHub token>
- Verify that the workflow has been triggered after the performance test has completed.
Some variations and extensions of the github
task
The default github
task payload sends a summary of the performance test.
In your workflow, you can read from the report and use that data for control flow or use snippets of that data in different actions. For example, you can check to see if there have been any task failures and take alternative actions.
You do not need to use the default github
task payload. You can provide your own payload by overriding the default of the payloadTemplateURL
.