# Publish

Publishing makes a [release](/docs/concepts/project-lifecycle.md#releases) from a branch, a frozen copy of its files, and deploys it to an environment.

## Before you start

You need a change you have previewed. See [Preview changes](/docs/projects/preview.md).

## Publish a branch

**Code**

1. Deploy `main` to production, the default environment (`--env staging` picks another). It creates the release and deploys it:

```bash
npx veryfront deploy
```

2. Read the output. You should now see `Deployed … to production` and the release's version.

### Troubleshooting

**If you see "The latest push is for branch "new-headline", but deploy targets "main""**, you merged a branch after your last push, and `deploy` only trusts what you pushed yourself. Run `npx veryfront push`, then `npx veryfront deploy` again.

**Studio**

1. Click **Deploy**.
2. Leave **Production** ticked.
3. Untick **Staging**.
4. Click **Deploy** in the popover.
5. Open **Deployment** > **Deployments**. You should now see a deployment on Production in the list.

**API**

1. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
2. Create a release from `main` with your [API key](/docs/authentication/api-keys.md):

```bash
curl -X POST https://api.veryfront.com/projects/$PROJECT/releases \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"branch_reference":"main"}'
```

3. Set `RELEASE_ID` to the `id` in the response: `export RELEASE_ID=<id>`.
4. Wait until the release's `asset_manifest.state` is `ready`:

```bash
curl https://api.veryfront.com/projects/$PROJECT/releases/$RELEASE_ID \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

5. Get the project:

```bash
curl https://api.veryfront.com/projects/$PROJECT \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

6. Set `ENVIRONMENT_ID` to the `id` of the entry named `production` in its `environments`: `export ENVIRONMENT_ID=<id>`.
7. Deploy the release to it:

```bash
curl -X POST https://api.veryfront.com/projects/$PROJECT/deployments \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"release_id\":\"$RELEASE_ID\",\"environment_id\":\"$ENVIRONMENT_ID\"}"
```

8. List the deployments. You should now see one with your `release_id`:

```bash
curl https://api.veryfront.com/projects/$PROJECT/deployments \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

### Try it in a sandbox

```playground
step: Create a project | npm create -y veryfront@latest support-desk -- --template minimal --yes
step: Push it | cd support-desk && npx veryfront push
step: Set PROJECT | export PROJECT=$VERYFRONT_PROJECT_ID
step: Create a release | export RELEASE_ID=$(curl -s -X POST https://api.veryfront.com/projects/$PROJECT/releases -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"branch_reference":"main"}' | jq -r .id)
step: Wait until it is ready | until curl -s https://api.veryfront.com/projects/$PROJECT/releases/$RELEASE_ID -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -e '.asset_manifest.state == "ready"'; do sleep 3; done
step: Set ENVIRONMENT_ID | export ENVIRONMENT_ID=$(curl -s https://api.veryfront.com/projects/$PROJECT -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r '.environments[] | select(.name == "production") | .id')
step: Deploy the release | curl -X POST https://api.veryfront.com/projects/$PROJECT/deployments -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d "{\"release_id\":\"$RELEASE_ID\",\"environment_id\":\"$ENVIRONMENT_ID\"}"
check: curl https://api.veryfront.com/projects/$PROJECT/deployments -H "Authorization: Bearer $VERYFRONT_API_KEY"
expect: "release_id"
```

### Troubleshooting

**If the API says "Release styles are not ready for deployment" or "Release browser assets are not ready for deployment"**, the release is still building. Repeat step 4 until it is `ready`.

## With MCP

1. Call `veryfront__create_release` with `project_reference` (the project's slug or ID) and `"branch_reference": "main"`. Keep its `id`.
2. Call `veryfront__get_release` with the release's `id` until `asset_manifest.state` is `ready`.
3. Call `veryfront__list_environments` with `project_reference`. Keep the `id` of the one named `production`.
4. Call `veryfront__create_deployment` with `project_reference`, the `release_id` and the `environment_id`.
5. Call `veryfront__list_deployments` with `project_reference` and the `environment_id`. It worked when a deployment with your `release_id` is listed.

## Next steps

* [Set variables](/docs/runtime/environments.md)
* [Roll back](/docs/deployment/rollback.md)
