Deploying from GitHub Actions

Overview

You can automate moonbase deployments from your GitHub Actions workflow using the moonbase deploy API. Every push to your main branch can trigger a fresh deploy — no manual ZIP upload needed.

Create an API key

Open API Keys in the sidebar and create a new key with deploy scope. Copy the key — it starts with mb_live_. Add it to your GitHub repository:

Settings → Secrets and variables → Actions → New secret

Name: MOONBASE_API_KEY

Value: mb_live_...

Find your mission ID

On your mission's Mission Control page, the URL contains your mission ID:

https://app.moonbase.cloud/missions/<mission ID>

Or ask the API: GET https://app.moonbase.cloud/api/v1/sites/{address}/status with your API key returns it as id (see the API Reference).

Add it as a repo secret (MOONBASE_MISSION_ID) or a variable.

Prepare the deploy result parser

Download the moonbase Skill (https://moonbase.cloud/skill), copy scripts/parse-deploy-result.sh from its bundle into your repository at the same path, and commit that helper before enabling the workflow. The example checks for the helper and its tools before uploading. It uses the shipped parser so a truncated stream, transport failure or deployed-but-not-ready app cannot turn the job green. Exit 3 means the upload landed but the app is not ready: check the mission status instead of uploading again.

Example workflow

name: Deploy to moonbase

on:
  push:
    branches: [main]

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

      - name: Check deploy parser and tools
        run: |
          set -euo pipefail
          test -f scripts/parse-deploy-result.sh
          for tool in bash jq zip unzip curl node; do
            command -v "$tool" >/dev/null
          done

      - name: Install dependencies
        run: npm ci

      - name: Build
        run: npm run build

      - name: Package for moonbase
        run: |
          rm -f -- deploy.zip
          zip -r deploy.zip . \
            --exclude "node_modules/*" \
            --exclude "*/node_modules/*" \
            --exclude ".git/*" \
            --exclude ".env*" \
            --exclude "*/.env*" \
            --exclude "deploy.zip" \
            --exclude ".next/cache/*"

      - name: Deploy to moonbase
        run: |
          set -euo pipefail
          log="$(mktemp)"; chmod 600 "$log"; trap 'rm -f "$log"' EXIT
          set +x
          curl_rc=0
          meta="$(printf 'Authorization: Bearer %s\n' "$MOONBASE_API_KEY" | curl -sSN -X POST https://upload.moonbase.cloud/api/projects/upload/stream \
            --header @- \
            -H "User-Agent: github-actions-moonbase/1.0" \
            -F "[email protected]" \
            -F "redeployProjectId=$MOONBASE_MISSION_ID" \
            -o "$log" -w '%{http_code} %{content_type}')" || curl_rc=$?
          bash scripts/parse-deploy-result.sh "$log" "${meta%% *}" "${meta#* }" "$curl_rc"
        env:
          MOONBASE_API_KEY: ${{ secrets.MOONBASE_API_KEY }}
          MOONBASE_MISSION_ID: ${{ secrets.MOONBASE_MISSION_ID }}

Monorepo deployments

For monorepos, ZIP only the sub-package you want to deploy. Exclude .env files and other credentials just as in the workflow above. Supply required secrets through the write-only environment variables dialog before deployment:

cd packages/my-app && rm -f -- ../../deploy.zip && zip -r ../../deploy.zip . -x ".env*" "*/.env*" "node_modules/*" "*/node_modules/*" ".git/*"

Both examples replace the generated deploy.zip so excluded files from an older archive cannot remain inside it. Keep any ZIP you need under a different filename before running these commands. Ensure your package.json is at the ZIP root, not nested inside a subfolder.

Deployment status

The endpoint responds with a live Server-Sent Events stream. Once the stream opens, the HTTP status is 200 even if the deploy later fails, so don't rely on curl's exit code alone. Keep the connection open and validate the complete result with the shipped parser, as the workflow example above does. A done event means the upload was published; app_ready:false is a separate deployed-but-not-ready outcome. Check the status endpoint before calling the app ready or retrying an uncertain upload. If the deploy fails, the stream ends with an error event instead. That event includes the same error ID as the in-app error screen, which is useful when you contact support.

Problems caught before the stream opens (a bad key, a plan limit, a build already running) come back as a JSON error with a 4xx status — see Errors before the stream opens in the API Reference.

To check a mission later without the stream, use the mission status endpoint: GET https://app.moonbase.cloud/api/v1/sites/{address}/status.