# Failed CI jobs (GitHub Actions)

> Report a failed workflow run to InfraInbox, and resolve the incident when a later run succeeds.

Web page: https://infrainbox.app/docs/cookbook/ci-pipeline/

**You'll get:** an incident when a GitHub Actions workflow fails, with a link back to the run, and automatic resolution the next time it passes.

## Before you start

An ingest key from a generic InfraInbox source, shaped like `iik_src_…`. Store it as a repository or organization secret, e.g. `INFRAINBOX_INGEST_KEY` (see [Events API: curl and scripts](https://infrainbox.app/docs/sources/events-api.md)).

## 1. Report a failure

Add a step that only runs when an earlier one in the job failed:

```yaml
- name: Notify InfraInbox on failure
  if: failure()
  run: |
    curl -fsS -m 10 \
      -H "Authorization: Bearer ${{ secrets.INFRAINBOX_INGEST_KEY }}" \
      -H "Content-Type: application/json" \
      -d '{
        "title": "${{ github.workflow }} failed on ${{ github.ref_name }}",
        "severity": "ERROR",
        "type": "ci.failed",
        "resource": "workflow:${{ github.workflow }}",
        "dedupKey": "gh:${{ github.repository }}:${{ github.workflow }}:${{ github.ref_name }}",
        "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
      }' \
      https://infrainbox.example.com/v1/events
```

## 2. Resolve it on the next success

Add a matching step that only runs when the job succeeded:

```yaml
- name: Resolve InfraInbox incident on success
  if: success()
  run: |
    curl -fsS -m 10 \
      -H "Authorization: Bearer ${{ secrets.INFRAINBOX_INGEST_KEY }}" \
      -H "Content-Type: application/json" \
      -d '{
        "title": "${{ github.workflow }} recovered on ${{ github.ref_name }}",
        "action": "resolve",
        "dedupKey": "gh:${{ github.repository }}:${{ github.workflow }}:${{ github.ref_name }}"
      }' \
      https://infrainbox.example.com/v1/events
```

Both steps use the same `dedupKey`, built from the repository, workflow and branch — that's what folds repeated failures into one incident and lets a later success close it.

## Check it works

- Push a commit that breaks the workflow: an incident appears, with a working link back to the failed run.
- Fix it and push again: the incident resolves on its own the moment the workflow passes.
