> Full SurrealDB documentation index: https://surrealdb.com/docs/llms.txt

# Use SurrealDB in GitHub Actions

This guide will show you how to set up and use the official GitHub Action for SurrealDB in your CI/CD pipeline.

This guide will show you how to set up and use the official GitHub Action for SurrealDB in your CI/CD pipeline.

## Step 1: Create a new GitHub workflow file

Create a new YAML file in your repository's `.github/workflows` directory. You can name the file `surrealdb-ci.yml`.

```yaml
name: SurrealDB CI

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - name: Git checkout
      uses: actions/checkout@v4
    - name: Start SurrealDB
      uses: surrealdb/setup-surreal@v3
      with:
        surrealdb_version: latest
        surrealdb_port: 8000
        surrealdb_username: root
        surrealdb_password: secret
        surrealdb_auth: false
        surrealdb_strict: false
        surrealdb_log: info
        surrealdb_additional_args: --allow-all
        surrealdb_retry_count: 30
```

## Step 2: Customise workflow arguments

The official SurrealDB GitHub Action accepts several arguments to configure the SurrealDB setup. The table below lists the available arguments and their defaults:

<table>
    <thead>
        <tr>
            <th scope="col">Argument</th>
            <th scope="col">Description</th>
            <th scope="col">Default</th>
            <th scope="col">Value</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td scope="row" data-label="Argument">
                surrealdb_version
            </td>
            <td scope="row" data-label="Description">
                SurrealDB version to use
            </td>
            <td scope="row" data-label="Default">
                latest
            </td>
            <td scope="row" data-label="Value">
                latest, nightly, beta, alpha, v1.x.x, v2.x.x, v3.x.x
            </td>
        </tr>
        <tr>
            <td scope="row" data-label="Argument">
                surrealdb_datastore
            </td>
            <td scope="row" data-label="Description">
                Datastore to start SurrealDB with
            </td>
            <td scope="row" data-label="Default">
                memory
            </td>
            <td scope="row" data-label="Value">
                Any valid datastore path, for example rocksdb:data
            </td>
        </tr>
        <tr>
            <td scope="row" data-label="Argument">
                surrealdb_port
            </td>
            <td scope="row" data-label="Description">
                Port to run SurrealDB on
            </td>
            <td scope="row" data-label="Default">
                8000
            </td>
            <td scope="row" data-label="Value">
                Valid number from 0 to 65535
            </td>
        </tr>
        <tr>
            <td scope="row" data-label="Argument">
                surrealdb_username
            </td>
            <td scope="row" data-label="Description">
                Username to use for SurrealDB
            </td>
            <td scope="row" data-label="Default">
                root
            </td>
            <td scope="row" data-label="Value">
                Customisable by the user
            </td>
        </tr>
        <tr>
            <td scope="row" data-label="Argument">
                surrealdb_password
            </td>
            <td scope="row" data-label="Description">
                Password to use for SurrealDB
            </td>
            <td scope="row" data-label="Default">
                root
            </td>
            <td scope="row" data-label="Value">
                Customisable by the user
            </td>
        </tr>
        <tr>
            <td scope="row" data-label="Argument">
                surrealdb_auth
            </td>
            <td scope="row" data-label="Description">
                Enable authentication
            </td>
            <td scope="row" data-label="Default">
                false
            </td>
            <td scope="row" data-label="Value">
                true, false
            </td>
        </tr>
        <tr>
            <td scope="row" data-label="Argument">
                surrealdb_strict
            </td>
            <td scope="row" data-label="Description">
                Enable strict mode
            </td>
            <td scope="row" data-label="Default">
                false
            </td>
            <td scope="row" data-label="Value">
                true, false
            </td>
        </tr>
        <tr>
            <td scope="row" data-label="Argument">
                surrealdb_log
            </td>
            <td scope="row" data-label="Description">
                Enable logs
            </td>
            <td scope="row" data-label="Default">
                trace
            </td>
            <td scope="row" data-label="Value">
                none, full, error, warn, info, debug, trace
            </td>
        </tr>
        <tr>
            <td scope="row" data-label="Argument">
                surrealdb_import_file
            </td>
            <td scope="row" data-label="Description">
                SurrealQL file to import on startup
            </td>
            <td scope="row" data-label="Default">

            </td>
            <td scope="row" data-label="Value">
                Path to a .surql file, requires SurrealDB v3.0.0 or later
            </td>
        </tr>
        <tr>
            <td scope="row" data-label="Argument">
                surrealdb_additional_args
            </td>
            <td scope="row" data-label="Description">
                Additional arguments for SurrealDB
            </td>
            <td scope="row" data-label="Default">

            </td>
            <td scope="row" data-label="Value">
                <a href="/docs/reference/cli/surrealdb-cli/commands/start.md" target="_blank" rel="noopener noreferrer" title="Any valid SurrealDB CLI arguments">Any valid SurrealDB CLI arguments</a>
            </td>
        </tr>
        <tr>
            <td scope="row" data-label="Argument">
                surrealdb_retry_count
            </td>
            <td scope="row" data-label="Description">
                Seconds to wait for SurrealDB to become ready
            </td>
            <td scope="row" data-label="Default">
                30
            </td>
            <td scope="row" data-label="Value">
                Any valid integer
            </td>
        </tr>
    </tbody>
