> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy from CI/CD: GitHub Actions, GitLab CI and Any Pipeline

> Deploy to Square Cloud from a pipeline: a least-privilege API key, a complete GitHub Actions workflow with the official action, a GitLab CI job, and the same deploy with plain curl.

A deploy from a pipeline is one command: `squarecloud commit <appID> --restart`. It zips the checked-out folder, sends it to an application that already exists and restarts it. This page shows how to run it from GitHub Actions, from any other CI and without the CLI.

> [!NOTE]
>
> A pipeline updates an application, it doesn't create one. Create the application first, with the [quickstart](https://docs.squarecloud.app/en/getting-started/quick-start.md), and copy its ID from the dashboard or from `squarecloud app list`.

Prefer no pipeline at all? [GitHub deploys](https://docs.squarecloud.app/en/cli-reference/github-deploys.md) link a repository to the application, and every push deploys by itself. Use a pipeline when the deploy depends on something else: tests, a build, a release, several applications.

## Create a key for the pipeline

Don't reuse your personal key. In the dashboard, open [**Account** → **Security**](https://squarecloud.app/en/account/security) and create a key only for this repository:

| Setting | Value | Why |
| :- | :- | :- |
| **Permissions** | `apps:deploy` and `apps:control` | `apps:deploy` sends the commit and `apps:control` restarts the application. |
| **Resources (optional)** | Only the applications this repository deploys | A leaked key can't touch anything else in the account. |

Add `envs:write` if the pipeline also sets environment variables, and `apps:read` if it reads the status or the logs. The [scopes table](https://docs.squarecloud.app/en/api-reference/authentication.md#scopes) lists what each one allows.

Store the key as a secret of your CI, never in the repository. With one key per repository, you can revoke one without stopping the others.

## GitHub Actions

Save the key as a repository secret named `SQUARECLOUD_API_KEY` and the application ID as a repository variable named `SQUARECLOUD_APP_ID` (**Settings** → **Secrets and variables** → **Actions**). Then add this workflow:

```yaml .github/workflows/deploy.yml theme={"system"}
name: Deploy

on:
  push:
    branches: [main]

concurrency:
  group: deploy-${{ github.ref_name }}

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7

      - uses: squarecloudofc/github-action@v2
        with:
          token: ${{ secrets.SQUARECLOUD_API_KEY }}
          command: commit ${{ vars.SQUARECLOUD_APP_ID }} --restart
```

Every push to `main` now sends the repository to your application and restarts it. Two details matter:

* Keep the `actions/checkout` step: without it the runner has no files to send.
* `concurrency` makes two pushes in a row deploy one after the other, instead of at the same time.

The [official action](https://github.com/squarecloudofc/github-action) installs the CLI on the runner, checks the download against the release checksums, masks the key in the logs and runs the command. Its inputs:

| Input | Default | Description |
| :- | :- | :- |
| `token` | | The API key. Required. |
| `command` | | The CLI command to run, without the `squarecloud` prefix. |
| `workdir` | `.` | The folder the command runs in, relative to the repository root. |
| `version` | `latest` | The CLI version to install. Pin one for reproducible runs. |
| `install-only` | `false` | Only installs the CLI and sets the key, for the next steps of the job. |

### Test and build before the deploy

With `install-only`, the CLI stays available to the following steps. The deploy runs only if the tests and the build pass, and the built files go up with the commit:

```yaml theme={"system"}
    steps:
      - uses: actions/checkout@v7

      - uses: squarecloudofc/github-action@v2
        with:
          token: ${{ secrets.SQUARECLOUD_API_KEY }}
          install-only: true

      - run: npm ci && npm test && npm run build

      - run: squarecloud commit ${{ vars.SQUARECLOUD_APP_ID }} --restart
```

Check that [`squarecloud.ignore`](https://docs.squarecloud.app/en/getting-started/squarecloud-ignore) doesn't leave out the build folder (`dist`, `.next`, `build`), or the application starts without it.

### Staging and production

One workflow, two applications: pushes to `main` go to production and pushes to `develop` go to staging.

```yaml theme={"system"}
on:
  push:
    branches: [main, develop]

concurrency:
  group: deploy-${{ github.ref_name }}

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7

      - uses: squarecloudofc/github-action@v2
        with:
          token: ${{ secrets.SQUARECLOUD_API_KEY }}
          command: commit ${{ github.ref_name == 'main' && vars.PRODUCTION_APP_ID || vars.STAGING_APP_ID }} --restart
```

### Several applications in one repository

Each folder is its own application, with its own configuration file. `fail-fast: false` keeps one failed deploy from cancelling the others, and `max-parallel` keeps the uploads under the rate limit.

```yaml theme={"system"}
jobs:
  deploy:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      max-parallel: 2
      matrix:
        include:
          - folder: bot
            app: ${{ vars.BOT_APP_ID }}
          - folder: website
            app: ${{ vars.WEBSITE_APP_ID }}
    steps:
      - uses: actions/checkout@v7

      - uses: squarecloudofc/github-action@v2
        with:
          token: ${{ secrets.SQUARECLOUD_API_KEY }}
          workdir: ${{ matrix.folder }}
          command: commit ${{ matrix.app }} --restart
```

### Environment variables from secrets

Keep tokens in GitHub secrets and send them to the application before the commit. `env set` changes only the variables it lists, and the restart after the commit loads them. The key needs the `envs:write` scope.

```yaml theme={"system"}
      - uses: squarecloudofc/github-action@v2
        with:
          token: ${{ secrets.SQUARECLOUD_API_KEY }}
          install-only: true

      - name: Update environment variables
        run: squarecloud app env set --app "$APP_ID" "DISCORD_TOKEN=$DISCORD_TOKEN"
        env:
          APP_ID: ${{ vars.SQUARECLOUD_APP_ID }}
          DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}

      - run: squarecloud commit ${{ vars.SQUARECLOUD_APP_ID }} --restart
```

Passing the secret through `env`, instead of writing `${{ secrets.DISCORD_TOKEN }}` in the command, keeps its value out of the script GitHub runs.

## Any other CI

Everywhere else the recipe is the same: install the CLI, set `SQUARECLOUD_API_KEY` and run the commit. In GitLab CI, with the key and the application ID saved as masked CI/CD variables:

```yaml .gitlab-ci.yml theme={"system"}
deploy:
  image: node:lts
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
  script:
    - npm install -g @squarecloud/cli
    - squarecloud commit "$SQUARECLOUD_APP_ID" --restart
```

On an image without Node.js, use the install script instead, which puts the CLI in `~/.local/bin`:

```bash theme={"system"}
curl -fsSL https://cli.squarecloud.app/install | bash
export PATH="$HOME/.local/bin:$PATH"
squarecloud commit "$SQUARECLOUD_APP_ID" --restart
```

The CLI reads the key from the `SQUARECLOUD_API_KEY` variable, so there is no login step and nothing is written to the runner's disk.

## Without the CLI

The same deploy is two API calls: a [commit](https://docs.squarecloud.app/en/api-reference/endpoint/apps/commit.md) with the zip, then a [restart](https://docs.squarecloud.app/en/api-reference/endpoint/apps/restart.md).

```bash theme={"system"}
set -euo pipefail
API="https://api.squarecloud.app/v2/apps/$SQUARECLOUD_APP_ID"

zip -qr app.zip . -x ".git/*" "node_modules/*"

curl -fsS -X POST "$API/commit" \
  -H "Authorization: $SQUARECLOUD_API_KEY" \
  -F "file=@app.zip"

curl -fsS -X POST "$API/restart" \
  -H "Authorization: $SQUARECLOUD_API_KEY"
```

`-f` makes curl exit with an error on any `4xx` or `5xx` answer, so a refused commit fails the job. The zip is your responsibility here: `squarecloud.ignore` is only read by the CLI and the VS Code extension. The limit is 100 MB.

## How the CLI behaves in a pipeline

* **Any failure exits with code `1`**, so a failed deploy fails the job. Check the exit code, not the text.
* **`commit` never opens a picker.** Without an ID, it uses the `ID=` line of the configuration file in the folder, and stops when there is none.
* **Confirmations fail closed.** Commands that delete or replace data ask for confirmation, and without a terminal they exit with code `1` and change nothing. Add `-y` to the ones you mean.
* **`--restart` also starts** an application that was stopped. Without it, the new files only run after the next restart.
* **Pace your commits.** An application accepts one commit every 5 seconds, and an account one every 2 seconds. A faster one answers `429`.
* **Parse `--json`,** not the tables: `squarecloud app status <appID> --json` after the deploy tells you whether the application is running.
* **Trace a failing run** with `SQUARECLOUD_DEBUG: 1` in the step's `env`. It prints the method, the path, the status and the duration of each request, never headers or bodies.

More in [Global flags and CI](https://docs.squarecloud.app/en/cli-reference/global-flags-and-ci.md#scripts-and-ci).

## Frequently asked questions

> [accordion] The deploy passes but the old code is still running.
>
> The commit ran without `--restart`. New files only run after a restart.

> [accordion] Can the pipeline create the application?
>
> It can, with `squarecloud upload`, but each run would create one more application. Create it once by hand and let the pipeline commit to it.

> [accordion] The job fails with 403 MISSING\_SCOPE or RESOURCE\_NOT\_ALLOWED.
>
> The key lacks a scope the command needs, or the application is not in the key's resources. Scopes can't be edited on an existing key: create a new one with `apps:deploy` and `apps:control` and replace the secret.

> [accordion] Is the application offline during the deploy?
>
> For the time of the restart, yes. To keep a website answering, put two applications behind a [load balancer](https://docs.squarecloud.app/en/services/load-balancer.md) and deploy one at a time.

## Related

* [`squarecloud commit`](https://docs.squarecloud.app/en/cli-reference/deploy#squarecloud-commit): every flag of the command.
* [Authentication](https://docs.squarecloud.app/en/cli-reference/authentication.md#ci-and-scripts): how the CLI reads the key.
* [GitHub deploys](https://docs.squarecloud.app/en/cli-reference/github-deploys.md): deploy on push without a pipeline.
* [API keys and scopes](https://docs.squarecloud.app/en/api-reference/authentication.md): scopes and keys limited to resources.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.