Appearance
behindgate/deploy-action deploys a build from a GitHub Actions workflow in one step. It downloads the bg-deploy CLI, verifies it against a checksum committed in the Action's own repository, caches it across runs, and deploys the folder you point it at.
The deploy itself is the CLI's, unchanged. The Action saves you installing the binary and wiring its flags, and it gives the job two outputs to use afterwards.
Quick start
yaml
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci && npm run build
- uses: behindgate/deploy-action@v1
with:
path: dist
token: ${{ secrets.BEHINDGATE_TOKEN }}Generate the token in the dashboard under Settings → Deploy tokens, and store it as a repository secret. Always pass it from a secret, never inline.
path is your build output: the folder whose contents become the app, so that index.html sits at the top of it. The CLI zips the contents rather than the folder, which is why pointing this at the directory above your build produces a site that serves nothing.
Inputs
| Input | Required | Default | What it does |
|---|---|---|---|
path | yes, except with delete-app | The folder to deploy, or an existing .zip to upload as-is. | |
token | no | A deploy token from Settings → Deploy tokens. Without it the job authenticates as itself, which is what Deploying without a token covers. | |
site-url | no | What to deploy to, written as the URL it serves on: the host names the site, the path names the app. Only with the job's own identity; it cannot be combined with token. | |
create-app | no | false | Create the app named by site-url when it is not there yet. |
delete-app | no | false | Delete the app named by site-url and exit without deploying. |
url | no | https://app.dev.behindgate.net/api/deploy/releases | Pin the deploy endpoint to an exact URL, for a local or self-hosted endpoint. |
cli-version | no | the version the Action pins | Hold a specific bg-deploy version after a bad release. Normally leave it unset. |
download-base-url | no | https://app.dev.behindgate.net | The host the CLI is downloaded from. |
Outputs
| Output | What it carries |
|---|---|
release-id | The identifier of the published release. Empty for delete-app. |
url | The address the deployed app is served at. Empty for delete-app. |
Give the step an id to read them:
yaml
- uses: behindgate/deploy-action@v1
id: deploy
with:
path: dist
token: ${{ secrets.BEHINDGATE_TOKEN }}
- run: echo "Deployed to ${{ steps.deploy.outputs.url }}"Deploying without a token
token is optional. Leave it out and the CLI authenticates as the workflow run itself: it exchanges the OIDC token GitHub mints for the job for a deploy token that lives fifteen minutes, so the repository stores no long-lived secret at all.
That needs two things:
permissions: id-token: writeon the job, which is what lets it request the OIDC token.- A CI trust for the repository in your workspace, under Settings → CI trusts. Deploy from CI without a secret covers how to set one up and what it grants.
yaml
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- uses: behindgate/deploy-action@v1
with:
path: distThis is also the only mode in which site-url, create-app and delete-app work. A deploy token is pinned to one app that already exists, so it can neither create another nor delete the one it names. Passing token together with any of the three fails the step immediately, before anything is downloaded or uploaded.
Per-pull-request previews
A trust that covers a whole site, holding Create apps and Delete apps, lets the pipeline stand a preview app up when a pull request opens and tear it down when it closes. Nobody creates anything in the dashboard, and the preview is private behind the site's sign-in like every other app.
yaml
name: Preview
on:
pull_request:
types: [opened, synchronize, reopened, closed]
jobs:
build:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist
preview:
needs: build
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist
- uses: behindgate/deploy-action@v1
id: preview
with:
path: dist
site-url: https://docs.example.com/preview/pr-${{ github.event.number }}
create-app: true
- run: echo "Preview at ${{ steps.preview.outputs.url }}"
teardown:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: behindgate/deploy-action@v1
with:
site-url: https://docs.example.com/preview/pr-${{ github.event.number }}
delete-app: trueThe build and the deploy are separate jobs on purpose. A job holding id-token: write can exchange its identity for a deploy token that may create and delete apps anywhere in the site the trust names, so the pull request's own build must not run beside it: the build job has no OIDC permission, and the deploy job takes only the built files. The teardown job runs no repository code at all, so it stays a single job.
delete-app needs no path and no checkout, since it uploads nothing, and deleting a path with no app there still succeeds. A teardown that runs twice, or on a pull request that never got a preview, is not a failure.
Without create-app, deploying to a path that serves no app is an error rather than a silent creation. That is what stops a mistyped path, or a pr-${{ github.event.number }} that expanded to nothing, from quietly minting an app nobody looks at.
Note that site-url and url are never the same value. site-url is where the release is served; url is the endpoint it is uploaded to.
Why the endpoint is pinned
A deploy token is not only a credential. It also carries the endpoint the CLI uploads to, as a claim inside the token itself. Anyone who can change your BEHINDGATE_TOKEN secret could therefore point your builds at a host they control, and nothing in the job would look wrong: the upload succeeds, the step exits 0, and your real site simply stops receiving updates.
The Action defaults url to the production endpoint rather than to whatever the token says, so the destination lives in your workflow file where code review and branch protection cover it. A token whose own claim disagrees with the pinned endpoint is refused rather than silently overridden.
Set url only when you need a different endpoint, and write it as a literal. Never put the endpoint in a secret: it is not sensitive, and storing it beside the token means one compromised store controls both the credential and the destination.
Which CLI version you get
Effectively the current one, and by default you pin nothing. BehindGate is a SaaS, so the server moves whether or not your workflow does; holding an old CLI leaves you on a client the server has moved past, and one that cannot receive a fix.
The Action still pins a checksum per platform, for integrity rather than stability. It downloads a binary and runs it on your runner beside your source and your secrets, so it verifies the archive before extracting it and fails the deploy on a mismatch rather than running it anyway. A scheduled job in the Action's repository verifies each new CLI release and opens a pull request, so new versions arrive through a reviewed commit.
cli-version is the escape hatch for the one case that needs it: holding the previous version after a bad CLI release. Using it routinely is how a workflow drifts.
The Action supports the linux, macOS and Windows runners on both amd64 and arm64. A runner outside that set fails with an explicit message rather than guessing at an archive that does not exist.
When it does not work
The step reports the CLI's two failure modes differently, because they need different fixes.
| Exit code | What it means |
|---|---|
2 | A configuration problem, rejected before anything was deployed: a missing or malformed token, a bad path, or a pinned endpoint that disagrees with the one the token was minted for. With no token the message points at the CI trust instead, which is what decides what the job may do. |
1 | The deploy itself failed: the endpoint rejected the release, the runner could not reach it, or the upload was interrupted. Often transient and worth retrying. |
An unset secret interpolates to an empty string rather than failing the workflow, which selects the job credential instead. The Action catches that: with no token and no OIDC token available, it fails naming both causes, the missing id-token: write permission and the secret that may simply not be set.
The token is masked in the log before anything else runs, and is passed to the CLI through the environment rather than on the command line, so it cannot appear in a process listing or in the step's command echo.
Other CI systems
The Action is GitHub Actions only. GitLab CI and Bitbucket Pipelines run bg-deploy directly and authenticate the same way, through their own OIDC identity. See Deploy from CI without a secret for both, and Deploy with the CLI for the binary itself.