velastack/action

velastack/action deploys a Vela app to your own server from GitHub Actions. It builds on the runner and hands the release to vela deploy over SSH, so a deploy from CI and a deploy from your laptop do the same thing.

Before you start

Provision the server and deploy once from your own machine — that first deploy is what mints the app id:

$ vela provision root@your-server
$ vela deploy --server root@your-server --domain example.com
$ git add .vela/project.json && git commit -m "Add the vela project id"

The action refuses to run until .vela/project.json is committed. A runner that finds no id mints a new one, and since its checkout is thrown away at the end of the job, every deploy would land as a brand new app and orphan the last one on the server.

Then one command writes the workflow and, with --setup-key, gives the action a way in:

$ vela enable ci --setup-key
$ git add .github/workflows/deploy.yml && git commit -m "Deploy on push"

vela enable ci writes .github/workflows/deploy.yml, checks what the workflow depends on (a lockfile, a deployed target, a GitHub remote) and creates a deploy key for CI: a new keypair, the public half added to the server’s authorized_keys, the private half stored as the SSH_PRIVATE_KEY repository secret with the gh CLI. The rest of this page is what that command sets up, for doing it by hand or changing it afterwards.

To make the key by hand instead:

$ ssh-keygen -t ed25519 -f vela-deploy -C "github actions"
$ ssh-copy-id -i vela-deploy.pub root@your-server

Add the private key to the repository as a secret named SSH_PRIVATE_KEY.

Usage

name: Deploy

on:
  push:
    branches: [main]

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

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: velastack/action@v1
        with:
          ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
        env:
          POCKETBASE_SUPERUSER_EMAIL: ci@example.com
          POCKETBASE_SUPERUSER_PASSWORD: ci-build-only-password

The action installs dependencies, builds, uploads a release, runs migrations, restarts the services and health-checks the result. A deploy that fails its health check puts the previous release back, migrations included, and fails the job. Use a concurrency group so two pushes queue rather than race; the server serializes deploys of one target as well, and drops one that turns out to be older than what went live meanwhile — see Two deploys at once.

Which target, which server

The workflow names no server and no domain. The first deploy of a target records both in .vela/project.json, and the action reads the server from there: production’s for a push, and for a pull request the one recorded for previews, falling back to production’s. Set server only to deploy somewhere the file does not name, and domain only to change it. A run with no server input and no recorded server for its target fails before anything is built, and says so.

target defaults to production. That is the entry stored as prod under targets in .vela/project.json: the two are spellings of the same target, so there is nothing to set for the usual case. Any other name, such as target: staging, is a separate copy of the app.

npm and pnpm

The action installs with whichever lockfile is committed:

  • package-lock.json - npm ci, with the npm cache restored
  • pnpm-lock.yaml only - pnpm install --frozen-lockfile
  • both - npm, the same choice the CLI makes
  • yarn.lock, bun.lock or none - the run fails early, asking for an npm or pnpm lockfile

For pnpm, the version is the one in package.json’s packageManager field ("packageManager": "pnpm@10.4.1") when there is one, and otherwise the newest major that reads the lockfile as written. To install some other way, do it in an earlier step and set install: false.

The two POCKETBASE_SUPERUSER_* values in the workflow are placeholders for a project with a backend, not credentials. See Secrets below.

Pull request previews

Add pull request events and an API key, and every pull request gets its own preview: a full copy of the app on the server, at <project>--<branch>.velastack.app. vela enable ci --previews writes a workflow like this one.

name: Deploy

on:
  push:
    branches: [main]
  pull_request:
    types: [opened, synchronize, reopened, closed]

permissions:
  contents: read
  pull-requests: write

concurrency:
  group: deploy-${{ github.head_ref || github.ref_name }}
  cancel-in-progress: false

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: velastack/action@v1
        with:
          ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
          api-key: ${{ secrets.VELA_API_KEY }}
        env:
          POCKETBASE_SUPERUSER_EMAIL: ci@example.com
          POCKETBASE_SUPERUSER_PASSWORD: ci-build-only-password

The target comes from the event when target is left unset: a push deploys production, a pull request deploys preview:<branch>. Closing the pull request, merged or not, removes the preview from the server — database and uploads included, with a snapshot kept in the server’s trash for two weeks — and retires its hostname. One comment on the pull request is kept up to date with the preview URL on every push, which is what pull-requests: write is for; a fork’s token cannot comment, and that never fails the deploy.

The removal rides on the closed event, so keep it in the trigger. If the workflow runs tests before deploying, let that event skip them: a branch is often closed precisely because it is red, and gating the cleanup on green leaves the preview behind for good.

jobs:
  check:
    if: github.event.action != 'closed'
    # ...
  deploy:
    needs: check
    if: ${{ !cancelled() && (github.event.action == 'closed' || needs.check.result == 'success') }}
    # ...

Previews never inherit domain — that is production’s. To serve them on your own domain as well, add a preview base on the project’s Domains page.

VELA_API_KEY is what records deploys on velastack.dev and gives previews their hostname. Create one at velastack.dev/api-keys/new and add it as a repository secret. The project must also be linked, which vela link writes into the same .vela/project.json you already commit. Without the key the deploy still runs; it just is not recorded, and a preview has nothing to be served on.

