# Deploy action for GitHub

Source: https://docs.autessa.com/docs/cdk/deploy-action

> Use the Autessa deploy GitHub Action to post a diff on every pull request and deploy to your stages when you merge to main.

# Deploy action for GitHub

(Preview)

The deploy API and the deploy action are in preview and not yet released. Names and shapes may change before they are generally available.

The deploy action runs the Autessa CDK in GitHub Actions. It comments a diff on each pull request, and deploys when the change lands on main.

The action runs the same engine as `npx autessa-cdk` from `@autessa/cdk`, so it loads projects written as `autessa.config.ts` or `autessa.yaml`. For Java projects it runs the Maven or Gradle plugin instead (see [Java projects](#java-projects)). For Python projects, run `autessa-cdk` in a workflow step (see [Commands](/docs/cdk/commands.md)).

## Quickstart

1. Ask a company admin for two deploy keys per stage, created in Autessa under **Settings → Deploy keys**:
   - a preview key with only **Preview changes**, for pull requests. Save it as a repository secret, for example `AUTESSA_PREVIEW_KEY_DEV` and `AUTESSA_PREVIEW_KEY_PROD`.
   - a deploy key with **Preview changes** and **Deploy**, for merges. Create GitHub environments `dev` and `production` (limit them to `main`, and add required reviewers if you want them), and save the key as an environment secret: `AUTESSA_DEPLOY_KEY_DEV` in `dev`, `AUTESSA_DEPLOY_KEY_PROD` in `production`.
2. Each job puts its key in the variable your `autessa.stages.yaml` names in `deployKeyEnv`.
3. Add the workflow below.

```yaml
# .github/workflows/autessa-deploy.yml
name: Autessa deploy
on:
  pull_request:
  push:
    branches: [main]
permissions:
  contents: read

jobs:
  # Pull requests: preview only, with "Preview changes" keys (repository secrets).
  preview:
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    concurrency:
      group: autessa-preview-${{ github.ref }}
      cancel-in-progress: true
    env:
      AUTESSA_DEPLOY_KEY_DEV: ${{ secrets.AUTESSA_PREVIEW_KEY_DEV }}
      AUTESSA_DEPLOY_KEY_PROD: ${{ secrets.AUTESSA_PREVIEW_KEY_PROD }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 24 }
      - run: npm ci   # only needed for autessa.config.ts projects
      - uses: Autessa-Inc/autessa-deploy-action@v0
        with:
          command: diff
          stages: dev,prod

  # Merges to main: deploy each stage with its "Deploy" key, kept in a GitHub environment.
  deploy-dev:
    if: github.event_name == 'push'
    runs-on: ubuntu-latest
    environment: dev
    concurrency:
      group: autessa-deploy-dev
      cancel-in-progress: false
    env:
      AUTESSA_DEPLOY_KEY_DEV: ${{ secrets.AUTESSA_DEPLOY_KEY_DEV }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 24 }
      - run: npm ci
      - uses: Autessa-Inc/autessa-deploy-action@v0
        with:
          command: deploy
          stages: dev

  deploy-prod:
    needs: deploy-dev
    runs-on: ubuntu-latest
    environment: production
    concurrency:
      group: autessa-deploy-prod
      cancel-in-progress: false
    env:
      AUTESSA_DEPLOY_KEY_PROD: ${{ secrets.AUTESSA_DEPLOY_KEY_PROD }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 24 }
      - run: npm ci
      - uses: Autessa-Inc/autessa-deploy-action@v0
        with:
          command: deploy
          stages: prod
```

Why split the keys: a pull request job runs code from the branch (including `npm ci` scripts), so it only gets a key that can look, not change. Environment secrets reach only jobs that name the environment, and those run only on pushes to `main`. `concurrency` makes a second merge wait for the first deploy to a stage instead of racing it.

On a pull request, the action posts a diff comment and updates it in place on every push. On a merge, it deploys `dev`, then `prod`. If a stage fails, the run stops there.

Each deploy shows up on the company's **Deployments** page in Autessa with the repository, the commit and a link to the workflow run, so you can go from a deployment back to the change that made it. See [Watch deployments](/docs/cdk/commands.md#watch-deployments).

## Refusals

A deploy stops after the preview, and fails the step, when a change:

- widens access (marked `WIDENS ACCESS`), unless `allow-widen: true`;
- costs money, such as buying a phone number (marked `WILL PURCHASE`), unless `allow-purchase: true` and the stage sets `allowPhonePurchase: true`;
- takes over a resource already in the tenant (marked `ADOPT`), unless `adopt: true`;
- drops columns and their data (marked `DELETES DATA`), unless `allow-destructive: true`.

Set these only in a workflow that a person reviews, for example after a pull request with the diff comment is approved.

## Java projects

With `build-tool: auto` (the default), the action picks the Node CDK when the folder has `autessa.config.*` or `autessa.yaml`, else the Maven plugin when it has `pom.xml`, else the Gradle plugin when it has `build.gradle.kts` or `build.gradle`. The job needs Java:

```yaml
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with: { distribution: temurin, java-version: 21, cache: maven }
      - uses: Autessa-Inc/autessa-deploy-action@v0
        with:
          command: ${{ github.event_name == 'pull_request' && 'diff' || 'deploy' }}
          stages: dev,prod
```

The project's wrapper (`./mvnw`, `./gradlew`) is used when it has one, and the inputs become the plugin's `autessa.*` properties.

## Inputs

| Input | Default | What it does |
| --- | --- | --- |
| `command` | `diff` | `diff` previews. `deploy` applies. |
| `stages` | | Comma-separated stage names from `autessa.stages.yaml`, run in order. |
| `fanout` | | Comma-separated fan-out groups. Each one runs against every tenant in the group. |
| `deploy-key` | | A deploy key for any stage whose `deployKeyEnv` variable is not set. |
| `working-directory` | `.` | The folder with `autessa.config.ts`, `autessa.yaml`, `pom.xml` or `build.gradle(.kts)`. |
| `build-tool` | `auto` | `auto`, `node`, `maven` or `gradle`. |
| `prune` | `false` | When deploying, also delete resources removed from the project. |
| `allow-widen` | `false` | Deploy even when a change widens access. |
| `allow-purchase` | `false` | Deploy even when a change costs money. The stage must also set `allowPhonePurchase: true`. |
| `adopt` | `false` | Take over resources already in the tenant under the project's names. |
| `allow-destructive` | `false` | Delete the columns the project dropped, with their data. |
| `fail-on-widen` | `false` | On `diff`: fail the check when any change widens access. |
| `skip-build` | `false` | Don't build app folders (Node projects only). |
| `comment-on-pr` | `true` | Post or update the diff comment on pull requests. |
| `github-token` | `${{ github.token }}` | Used to comment. Needs `pull-requests: write`. |
| `base-url` | | Override the API base URL. The default is `https://api.autessa.com`. |

Each stage reads its key from the environment variable named by `deployKeyEnv` in `autessa.stages.yaml`, then from `deploy-key`, then from `AUTESSA_DEPLOY_KEY`. Keys are masked in logs.

## Outputs

| Output | What it holds |
| --- | --- |
| `summary` | The diff as markdown. Also written to the job summary. |
| `changes` | JSON, one entry per tenant with its summary, changes and deployment. |
| `widens` | `true` when any change widens access. |
| `purchases` | `true` when any change costs money. |
| `deployment-ids` | JSON array of deployment IDs (deploy only). |
| `passed` | `true` when every step succeeded. |
| `reason` | Why the step ended: `ok`, `error`, `usage`, `widens_access`, `purchase_not_allowed`, `adopt_not_allowed`, `destructive_not_allowed` or `checks_failed`. |
| `exit-code` | The exit code for `reason`, the same as the [command line's](/docs/cdk/commands.md#exit-codes). The step exits with it. |

## Versions

The action runs on Node 24. `@v0` follows the newest `v0.x.y` release. Pin `@v0.1.0`, or a commit, to stay on one version.

## Tips

- Set `fail-on-widen: true` on pull requests, or require a review on pull requests whose diff contains `WIDENS ACCESS`.
- Add the [eval action](/docs/integrations/github-actions.md) before deploy to block releases that fail your attack simulation or grading threshold.
- Prefer [Autessa Pipelines](/docs/cdk/pipelines.md) if you want promotion rules and run history inside Autessa.

## Example

A full project with ready-to-copy workflows (`deploy.yml.example`) for TypeScript and Java: [autessa-as-code-tenant](https://github.com/Autessa-Inc/autessa-examples/tree/main/examples/autessa-as-code-tenant).

## Related

- [Commands](/docs/cdk/commands.md)
- [Multiple tenants](/docs/cdk/tenants.md)
- [GitHub Actions integrations](/docs/integrations/github-actions.md)
- [Autessa Pipelines](/docs/cdk/pipelines.md)