</table>

The file passed to `surrealdb_import_file` selects its own namespace and database, so it should begin with a `USE NS ... DB ...;` statement.

### Workflow outputs

The action exposes the details of the instance it started, so that later steps do not have to reconstruct them:

<table>
    <thead>
        <tr>
            <th scope="col">Output</th>
            <th scope="col">Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td scope="row" data-label="Output">
                endpoint
            </td>
            <td scope="row" data-label="Description">
                The HTTP endpoint the SurrealDB instance is listening on
            </td>
        </tr>
        <tr>
            <td scope="row" data-label="Output">
                version
            </td>
            <td scope="row" data-label="Description">
                The exact version of SurrealDB that was installed
            </td>
        </tr>
    </tbody>
</table>

### Example configuration

Here is an example configuration that sets specific values for each argument:

```yaml
name: SurrealDB CI

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - name: Git checkout
      uses: actions/checkout@v4
    - name: Start SurrealDB
      id: surrealdb
      uses: surrealdb/setup-surreal@v3
      with:
        surrealdb_version: latest
        surrealdb_port: 8000
        surrealdb_username: root
        surrealdb_password: secret
        surrealdb_auth: false
        surrealdb_strict: false
        surrealdb_log: info
        surrealdb_additional_args: --allow-all
        surrealdb_retry_count: 30
    - name: Run the tests
      run: ./run-tests.sh
      env:
        SURREALDB_ENDPOINT: ${{ steps.surrealdb.outputs.endpoint }}
```

### Tips for customisation

1. **Version Control**: Use specific versions to avoid unexpected changes. Example: surrealdb_version: v3.2.4.
2. **Security**: Always use strong passwords for surrealdb_password and avoid using default credentials in production.
3. **Logs**: Set an appropriate log level based on your needs. For debugging, use debug or trace.
4. **Additional Arguments**: Use surrealdb_additional_args to pass any additional CLI arguments required by your setup.

## Step 3: Commit and push

After creating and customising your workflow file, commit and push it to your repository:
```sh
git add .github/workflows/surrealdb-ci.yml
git commit -m "Add SurrealDB CI workflow"
git push origin main
```

## Step 4: Verify workflow execution

Go to your repository on GitHub and navigate to the "Actions" tab. You should see your workflow running when you push changes or create a pull request. Check the logs to verify that SurrealDB is starting up correctly and that all steps are executed successfully.

## Conclusion

Using the official GitHub Action for SurrealDB simplifies the process of setting up and running SurrealDB in your CI/CD pipeline. Customise the workflow as per your project requirements, and ensure you follow best practices for security and version control.