If pushes should deploy a named target such as staging rather than production, pass it on every event except a pull request, and leave it empty there so the preview target can take over. The empty value has to come last: '' is falsy in GitHub expressions, so cond && '' || 'staging' reads like a ternary but hands back staging on every event — and on a closed pull request that would try to remove it. The action refuses to remove anything but a preview in auto mode, but the pull request’s deploys would still have landed on that target.

          target: ${{ !startsWith(github.event_name, 'pull_request') && 'staging' || '' }}

Dependabot and forks

Pull requests opened by Dependabot, and any pull request from a fork, run without the repository’s secrets, so the action has no SSH key and cannot reach the server. Skip the job for them rather than let it fail; with no preview deployed there is nothing to remove on close either, so the same condition covers the closed event:

  deploy:
    if: github.event_name != 'pull_request' || (github.event.pull_request.user.login != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork)

Inputs

  • server - SSH target, as user@host or host. Read from the target’s entry in .vela/project.json when unset.
  • ssh-key - Required. Private key with access to the server.
  • ssh-port - Port, when the server does not listen on 22.
  • known-hosts - Contents for known_hosts. Without it the host key is fetched on first connect.
  • target - Which copy of the app to deploy: production (the prod entry in .vela/project.json), or a name you chose such as staging. Defaults to production, or to preview:<branch> on a pull request. environment is the deprecated name, still honoured when target is unset.
  • domain - Hostname(s) to serve on, comma separated. Read from .vela/project.json; only needed to change it. Never applied to previews.
  • api-key - velastack.dev API key, so the deploy is recorded on the linked project and previews get a velastack.app hostname.
  • action - deploy, destroy, or auto. auto deploys on every event except a closed pull request, where it removes the preview — and only ever a preview: a closed event whose target is anything else fails the job. Defaults to auto.
  • confirm-name - The app’s name, required when action: destroy targets production or a named environment such as staging. Never needed for previews.
  • comment - On pull requests, keep one comment up to date with the preview URL. Defaults to true.
  • github-token - Token the comment is posted with, and the pull request’s state is read with before a preview deploys. Defaults to the workflow token, which needs pull-requests: write.
  • project - Override the project name.
  • health-path - Path the health check requests.
  • remote-db - Build against the server’s database. Left unset, the CLI decides: on once the target has been deployed to. Set false to build against a throwaway one.
  • working-directory - Directory holding the app. Defaults to ..
  • node-version - Node.js version to build with. Defaults to .nvmrc or .node-version, then 26.
  • install - Install dependencies first: npm ci, or pnpm install --frozen-lockfile when only a pnpm-lock.yaml is committed. Defaults to true.
  • vela-version - Version of the CLI to run. Defaults to the one the project pins.

Outputs

  • release - Identifier of the release that was activated
  • url - URL the app is served on
  • hostnames - Every hostname the target is served on, comma separated
  • target - The target that was deployed or removed, such as production or preview:my-branch
  • mode - deploy, destroy, or skipped when a preview was not deployed because its pull request had closed

On a destroy, release, url and hostnames are empty.

Pages that prerender from data

A prerendered page is rendered once, at build time, against whatever database the build can see. On a runner that would be an empty throwaway database, so those pages would come out full of defaults.

The deploy avoids that on its own: once the target has been deployed to, the build is rendered against that instance’s database, tunnelled over the same SSH connection. The superuser credentials come off the server, so no new secrets go into CI, and the build only ever reads. Nothing has to be set for this.

Set remote-db: false to opt out and build against a throwaway database instead:

      - uses: velastack/action@v1
        with:
          ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
          remote-db: false

Prerendered pages see the target’s domain as url.origin, taken from the domain already recorded for it, so there is nothing to pass for it. Their canonical links, like the app’s name, come from src/lib/site.ts, not from the database.

Secrets

Production environment variables live on your server, not in the action and not in the release. Set them once with vela env. Anything the build needs — as opposed to the running app — belongs in the workflow’s env, because it has to exist on the runner:

      - uses: velastack/action@v1
        with:
          ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
        env:
          POCKETBASE_SUPERUSER_EMAIL: ci@example.com
          POCKETBASE_SUPERUSER_PASSWORD: ci-build-only-password
          PUBLIC_SITE_URL: https://example.com

The PocketBase superuser’s real credentials never go in the workflow, and never in GitHub secrets. The server created them on the first deploy and keeps them in the target’s environment; a build that renders against the deployed database reads them from there over SSH.

What a project with a backend does need on the runner is the pair of placeholders above. They are the login for a throwaway database that exists only on the runner, for the builds that use one: a target’s first deploy from CI, the first deploy of each pull request preview, and any build with remote-db: false. Any values work (the password needs ten characters), they open nothing, and they never leave the job. The CLI checks that both are set before it deploys a project with a backend, so keep them in the workflow even when every build uses the deployed database. A project without a backend needs neither.

Pinning the host key

By default the action trusts the server’s host key the first time it connects. To pin it instead, capture it once and pass the output as the known-hosts input:

$ ssh-keyscan -H your-server

Requirements

  • The app builds with @sveltejs/adapter-node
  • .vela/project.json is committed — it carries the app id the server keys everything on
  • A package-lock.json (npm) or a pnpm-lock.yaml (pnpm) is committed