---
title: WatchFor GitHub Action: maintenance windows, post-deploy checks, preview monitors
description: The official WatchFor GitHub Action mutes alerts while you deploy, checks the release from WatchFor's probe network and fails the job when something is down, and gives every preview environment its own monitor.
canonical: https://watchfor.io/docs/api/github-actions
---

# WatchFor GitHub Action: maintenance windows, post-deploy checks, preview monitors

The official WatchFor GitHub Action mutes alerts while you deploy, checks the release from WatchFor's probe network and fails the job when something is down, and gives every preview environment its own monitor.

Deploys page people for the wrong reason: the site restarts, a check
fails, the on-call phone rings for something you are doing on purpose.
And after the deploy, nobody looks until a customer does. The official
[WatchFor GitHub Action](https://github.com/watchfor-io/watchfor-action)
handles both ends of the pipeline:

| Command | What it does |
| --- | --- |
| `maintenance` | Opens a [maintenance window](/docs/monitors/maintenance) for the monitors a deploy touches and closes it when the job ends, including when the job fails or is cancelled |
| `maintenance-start` / `maintenance-end` | The same, across jobs |
| `check` | Runs your monitors now, runs [live checks](/docs/api/diagnostics) against a URL, writes a summary table to the job and fails it when something is down |
| `monitor` / `monitor-delete` | Creates or updates a monitor for a preview environment, and deletes it when the pull request closes |

Everything it does goes through the [REST API](/docs/api) with your API
key, so plan limits and permissions are the same as in the dashboard, and
every change appears in the [activity log](/docs/organization/activity-log)
with the client `watchfor-action`.

It runs on Linux and macOS runners, GitHub-hosted or your own (see
[macOS and iOS pipelines](#macos-and-ios-pipelines)). On
[GitLab CI](#gitlab-ci) the same jobs are a few `curl` calls.

## Setup

1. Create an API key with **read + write** scope under **Settings → API
   keys** ([Authentication](/docs/api/authentication)).
2. Add it to the repository (or a GitHub environment) as a secret named
   `WATCHFOR_API_KEY`.

GitHub does not pass secrets to workflows started from forks, so run these
steps on `push`, `workflow_dispatch` or pull requests from branches of the
same repository.

## Mute alerts while you deploy

```yaml
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7

      - uses: watchfor-io/watchfor-action@v1
        with:
          api-key: ${{ secrets.WATCHFOR_API_KEY }}
          command: maintenance
          tags: production      # or monitors: names or ids
          duration: 30m         # the longest it may stay open

      - run: ./deploy.sh
```

The window is open before the step finishes, so alerts are muted from the
first second of the deploy. Checks keep running and their results stay on
record; nobody is paged, and by default the time is left out of uptime and
SLA figures. The window is named `Deploy owner/repo@sha` and its
description links back to the workflow run.

When the job ends, the action closes the window, whether the job passed,
failed or was cancelled:

- `close: end` (default) ends the window now. Alerts resume at once, the
  uptime exclusion stops when the job ends, and the window stays on the
  Maintenance page. A window that is no longer running by then (its
  `duration` ran out, or someone ended it) is logged and the job goes on.
- `close: delete` removes it. Alerts resume at once, and the deploy's time
  counts in uptime like any other.

Versions before 1.1.0 switched the window off instead: alerts came back
within a minute, but the uptime exclusion ran to the planned end. Pin
`@v1` or `@v1.1.0` or later to get the new behaviour.

A window that closes within its first minute is removed in both cases.
Closed windows don't count toward the plan's limit on active and upcoming
windows.

## Check the release

```yaml
      - run: ./deploy.sh

      - uses: watchfor-io/watchfor-action@v1
        with:
          api-key: ${{ secrets.WATCHFOR_API_KEY }}
          command: check
          tags: production
          url: https://shop.example.com/health
          diagnostics: http-headers, ssl-check, tls-grade
          min-grade: B
```

For monitors, the action runs **check now**, waits for a check that
started after the step and judges it the way alerting does: a critical
alert rule failing on that check (an HTTP 500, a missing keyword) fails the
step, not only a site that does not answer; a failing warning rule, such
as a slow response, is a warning. Live checks run from WatchFor's probe
network against any URL, monitored or not; `diagnose-target` runs DNS,
TLS, HTTP and ping from up to three regions in one verdict (plans with
location selection).

The job summary gets one row per check (result, what was measured, the
location), and the step sets `result` (`passed`, `warning` or `failed`),
`failed` and `results` (JSON) as outputs. `fail-on` decides what fails the
job: `error` (default) for failures, `warning` to include warnings such as
a certificate expiring within 14 days, `never` to report only.

> **Check-now allowance**
>
> Each plan allows a number of check-now runs per monitor per hour. When a
> monitor's allowance is spent, the step waits for its next scheduled
> check instead, so a second deploy within the hour is still verified.
> `timeout` (default 300 seconds) bounds the wait. Live checks spend the
> same hourly allowance as the Toolbox.

## Preview environments

```yaml
on:
  pull_request:
    types: [opened, synchronize, reopened, closed]

jobs:
  preview-monitor:
    runs-on: ubuntu-latest
    steps:
      - if: github.event.action != 'closed'
        uses: watchfor-io/watchfor-action@v1
        with:
          api-key: ${{ secrets.WATCHFOR_API_KEY }}
          command: monitor
          name: preview-pr-${{ github.event.number }}
          url: https://pr-${{ github.event.number }}.preview.example.dev
          tags: preview
          config: '{"notificationGroupIds": []}'   # watch it, page nobody

      - if: github.event.action == 'closed'
        uses: watchfor-io/watchfor-action@v1
        with:
          api-key: ${{ secrets.WATCHFOR_API_KEY }}
          command: monitor-delete
          name: preview-pr-${{ github.event.number }}
          tags: preview
```

The monitor is found by its exact name, so new commits update the same
monitor instead of creating another, and only the fields the step states
are changed. `type` and `config` cover every [monitor type](/docs/api/monitor-types).
Without `locations`, a new monitor runs from one location in each of up to
three regions. `monitor-delete` with `tags` only deletes a monitor that
carries all of them, and a monitor that is already gone counts as done.

## macOS and iOS pipelines

The action is JavaScript that the Actions runner executes with its own
Node, so it needs nothing on the machine: no Homebrew packages, no shell
tools, no Xcode. It works the same on GitHub-hosted macOS runners
(`runs-on: macos-latest`) and on self-hosted Macs. The action's own CI runs
it on `macos-latest` for every change. A self-hosted runner needs a runner
version that runs `node24` actions.

### Check the API after a TestFlight upload

A new build is only as good as the backend it talks to. Check the API's
monitors and the endpoint the build calls right after the upload, and the
job fails before testers open a broken app. Move the step above the upload
to block the upload instead.

```yaml
jobs:
  beta:
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v7
      - run: bundle exec fastlane beta   # your lane: build, sign, upload

      - uses: watchfor-io/watchfor-action@v1
        with:
          api-key: ${{ secrets.WATCHFOR_API_KEY }}
          command: check
          tags: mobile-api
          url: https://api.example.com/v2/health
          diagnostics: api-tester, ssl-check
          expected-status: 200
```

`ssl-check` fails when the API's certificate does not validate, which is
exactly what the app's network calls run into, and warns 14 days before
it expires (`fail-on: warning` fails the job on that too).

### Mute alerts while the backend deploys

When the backend and the app ship from one workflow, wrap the backend
deploy in a maintenance window on a Linux runner and keep the Mac for the
build. The window closes when the `backend` job ends; the `ios` job checks
the same monitors afterwards.

```yaml
jobs:
  backend:
    runs-on: ubuntu-latest
    steps:
      - uses: watchfor-io/watchfor-action@v1
        with:
          api-key: ${{ secrets.WATCHFOR_API_KEY }}
          command: maintenance
          tags: mobile-api
          duration: 20m
      - run: ./deploy-backend.sh

  ios:
    needs: backend
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v7
      - run: bundle exec fastlane release
      - uses: watchfor-io/watchfor-action@v1
        with:
          api-key: ${{ secrets.WATCHFOR_API_KEY }}
          command: check
          tags: mobile-api
```

Signing certificates and provisioning profiles expire too, but they are
files, not endpoints, so no monitor can probe them. A scheduled job can
read their dates and report through a heartbeat:
[a script for it](/blog/monitor-macos-ios-ci-cd-pipelines#certificates-and-provisioning-profiles).

## Heartbeats for scheduled builds

A nightly build that does not run raises no error: the schedule was edited
away, the runner pool was empty, or GitHub turned the schedule off (it
disables scheduled workflows in a public repository after 60 days without
activity). A [heartbeat monitor](/docs/monitors/heartbeat) expects a ping
on a schedule and opens an incident when it does not come.

1. Create a heartbeat monitor in **Cron job** mode with the workflow's
   schedule, for example `0 2 * * *` in `UTC` (GitHub runs `schedule`
   triggers in UTC). GitHub can start scheduled runs late when it is busy,
   so make the grace period cover that plus the build's longest run.
2. Copy the ping URL from the monitor's **Setup** tab and store it as a
   secret, here `WATCHFOR_NIGHTLY_PING_URL`. It needs no API key; anyone
   with the URL can ping the monitor.
3. Ping at the start and at the end of the job:

```yaml
on:
  schedule:
    - cron: "0 2 * * *"

jobs:
  nightly:
    runs-on: macos-latest
    env:
      PING_URL: ${{ secrets.WATCHFOR_NIGHTLY_PING_URL }}
    steps:
      - run: curl -fsS --retry 3 "$PING_URL/start?rid=$GITHUB_RUN_ID"
      - uses: actions/checkout@v7
      - run: ./scripts/nightly.sh

      - if: ${{ !cancelled() }}
        env:
          JOB_STATUS: ${{ job.status }}
        run: |
          [ "$JOB_STATUS" = success ] && SIGNAL="" || SIGNAL=/fail
          curl -fsS --retry 3 --data-raw "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
            "$PING_URL$SIGNAL?rid=$GITHUB_RUN_ID"
```

A run that never starts opens a critical **Missed schedule** incident; a
failed run sends `/fail` and opens a **Run failed** warning instead. The
start and finish pings share a run id, so the monitor charts how long each
build took, and the body (the run's link) shows with the ping on the
**Pings** tab. A cancelled run sends nothing; if no other run pings in
time, the missed schedule alerts.

### The heartbeat command

Since version 1.1.0, `command: heartbeat` replaces both `curl` steps:

```yaml
      - uses: watchfor-io/watchfor-action@v1
        with:
          command: heartbeat
          ping-url: ${{ secrets.WATCHFOR_NIGHTLY_PING_URL }}
          status: start

      # … the build …

      - if: always()
        uses: watchfor-io/watchfor-action@v1
        with:
          command: heartbeat
          ping-url: ${{ secrets.WATCHFOR_NIGHTLY_PING_URL }}
          status: ${{ job.status }}
```

| Input | Default | Meaning |
| --- | --- | --- |
| `ping-url` | required | The ping URL from the Setup tab, or only its token; no `api-key` needed |
| `status` | `success` | `success`, `fail`, `start` or an exit code `0`-`255`; `job.status` values work as they are (`failure` sends `/fail`, `cancelled` sends nothing) |
| `run-id` | the run id and attempt | Pairs a `start` with its finish, so the duration is measured |
| `description` | the workflow, commit and run link | Stored with the ping, up to 10 KB |
| `fail-on` | `error` | `never` turns an undelivered ping into a warning |

The ping URL is masked in the log and never printed. Network errors, rate
limits and server errors are retried with backoff, and the job summary
says which ping was recorded.

## Inputs at a glance

| Input | Default | Meaning |
| --- | --- | --- |
| `api-key` | required | Read + write API key, from a secret |
| `command` | required | One of the commands above |
| `monitors` / `tags` | | Which monitors: ids or exact names, and tags |
| `name` | | Window name, or the monitor's exact name |
| `duration` | `30m` | Longest the window stays open (5 minutes to 30 days) |
| `close` | `end` | `end` or `delete` |
| `exclude-from-uptime` | `true` | Leave the window's time out of uptime and SLA |
| `url` | | Live-check target; the preview monitor's target |
| `diagnostics` | | Live checks to run, e.g. `http-headers, ssl-check, dns-lookup` |
| `expected-status` | `200-399` | Status codes `http-headers` and `api-tester` accept |
| `min-grade` | | Lowest acceptable [WatchFor Grade](/grades) for graded checks |
| `fail-on` | `error` | `error`, `warning` or `never` |
| `type`, `interval`, `locations`, `config` | `http`, type default | Preview monitor settings |

Every input and output, with more examples:
[the action's README](https://github.com/watchfor-io/watchfor-action#readme).

## Behaviour you can rely on

- The API key is masked in the job log before anything runs, and only
  sent to WatchFor as a bearer token.
- Rate limits and server errors are retried with backoff; every write
  carries an `Idempotency-Key`, so a retry never opens a second window or
  creates a second monitor.
- An unknown monitor name or tag fails the step instead of quietly
  checking nothing.

## GitLab CI

The action is GitHub-only; on GitLab the same three jobs are `curl` and
`jq`. They run on Linux and on macOS runners (GitLab's own or a Mac
runner registered with your project): the `date` call works with both GNU
and BSD `date`. Add `WATCHFOR_API_KEY` (read + write) and the ping URL as
CI/CD variables, and install `jq` on images that lack it
(`brew install jq` on a Mac).

### Maintenance window around a deploy

```yaml
variables:
  WATCHFOR: https://watchfor.io/api/v1

deploy:
  stage: deploy
  script:
    - |
      STARTS=$(date -u -v+10S +%FT%TZ 2>/dev/null || date -u -d '+10 seconds' +%FT%TZ)
      curl -fsS -X POST "$WATCHFOR/maintenance-windows" \
        -H "Authorization: Bearer $WATCHFOR_API_KEY" -H "Content-Type: application/json" \
        -H "Idempotency-Key: deploy-$CI_JOB_ID" \
        -d "{\"name\":\"Deploy $CI_PROJECT_PATH@$CI_COMMIT_SHORT_SHA\",\"startsAt\":\"$STARTS\",\"durationMinutes\":30,\"monitorTags\":[\"production\"]}" \
        | jq -r .id > window.id
    - ./deploy.sh
  after_script:
    - |
      curl -fsS -X POST "$WATCHFOR/maintenance-windows/$(cat window.id)/complete" \
        -H "Authorization: Bearer $WATCHFOR_API_KEY" \
        -H "Idempotency-Key: deploy-end-$CI_JOB_ID"
```

The window starts 10 seconds ahead so it is armed at once, and
`after_script` ends it whether the deploy passed or failed: alerts resume
at once and the uptime exclusion stops there. If the window already ended
(its 30 minutes ran out), the call gets a 409 and nothing changes.

### Check the release

```yaml
verify:
  stage: verify
  script:
    # A live check from WatchFor's probe network: does the URL answer 2xx/3xx?
    - |
      curl -fsS -X POST "$WATCHFOR/diagnostics/http-headers" \
        -H "Authorization: Bearer $WATCHFOR_API_KEY" -H "Content-Type: application/json" \
        -d '{"target": "https://api.example.com/health"}' > run.json
      jq '{success, error, status: (.result.response.status_code // .result.metrics["http.status_code"]), location: .location.name}' run.json
      jq -e '.success and ((.result.response.status_code // .result.metrics["http.status_code"]) as $s | $s >= 200 and $s < 400)' run.json > /dev/null
    # Check now on one monitor, wait for that check, then read its status
    - |
      SINCE=$(( $(date -u +%s) - 1 ))
      curl -sS -o /dev/null -w 'check now: HTTP %{http_code}\n' -X POST "$WATCHFOR/monitors/$MONITOR_ID/check-now" \
        -H "Authorization: Bearer $WATCHFOR_API_KEY" -H "Idempotency-Key: verify-$CI_JOB_ID"
      for i in $(seq 1 30); do
        sleep 10
        LAST=$(curl -fsS "$WATCHFOR/monitors/$MONITOR_ID/checks?hours=1&limit=1" -H "Authorization: Bearer $WATCHFOR_API_KEY" \
          | jq -r '.data[0].timestamp // empty | sub("\\.[0-9]+Z$"; "Z") | fromdateiso8601')
        [ -n "$LAST" ] && [ "$LAST" -ge "$SINCE" ] && break
      done
      [ -n "$LAST" ] && [ "$LAST" -ge "$SINCE" ] || { echo "no check within 5 minutes"; exit 1; }
      sleep 5
      REASON=$(curl -fsS "$WATCHFOR/monitors/$MONITOR_ID" -H "Authorization: Bearer $WATCHFOR_API_KEY" | jq -r .status_reason)
      echo "status_reason: $REASON"
      [ "$REASON" = ok ]
```

- `success: false` on a live check is an answer, not an error: the check
  ran and found the problem, so the job fails on it.
- A check now answers `429` once the monitor's hourly allowance is spent;
  the loop then waits for the next scheduled check, so keep the loop longer
  than the monitor's interval.
- `status_reason` other than `ok` means an alert rule is failing on that
  check or an incident is open (the values are listed under
  [Monitors](/docs/api/monitors)). The action does the same and also tells
  warnings from failures.

### Heartbeat for scheduled pipelines

```yaml
nightly:
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule"
  tags: [macos]              # your macOS runner's tag, if the build needs a Mac
  script:
    - curl -fsS --retry 3 "$WATCHFOR_PING_URL/start?rid=$CI_PIPELINE_ID"
    - ./scripts/nightly.sh
  after_script:
    - |
      case "$CI_JOB_STATUS" in
        success) curl -fsS --retry 3 --data-raw "$CI_PIPELINE_URL" "$WATCHFOR_PING_URL?rid=$CI_PIPELINE_ID" ;;
        failed) curl -fsS --retry 3 --data-raw "$CI_PIPELINE_URL" "$WATCHFOR_PING_URL/fail?rid=$CI_PIPELINE_ID" ;;
      esac                   # canceled: no ping
```

Set the monitor's cron expression and timezone to the pipeline schedule's.
A ping needs no API key, only the URL.

### Other CI systems

Jenkins, CircleCI, Bitrise and the rest make the same calls with `curl`
or an [SDK](/docs/api#sdks--cli). See
[Maintenance windows](/docs/api/maintenance-windows),
[Checks and uptime](/docs/api/checks-uptime),
[Live diagnostics](/docs/api/diagnostics) and
[Heartbeat & cron jobs](/docs/monitors/heartbeat).

---

Canonical page: https://watchfor.io/docs/api/github-actions · All docs: https://watchfor.io/docs · Site guide: https://watchfor.io/llms.txt
