Skip to content

Write reliable service workflows

Zekt connects workflows: it delivers events, starts orchestration steps, and reports how the runs ended. The work itself happens in your workflow code, and Zekt passes on the result GitHub reports for it:

Zekt doesn’t look inside the run. A workflow that hides an error reports success, and a workflow that can’t handle being run twice turns a harmless re-send into a problem. These guidelines help you build workflows that hold up.

For working examples, see the provider workflow, the consumer workflow, a consumer service and an orchestration.

The event type is what connects the two sides. The provider sets it with the Zekt Action’s event-type, and the receiving workflow lists it in on.repository_dispatch.types.

# Provider (or subscriber) workflow
- uses: zekt-dev-org/zekt-action@v3
with:
event-type: invoice-approved
# Receiving workflow
on:
repository_dispatch:
types: [invoice-approved] # character for character the same
  • Name it after what happened, and be specific. invoice-approved or image-scan-requested says what the event is. deploy, build, done or test could mean anything, and another workflow may already use them. A service’s event type uses letters, numbers and hyphens, up to 50 characters.
  • Know what else listens in the receiving repository. GitHub starts every workflow in the repository whose types: includes the event type. A workflow with repository_dispatch and no types: at all runs for every event the repository receives, every Zekt event included. A generic name can therefore start a workflow you didn’t mean to start.
  • Keep both sides in step. If the names differ, no run starts, and nothing errors on either side. Agree on the name, and change it on both sides together.
  • Send the event type your service declares. Zekt doesn’t enforce a provider service’s declared Dispatch Event Type on broadcasts: subscribers receive the type the Zekt Action sent. If the two differ, subscribers filtering on the declared type don’t run, and the provider console flags the service with an event type mismatch warning.
  • Orchestration steps use the declared type. A service called as an orchestration step receives the step under its declared event type, or zekt-workflow-completed if it declares none. Its workflow must listen for that type. This applies to consumer services too.
  • Consumer services fired by subscribers: you receive the event type the subscriber’s workflow sent, not the one the service declares. Tell subscribers which type to send. See Offer a consumer service.
  • Have exactly one workflow listen for a service’s event type in the service’s repository. Zekt ties an orchestration step to one run, and two workflows on the same type do the work twice.
  • Be careful with zekt-workflow-completed. An event arrives under this name when the provider didn’t use the Zekt Action, or when its payload expired before the run finished (Payload rules). It’s the same name for every service and carries no payload, so a workflow listening for it can’t tell from the type what it’s receiving.
  • Test the trigger with your real event type. The Event Simulator defaults to zekt-test. Set it to the type you’ll actually receive.

If a consumer workflow didn’t run, see Troubleshooting.

We strongly recommend making your workflows idempotent: running them again with the same input leads to the same end state, and reports the same result. This matters most for a workflow that does work on request, such as a consumer service or an orchestration step.

Your workflow will run more than once for the same event sooner or later:

  • delivery is at-least-once, so an event can occasionally arrive twice;
  • consumers can Retry a failed delivery, and providers can Replay an event with Zekt Analytics;
  • people re-run workflows from GitHub’s Actions tab. A re-run of the sending workflow is a new event: for a consumer service fired by subscribers, it carries a new correlationId;
  • an orchestration has no retry or resume. To recover from a failed step, you submit the orchestration again, and that new orchestration runs every step again, including the steps that completed last time. Re-running the workflow that submitted it does the same.

A workflow that isn’t idempotent gets the second run wrong, in one of two ways:

  • It fails although nothing is wrong. “Create the resource group” fails because the group already exists, so a retry reports a failure for work that was in fact done.
  • It succeeds but does the work twice. A second invoice line, a second notification, a counter incremented twice. Everything reports success, and the problem surfaces later.

Tools that describe a desired state, such as Terraform, Bicep, Pulumi, Kubernetes manifests or Ansible, are idempotent by design: applying the same definition again changes nothing. They’re a good fit for infrastructure work behind a service. Keep their state in a shared, locked backend, so two runs never work from different copies.

With Bash, PowerShell, Python or any other imperative code, you make the script idempotent yourself:

Instead ofDo
Create, and fail if it existsCreate it if it’s missing, or use a create-or-update call.
Append a row or send a message on every runRecord it under the event’s ID, and skip it if it’s already there.
Random or time-based namesNames derived from the input, so a second run finds the first run’s result.
Increment a valueSet the value.
Delete, and fail if it’s goneDelete it if it’s there. “Not found” means done.

For example, a consumer workflow that publishes a release once per version:

permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Create the release once
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ github.event.client_payload.zekt.payload.version }}
run: |
set -euo pipefail
if gh release view "v$VERSION" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "Release v$VERSION already exists. Nothing to do."
else
gh release create "v$VERSION" --repo "$GITHUB_REPOSITORY" --generate-notes
fi

