# Actions

Actions are buttons that start a GitHub Actions workflow. Use them to rebuild the site on demand, regenerate a page, optimise images or anything else you've automated. The workflow does the work; SP CMS starts it, passes it context and tracks the run. For the editor's side, see [run actions](/guides/actions/).

GitHub Actions must be enabled on the repository.

## Add a deploy button

First, create the workflow. It must accept a `payload` input:

```yaml title=".github/workflows/deploy.yml"
name: Deploy
on:
  workflow_dispatch:
    inputs:
      payload:
        description: SP CMS context as JSON
        required: true
        type: string
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: echo "Run your deploy command here"
```

Then add the button to `.pages.yml`:

```yaml
actions:
  - name: deploy
    label: Deploy site
    workflow: deploy.yml
```

To try it, choose **Deploy site** in the sidebar and confirm. Follow the run on the **Actions** page, under Admin in the sidebar.

## Where buttons appear

Where you define an action decides where its button shows up and what it acts on:

| Defined under               | Button appears                           | `scope`                           |
| --------------------------- | ---------------------------------------- | --------------------------------- |
| Root `actions`              | Sidebar, or Overview quick links         | `sidebar` (default) or `overview` |
| A collection's `actions`    | On the collection list, or on each entry | Required: `collection` or `entry` |
| A file's `actions`          | On the file                              | Leave out                         |
| A media library's `actions` | On the library                           | Leave out                         |

For example, add this action to a collection to show a button on each entry:

```yaml
content:
  - name: posts
    type: collection
    path: src/content/posts
    actions:
      - name: preview
        label: Preview
        workflow: preview.yml
        scope: entry
```

## Keys

| Key          | Description                                                                                        |
| ------------ | -------------------------------------------------------------------------------------------------- |
| `name`       | Required. Unique ID: letters, numbers, `-` and `_`.                                                |
| `label`      | Required. Button text.                                                                             |
| `icon`       | A [Hugeicons](https://hugeicons.com) name for the button, such as `Rocket01`. Defaults to a flash. |
| `workflow`   | Required. Workflow filename in `.github/workflows/`.                                               |
| `ref`        | Branch or tag to run the workflow from. Defaults to the branch open in SP CMS (also `current`).    |
| `scope`      | Placement or context; see [above](#where-buttons-appear).                                          |
| `confirm`    | `false` to skip confirmation, or `{ title, message, button }` to change the dialog's text.         |
| `fields`     | Inputs to ask for before running; see below.                                                       |
| `cancelable` | `false` to prevent cancelling runs from SP CMS. Default `true`.                                    |

## Ask for inputs

`fields` adds a form to the confirmation dialog. Values arrive in `payload.inputs`.

```yaml
actions:
  - name: deploy
    label: Deploy
    workflow: deploy.yml
    fields:
      - name: environment
        label: Environment
        type: select
        required: true
        default: staging
        options:
          - { label: Staging, value: staging }
          - { label: Production, value: production }
      - name: clear_cache
        label: Clear CDN cache
        type: checkbox
```

| Field key  | Description                                                                  |
| ---------- | ---------------------------------------------------------------------------- |
| `name`     | Required. Key in `payload.inputs`.                                           |
| `label`    | Required. Label in the form.                                                 |
| `type`     | Required. `text`, `textarea`, `number`, `checkbox` or `select`.              |
| `required` | Whether a value is required.                                                 |
| `default`  | Initial value.                                                               |
| `options`  | Required for `select`, and only allowed there. A list of `{ label, value }`. |

When an action has fields, the dialog is shown even with `confirm: false`.

## The payload

The workflow receives one JSON string in `inputs.payload`:

```json
{
  "source": "pages-cms",
  "action": { "name": "deploy", "label": "Deploy", "cancelable": true },
  "repository": {
    "owner": "SeymourpowellLtd",
    "repo": "website",
    "ref": "main",
    "workflowRef": "main",
    "sha": "abc123…"
  },
  "triggeredAt": "2026-03-30T12:00:00.000Z",
  "triggeredBy": {
    "userId": "…",
    "name": "Sam Lee",
    "email": "sam@example.com",
    "githubUsername": "samlee",
    "image": null
  },
  "context": {
    "type": "entry",
    "name": "posts",
    "path": "src/content/posts/hello.md",
    "data": {}
  },
  "inputs": { "environment": "staging", "clear_cache": true }
}
```

`source` is a fixed value. `context` describes where the action was run from: `repository`, `collection`, `entry`, `file` or `media`, with the content or library `name` and the `path`. `context.data` holds extra details from the page, such as a collection's label. `githubUsername` is `null` or missing for people without a linked GitHub account. Reruns also include `"triggerType": "rerun"` and `rerunOfActionRunId`.

Read values with `fromJSON`:

```yaml
- run: ./deploy.sh "$ENVIRONMENT"
  env:
    ENVIRONMENT: ${{ fromJSON(inputs.payload).inputs.environment }}
```

Treat the whole payload as user input, including filenames, form values and the name of the person who ran it. In a shell step, pass expressions through `env` and quote the shell variable as above. GitHub substitutes expressions placed directly in `run` before the shell runs the script.

## Who can run actions

Managers, people signed in with GitHub who have write access to the repository, and invited collaborators can run the actions in `.pages.yml`. Only managers can cancel a run (unless `cancelable: false`) or run it again.
