# Deploy from GitHub Actions

> A GitHub Actions workflow can push your repository to staging or a preview over SSH, wait for the build, and promote to live after approval. With examples.

Source: https://docs.wpwaterfall.com/github-actions

A GitHub Actions workflow can send your code to WP Waterfall on every push: it pushes to staging or a preview over SSH, waits for the build, and promotes to live. Live code is read only, so a workflow never writes to live. It asks WP Waterfall to promote what staging already runs. There is no SSH password, no rsync, and no IP allowlist.

The workflows use plain steps: `actions/checkout`, the community action `webfactory/ssh-agent` (MIT license) to load an SSH key, `git push`, and `curl` calls to the public API.

## Which path should I use?

| Path | How the code reaches WP Waterfall | Use it when |
|---|---|---|
| A. Push from the workflow | The workflow pushes the commit to staging (or a preview) over SSH. | You want one workflow to build, push, and promote. |
| B. Connect the repository | WP Waterfall pulls from GitHub with a read only deploy key and a webhook. The workflow only waits and promotes. | You want pushes to GitHub to reach staging and every preview with no key in a workflow. See [Connect GitHub, GitLab, or Bitbucket](https://docs.wpwaterfall.com/connect-github). |

WP Waterfall runs the `build` steps from `wpwaterfall.yml` on its own servers, so you push source and do not commit `vendor/` or compiled files. See [wpwaterfall.yml reference](https://docs.wpwaterfall.com/code/wpwaterfall-yml).

## What do I need?

1. A real site (with a site license), **live launched**, and staging in **Git mode**. Until you launch live, the promote step fails with `live_not_launched`. Launch it once from the site's Info tab, or with `launch_live` in an assistant.
2. An API key with the `sites:read` and `sites:write` scopes, made by a person whose role can deploy code (Owner, Admin, or Developer). Give it an expiry, and leave its IP allowlist empty, because GitHub runner addresses change. See [Create an API key](https://docs.wpwaterfall.com/developers/create-an-api-key) and [API keys and scopes](https://docs.wpwaterfall.com/api-keys-and-scopes). Do not tick **Allow deleting and resetting sites**: the workflow never needs it.
3. The site id and the staging id, from `GET /v1/sites` and `GET /v1/sites/{id}/environments`, or from `list_environments` in an assistant.
4. A GitHub repository whose history contains staging's history (see step 1 of path A).

These names are the same in every example:

| Name | Kind | Value |
|---|---|---|
| `WPWATERFALL_API_KEY` | Secret | The API key. |
| `WPWATERFALL_SSH_KEY` | Secret | The private SSH key (path A only). |
| `WPWATERFALL_GIT_URL` | Secret | The SSH address of the environment, `ssh://USER@HOST:PORT/srv/git/site.git` (path A only). |
| `WPWATERFALL_KNOWN_HOSTS` | Secret | The host key line of that address (path A only). |
| `WPWATERFALL_SITE_ID` | Variable | The site id. |
| `WPWATERFALL_STAGING_ID` | Variable | The staging environment id. |

Add them under **Settings**, **Secrets and variables**, **Actions**, for example with `gh secret set WPWATERFALL_API_KEY`. Never write a key into a workflow file, a commit, or a log.

A workflow on a private repository uses your GitHub Actions minutes. If a run stops at once with "recent account payments have failed or your spending limit needs to be increased", fix the billing settings of your GitHub account and run it again. The first run of the workflow below, checked on 2026-10-16 against a real site, took 21 seconds for the push and the wait, and 14 seconds for the promote.

## Path A: how do I push from the workflow?

### 1. Seed the repository from the site

WP Waterfall refuses a push that rewrites history, so the GitHub repository must start from the site's own repository. Clone the site (see [Git access](https://docs.wpwaterfall.com/git-access#how-do-i-clone-and-push)), then push that clone to a new GitHub repository.

```bash
git clone ssh://USER@HOST:PORT/srv/git/site.git my-site
cd my-site
git remote add github git@github.com:acme/my-site.git
git push github master
```

From now on, work in the GitHub repository.

### 2. Make a deploy key for staging

Make a key that only CI uses, and keep it out of your own account:

```bash
ssh-keygen -t ed25519 -N "" -C "github-actions" -f deploy_key
```

Save the contents of `deploy_key` as the secret `WPWATERFALL_SSH_KEY`, then delete the file. Save the public key `deploy_key.pub` on the staging environment, so the key can push there and nowhere else:

```bash
curl -sS -X POST "https://api.wpwaterfall.com/v1/environments/$STAGING_ID/ssh-keys" \
  -H "Authorization: Bearer $WPWATERFALL_API_KEY" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --rawfile key deploy_key.pub '{name: "github-actions", public_key: $key}')"
```

Save the staging address (`wpwaterfall_remote.ssh.url` from `GET /v1/environments/{id}/git`) as the secret `WPWATERFALL_GIT_URL`. A key on a team member's account also works, but it acts as that person on every environment they can push to. See [Git access](https://docs.wpwaterfall.com/git-access).

### 3. Pin the host key

The workflow checks the host key and never turns checking off. Get the key line once, check its fingerprint against the one on the **Info** tab of the environment, and save the line as the secret `WPWATERFALL_KNOWN_HOSTS`:

```bash
ssh-keyscan -p PORT HOST > known_hosts
ssh-keygen -lf known_hosts
```

### 4. Add the workflow

Save this as `.github/workflows/deploy.yml`.

```yaml
name: Deploy to WP Waterfall

# Push every commit on master to staging over SSH, wait for the build, then promote to live.
# The key is loaded with webfactory/ssh-agent, and the host key comes from a secret, so the host is checked.
# The promote job uses the GitHub environment "production". Add required reviewers to that
# environment and a person approves every promote. Live code is never written by this workflow.
on:
  push:
    branches: [master]

permissions:
  contents: read

concurrency:
  group: wpwaterfall-deploy
  cancel-in-progress: false

jobs:
  staging:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Load the SSH key
        uses: webfactory/ssh-agent@v0.10.0
        with:
          ssh-private-key: ${{ secrets.WPWATERFALL_SSH_KEY }}

      - name: Push to staging
        env:
          GIT_URL: ${{ secrets.WPWATERFALL_GIT_URL }}
          KNOWN_HOSTS: ${{ secrets.WPWATERFALL_KNOWN_HOSTS }}
        run: |
          mkdir -p ~/.ssh
          echo "$KNOWN_HOSTS" >> ~/.ssh/known_hosts
          git push "$GIT_URL" HEAD:refs/heads/master

      - name: Wait for staging to run this commit
        env:
          API_KEY: ${{ secrets.WPWATERFALL_API_KEY }}
          SITE_ID: ${{ vars.WPWATERFALL_SITE_ID }}
          ENV_ID: ${{ vars.WPWATERFALL_STAGING_ID }}
        run: |
          API="https://api.wpwaterfall.com/v1"
          for _ in $(seq 1 90); do
            releases=$(curl -fsS -H "Authorization: Bearer $API_KEY" "$API/sites/$SITE_ID/releases?environment_id=$ENV_ID&limit=20")
            state=$(jq -r --arg sha "$GITHUB_SHA" '[.data[] | select(.sha == $sha)][0].status // "waiting"' <<<"$releases")
            [ "$state" = active ] && exit 0
            case "$state" in failed|superseded) echo "The release of $GITHUB_SHA is $state."; exit 1;; esac
            builds=$(curl -fsS -H "Authorization: Bearer $API_KEY" "$API/environments/$ENV_ID/builds?limit=20")
            build=$(jq -r --arg sha "$GITHUB_SHA" '[.data[] | select(.sha == $sha)][0].status // "waiting"' <<<"$builds")
            case "$build" in failed|cancelled) echo "The build ended as $build."; exit 1;; esac
            sleep 10
          done
          echo "Staging does not run $GITHUB_SHA after 15 minutes."
          exit 1

  promote:
    needs: staging
    runs-on: ubuntu-latest
    environment: production
    steps:
      - name: Promote staging to live
        env:
          API_KEY: ${{ secrets.WPWATERFALL_API_KEY }}
          SITE_ID: ${{ vars.WPWATERFALL_SITE_ID }}
        run: |
          API="https://api.wpwaterfall.com/v1"
          body=$(jq -n --arg sha "$GITHUB_SHA" --arg note "Release from GitHub run $GITHUB_RUN_NUMBER" '{confirm: true, sha: $sha, note: $note}')
          curl -sS --fail-with-body -X POST "$API/sites/$SITE_ID/promote" \
            -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
            -H "Idempotency-Key: $GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT-promote" \
            -d "$body" -o job.json || { cat job.json; exit 1; }
          job=$(jq -r .id job.json)
          for _ in $(seq 1 90); do
            state=$(curl -fsS -H "Authorization: Bearer $API_KEY" "$API/jobs/$job" | jq -r .status)
            case "$state" in
              succeeded) exit 0;;
              failed|cancelled) echo "The promote ended as $state."; exit 1;;
            esac
            sleep 10
          done
          echo "The promote is still running after 15 minutes."
          exit 1
```

Keep `fetch-depth: 0`, because a shallow clone cannot push. The `sha` in the promote makes it safe: if staging runs a different commit by then, WP Waterfall refuses with `staging_changed` and live stays as it is.

### 5. Ask for an approval before live

Create a GitHub environment named `production` under **Settings**, **Environments**, and add **Required reviewers**. The `promote` job then waits for approval. Remove `environment: production` to promote on every push.

### Can CI that cannot hold an SSH key use a token?

Yes. Make a Git token for staging with `POST /v1/environments/{id}/git/tokens` (see [Git access](https://docs.wpwaterfall.com/git-access)), save its `username`, `token`, and `clone_url` as secrets, and replace the two SSH steps with this one:

```bash
AUTH="$(printf '%s:%s' "$GIT_USER" "$GIT_TOKEN" | base64 -w0)"
echo "::add-mask::$AUTH"
git -c "http.extraheader=Authorization: Basic $AUTH" push "$GIT_URL" HEAD:refs/heads/master
```

Set `GIT_URL`, `GIT_USER`, and `GIT_TOKEN` from secrets under `env:`, as the SSH step sets `GIT_URL`.

## Path B: how do I promote from Actions with a connected repository?

Connect the repository first (see [Connect GitHub, GitLab, or Bitbucket](https://docs.wpwaterfall.com/connect-github)). WP Waterfall then pulls every push into staging by webhook, and the workflow needs only the API key and the two ids. Use the workflow from path A with these changes:

- Set `on.push.branches` to the **Staging branch** on the card.
- Remove the checkout, SSH, and push steps and the three SSH secrets. The `staging` job keeps only the wait step, and the `promote` job stays as it is.
- Do not call `POST /v1/environments/{id}/git/pull` beside the webhook: a second pull answers `job_already_running` while one is open. Use it only for a repository without a webhook.

While a repository is connected, pushes to the WP Waterfall remote are refused, so pick one path.

The finished workflow:

```yaml
name: Promote after WP Waterfall pulls

# Use this when the repository is connected under Environments, External repository. The webhook
# pulls each push into staging, so this workflow only waits for the build and then promotes.
# The promote job uses the GitHub environment "production". Add required reviewers to that
# environment and a person approves every promote. Live code is never written by this workflow.
on:
  push:
    branches: [main]

permissions:
  contents: read

concurrency:
  group: wpwaterfall-deploy
  cancel-in-progress: false

jobs:
  staging:
    runs-on: ubuntu-latest
    steps:
      - name: Wait for staging to run this commit
        env:
          API_KEY: ${{ secrets.WPWATERFALL_API_KEY }}
          SITE_ID: ${{ vars.WPWATERFALL_SITE_ID }}
          ENV_ID: ${{ vars.WPWATERFALL_STAGING_ID }}
        run: |
          API="https://api.wpwaterfall.com/v1"
          for _ in $(seq 1 90); do
            releases=$(curl -fsS -H "Authorization: Bearer $API_KEY" "$API/sites/$SITE_ID/releases?environment_id=$ENV_ID&limit=20")
            state=$(jq -r --arg sha "$GITHUB_SHA" '[.data[] | select(.sha == $sha)][0].status // "waiting"' <<<"$releases")
            [ "$state" = active ] && exit 0
            case "$state" in failed|superseded) echo "The release of $GITHUB_SHA is $state."; exit 1;; esac
            builds=$(curl -fsS -H "Authorization: Bearer $API_KEY" "$API/environments/$ENV_ID/builds?limit=20")
            build=$(jq -r --arg sha "$GITHUB_SHA" '[.data[] | select(.sha == $sha)][0].status // "waiting"' <<<"$builds")
            case "$build" in failed|cancelled) echo "The build ended as $build."; exit 1;; esac
            sleep 10
          done
          echo "Staging does not run $GITHUB_SHA after 15 minutes."
          exit 1

  promote:
    needs: staging
    runs-on: ubuntu-latest
    environment: production
    steps:
      - name: Promote staging to live
        env:
          API_KEY: ${{ secrets.WPWATERFALL_API_KEY }}
          SITE_ID: ${{ vars.WPWATERFALL_SITE_ID }}
        run: |
          API="https://api.wpwaterfall.com/v1"
          body=$(jq -n --arg sha "$GITHUB_SHA" --arg note "Release from GitHub run $GITHUB_RUN_NUMBER" '{confirm: true, sha: $sha, note: $note}')
          curl -sS --fail-with-body -X POST "$API/sites/$SITE_ID/promote" \
            -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
            -H "Idempotency-Key: $GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT-promote" \
            -d "$body" -o job.json || { cat job.json; exit 1; }
          job=$(jq -r .id job.json)
          for _ in $(seq 1 90); do
            state=$(curl -fsS -H "Authorization: Bearer $API_KEY" "$API/jobs/$job" | jq -r .status)
            case "$state" in
              succeeded) exit 0;;
              failed|cancelled) echo "The promote ended as $state."; exit 1;;
            esac
            sleep 10
          done
          echo "The promote is still running after 15 minutes."
          exit 1
```

## How do I deploy a preview?

A preview follows the branch with its own name. With path B, a push to `qa` updates the preview `qa` by itself, and **Create a preview environment when a new remote branch is pushed** can create one. With path A, create the preview in WP Waterfall once, save a deploy key on it, and use this workflow, which reads its secrets and variables from a GitHub environment named `qa`.

```yaml
name: Deploy the qa branch to WP Waterfall

# Push the qa branch to the WP Waterfall preview environment named qa over SSH, then wait for the build.
# The preview environment must exist first. Create it in WP Waterfall, then save an SSH key on it.
# The GitHub environment "qa" holds that preview's own secrets and variables, so the names below
# stay the same for every preview. A preview never touches live.
on:
  push:
    branches: [qa]

permissions:
  contents: read

concurrency:
  group: wpwaterfall-qa
  cancel-in-progress: false

jobs:
  preview:
    runs-on: ubuntu-latest
    environment: qa
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Load the SSH key
        uses: webfactory/ssh-agent@v0.10.0
        with:
          ssh-private-key: ${{ secrets.WPWATERFALL_SSH_KEY }}

      - name: Push to the qa preview environment
        env:
          GIT_URL: ${{ secrets.WPWATERFALL_GIT_URL }}
          KNOWN_HOSTS: ${{ secrets.WPWATERFALL_KNOWN_HOSTS }}
        run: |
          mkdir -p ~/.ssh
          echo "$KNOWN_HOSTS" >> ~/.ssh/known_hosts
          git push "$GIT_URL" HEAD:refs/heads/qa

      - name: Wait for the preview to run this commit
        env:
          API_KEY: ${{ secrets.WPWATERFALL_API_KEY }}
          SITE_ID: ${{ vars.WPWATERFALL_SITE_ID }}
          ENV_ID: ${{ vars.WPWATERFALL_ENVIRONMENT_ID }}
        run: |
          API="https://api.wpwaterfall.com/v1"
          for _ in $(seq 1 90); do
            releases=$(curl -fsS -H "Authorization: Bearer $API_KEY" "$API/sites/$SITE_ID/releases?environment_id=$ENV_ID&limit=20")
            state=$(jq -r --arg sha "$GITHUB_SHA" '[.data[] | select(.sha == $sha)][0].status // "waiting"' <<<"$releases")
            [ "$state" = active ] && exit 0
            case "$state" in failed|superseded) echo "The release of $GITHUB_SHA is $state."; exit 1;; esac
            builds=$(curl -fsS -H "Authorization: Bearer $API_KEY" "$API/environments/$ENV_ID/builds?limit=20")
            build=$(jq -r --arg sha "$GITHUB_SHA" '[.data[] | select(.sha == $sha)][0].status // "waiting"' <<<"$builds")
            case "$build" in failed|cancelled) echo "The build ended as $build."; exit 1;; esac
            sleep 10
          done
          echo "The preview does not run $GITHUB_SHA after 15 minutes."
          exit 1
```

A preview cannot be promoted to live. Merge its branch into the default branch, let staging take it, and promote from there.

## What do the API steps do?

| Step | API calls | Waits for |
|---|---|---|
| Wait for the release | `GET /v1/sites/{id}/releases?environment_id=ID` and `GET /v1/environments/{id}/builds` | An active release of the commit. Fails when its release or build failed, or a newer release replaced it. |
| Promote | `POST /v1/sites/{id}/promote` with `confirm: true`, then `GET /v1/jobs/{id}` | The promote job. Code only: it never copies the database or uploads. |

The promote sends an `Idempotency-Key` from the run, so a re-run step cannot start a second job. The script polls every 10 seconds for 15 minutes.

## What if a step fails?

| What you see | What to do |
|---|---|
| `git push` prints `Permission denied (publickey)` | The key in `WPWATERFALL_SSH_KEY` is not saved on the environment, or its creator's role cannot deploy code. Save the public key again. |
| `git push` prints `Host key verification failed` | `WPWATERFALL_KNOWN_HOSTS` is empty or does not match the address. Run `ssh-keyscan -p PORT HOST` again and compare it with the **Info** tab. |
| `git push` prints `non-fast-forward` | The GitHub history does not contain staging's history. Seed the repository from the site (path A, step 1). |
| `git push` prints `This environment takes code from ... Push there.` | A repository is connected. Use path B. |
| The wait step says the build ended as failed | Read the build log: `GET /v1/builds/{id}/log`, or **Info** on staging. Fix the `build` step in `wpwaterfall.yml` and push again. |
| The wait step times out | The push or the webhook did not reach WP Waterfall. Check the webhook deliveries on GitHub and the **External repository** card. |
| The promote says `staging_changed` | Another commit reached staging first. Run the workflow again for the newer commit. |
| The promote says `nothing_to_promote` | Live already runs this commit, for example on a re-run. Nothing is wrong. |
| `403` from the API | The key lacks `sites:write`, or its creator's role cannot deploy code. |

## API

- `POST /v1/environments/{id}/ssh-keys` saves a key on one environment. `GET /v1/environments/{id}/git` gives the SSH address.
- `GET /v1/sites/{id}/releases?environment_id=ID` and `GET /v1/environments/{id}/builds` say what an environment runs.
- `GET /v1/sites/{id}/promote/preview` lists the commits and blockers before a promote. `POST /v1/sites/{id}/promote` promotes.
- `POST /v1/environments/{id}/git/pull` pulls the connected repository. `GET /v1/jobs/{id}` follows a job.
- MCP tools: `create_git_token`, `list_git_tokens`, `preview_promote`, `promote_to_live`, `list_releases`, `pull_git_repository`, and `wait_for_job`. The prompt `set_up_github_actions` walks an assistant through this article.

## Limits

A workflow cannot roll back. Roll back in the dashboard or with `POST /v1/releases/{id}/activate`.

## Related

- [Connect GitHub, GitLab, or Bitbucket](https://docs.wpwaterfall.com/connect-github)
- [Git access](https://docs.wpwaterfall.com/git-access)
- [API keys and scopes](https://docs.wpwaterfall.com/api-keys-and-scopes)
- [How Git deploys work](https://docs.wpwaterfall.com/code/git-workflow)