To recognise work you’ve already done:

  • Events (from a provider, or fired into a consumer service by a subscriber): use zekt.correlationId together with zekt.replayId, never dispatch_id. See Duplicates and ordering.
  • Orchestration steps: Zekt sends each step at most once. _zekt.orchestration.executionId plus stepId identify one step of one orchestration. A resubmitted orchestration has a new executionId, so its steps look new.

Either way, a repeat with a new ID is still a repeat of the same work. An ID check only helps when the ID is the same, so make the work itself safe to repeat.

Runs that overlap, and events out of order

Section titled “Runs that overlap, and events out of order”

Zekt gives no ordering guarantee between events, and two runs can overlap.

  • Use GitHub’s concurrency so that runs changing the same thing wait for each other:

    concurrency:
    group: deploy-${{ github.event.client_payload.zekt.payload.environment }}
    cancel-in-progress: false
  • Don’t assume the event that arrives last is the newest. If order matters, put a version or timestamp in the payload, and ignore an event older than the state you already have.

Zekt records how GitHub says the run ended and passes that on. It doesn’t re-send, retry or notify anyone because a receiving run failed: Zekt’s automatic retries and the Retry action only cover sends that GitHub refused. So make sure the run’s ending is true.

In an orchestration, the run’s conclusion decides the step:

  • Only success completes a step. Any other conclusion, including cancelled, skipped and neutral, fails it, and a failed step ends the orchestration.
  • Outputs a run reported before failing aren’t passed to later steps.
  • A step is final once GitHub reports its run’s conclusion. Re-running that run from the Actions tab changes nothing: Zekt ignores the re-run’s result and outputs. To recover, submit the orchestration again (see above).

In your workflow:

  • Stop on the first error. Start Bash scripts with set -euo pipefail. In PowerShell, set $ErrorActionPreference = 'Stop', and check $LASTEXITCODE after native commands, because their failures don’t stop a PowerShell script on their own. In Python, let exceptions end the script with a non-zero exit code.
  • Don’t swallow failures. continue-on-error: true and || true make the run succeed, and that success is what Zekt passes on.
  • Check the input before you act. Fail early, with a message that says which field is missing or wrong, rather than halfway through the work.
  • Set timeout-minutes on your jobs. Without it, GitHub lets a hanging job run for up to six hours before cancelling it, and anything waiting for your run waits too. An orchestration’s timeout_minutes doesn’t help here: it only limits how long Zekt waits for a step’s run to start. Once the run has started, the step waits for GitHub’s result.
  • Consumers: check the sender’s result. You’re triggered whatever the provider’s run concluded. Read client_payload.workflow_run.conclusion if you should only act on success.
  • Consumer services: report outputs last. A run that reports outputs and then fails still fails the step. When the action is called several times, the last call wins. Report outputs once, at the end, when the work has succeeded.

Publish a schema for what your service takes and returns, so the people using it know what to send (fields, types, shape) and what they’ll get back:

  • a broadcast schema for the payload a provider service sends;
  • an input schema and an output schema for a consumer service.

Enforcing a schema stops payloads that don’t match. Still validate in your workflow, because a schema doesn’t catch everything:

  • payloads aren’t checked when enforcement is off or the payload is Shield-encrypted;
  • a mismatch with an output schema only warns, and provider services have no output schema;
  • a schema describes the shape, not whether a value makes sense for your service.

When the shape changes, publish a new version. Zekt refuses a breaking change within the same major version, and subscribers choose which versions they follow. See Breaking changes.

Keep secrets and customer values out of the repository

Section titled “Keep secrets and customer values out of the repository”

Values that are specific to you or your customers, such as tenant or subscription IDs, client secrets, keys, connection strings and passwords, don’t belong in the repository.

  • Store them in GitHub secrets (per repository, organization or environment), or in your cloud provider’s vault, and read them at run time.
  • Prefer short-lived credentials. Many cloud providers accept GitHub’s OpenID Connect tokens, so you don’t need to store a long-lived key at all.
  • Keep them out of logs. GitHub masks the secrets it knows, but not values you derive from them. Mask those with ::add-mask::, and don’t print whole payloads that might contain them.

The payload comes from another workflow, often in another account.

  • Pass values through env. Writing ${{ github.event.client_payload… }} straight into a run: script lets a crafted value break or inject into the script. All the examples in these docs use env.
  • Don’t rely on identity fields in the payload. A sender can put any value there. See What your repository receives.
  • Give the job only the permissions it needs. Set permissions: explicitly in every workflow.
  • The event type is specific, identical on both sides, and the one the service declares.
  • Exactly one workflow in the receiving repository listens for it.
  • Running the workflow twice with the same event gives the same result.
  • Runs that change the same thing don’t overlap, and an old event can’t overwrite newer state.
  • Errors end the run with a failure, and nothing swallows them.
  • Jobs have a timeout-minutes.
  • The service has a published schema, and the workflow still validates its input.
  • No secret or customer-specific value is committed, logged, or sent in a payload.
  • Payload values reach scripts through env, and permissions: is set.