---
title: "Deploy a site or Worker"
description: "A site built on main can deploy as soon as its build succeeds. To tie deployment to a stable release, make it depend on both jobs (needs: [build_site, publish] in the monorepo example) and pass the tag as release-tag. Monorepo workflows"
canonical_url: "https://actions.xovajs.com/en/guides/deployment"
---
# Deploy a site or Worker

> A site built on main can deploy as soon as its build succeeds. To tie deployment to a stable release, make it depend on both jobs (needs: [build_site, publish] in the monorepo example) and pass the tag as release-tag. Monorepo workflows

A site built on `main` can deploy as soon as its build succeeds. To tie deployment to a stable release, make it depend on both jobs (`needs: [build_site, publish]` in the monorepo example) and pass the tag as `release-tag`. [Monorepo workflows](https://actions.xovajs.com/en/examples/monorepo)

## Deployment permissions

Build with `check.yml` and pass its `source-sha` and `artifact-id` to `deploy.yml`. Use the same `config-file` for both. Grant write permissions and deployment credentials only to the deploy job.

| Provider | GitHub permissions | Cloudflare token permissions |
| --- | --- | --- |
| GitHub Pages | `contents: read`, `pages: write`, `id-token: write` | — |
| Cloudflare Pages | `contents: read` | Pages write access on the target account |
| Cloudflare Workers | `contents: read` | `Workers Scripts: Edit` on the target account |

Cloudflare production deployments use `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` from repository secrets or organization secrets shared with the repository. Previews use `CLOUDFLARE_PREVIEW_ACCOUNT_ID` and `CLOUDFLARE_PREVIEW_API_TOKEN` from the `docs-preview` environment. See [manual previews](https://actions.xovajs.com/en/guides/deployment#manual-cloudflare-workers-previews).

For automatic D1 provisioning, set `binding` and `database_name` in `d1_databases`, omit `database_id` and grant `D1: Edit`. Wrangler reuses the named database or creates it if missing.

## Deployment policy

Production evaluates `artifact.deployment-policy` after environment protection rules pass and the job holds the concurrency lock.

| Policy | `release-tag` | Deployment condition |
| --- | --- | --- |
| `latest-stable` (default) | Required | The tag identifies the latest published stable GitHub Release and resolves to `source-sha`. An older stable release is skipped. |
| `always` | Supplied | Any published stable GitHub Release whose tag resolves to `source-sha`. |
| `always` | Omitted | Deploy the artifact for `source-sha` without a Release lookup, e.g. on a push to `main`. |

Tagged deployments first skip drafts and prereleases. `latest-stable` also skips older stable releases. Only then does the job resolve the tag’s commit and compare it with `source-sha`. A mismatch or a failed lookup at any required step fails the job.

## Choose a provider

### GitHub Pages

Select `github-pages`, set `artifact.output-directory` to the built site and choose GitHub Actions as the source in the repository’s Pages settings. See the [monorepo site workflow](https://actions.xovajs.com/en/examples/monorepo).

### Cloudflare Pages Direct Upload

Set `artifact.provider` to `cloudflare-pages` and `project-name` to an existing Pages project. To deploy from `main`, filter for that branch in the caller and set `deployment-policy: always`.

Wrangler uploads the verified `payload/` to production and records the source SHA. A root `_worker.js` file or directory fails validation before upload because Pages treats it as a server entry point.

### Cloudflare Workers static assets

Point `artifact.output-directory` at the built site. Use a standalone Wrangler JSONC file with `assets.directory` pointing to a subdirectory next to that file. Omit `main`, `build.command` and inherited configuration.

The deploy job verifies the same-run artifact’s repository, commit and digest, then restores all files, including dotfiles, under `assets.directory` in a temporary directory. The official Wrangler Action uploads them with the pinned version, without reinstalling or rebuilding.

### Prebuilt Workers

Prebuilt Workers support production only. This `artifact` section uses the [pnpm project setup](https://actions.xovajs.com/en/examples/monorepo#project-configuration). `wrangler-config` is relative to `output-directory`. `server/` and `public/` can be siblings.

```json
{
  "component": "api",
  "kind": "bundle",
  "provider": "cloudflare-workers",
  "worker-name": "example-api",
  "output-directory": ".output",
  "wrangler-config": "server/wrangler.json",
  "check-command": "pnpm test",
  "build-command": "pnpm build"
}
```

Package `main`, its imported modules and any declared static assets together. If the build emits multiple modules, add module collection rules to the final Wrangler config.

The deploy job verifies the component, artifact kind, config path in the manifest, Worker name and `payload/` digest. It then runs `deploy --no-bundle` with the pinned Wrangler version in a clean directory.

## Manual Cloudflare Workers previews

1. Enable the workers.dev preview URL for a dedicated Worker in a separate Cloudflare preview account.
2. Set `CLOUDFLARE_PREVIEW_ACCOUNT_ID` and `CLOUDFLARE_PREVIEW_API_TOKEN` in the `docs-preview` GitHub environment. Limit Worker write access to the preview account. Set the repository variable `XOVA_DOCS_PREVIEW_WORKER` to the Worker name.
3. Enter the full commit SHA in the `workflow_dispatch` input. With `require-reachable: true`, a repository branch or tag must contain the commit. Pass the build’s `source-sha` and `artifact-id` to `deploy.yml` with `target: preview` and omit `release-tag`.

Check the preview URL and full SHA in the run summary. Previews serve static artifacts only, preserve `assets.base_path` and exclude production routes and bindings. Deployments from one repository to the same preview Worker run in sequence.

Skip the manual build when the preview variable is unset. A direct call with `target: preview` fails validation if the variable is missing or blank. For multiple sites, assign distinct `artifact.component` and `artifact-name` values.


## Sitemap

See the full [sitemap](https://actions.xovajs.com/sitemap.md) for all pages.
