> ## Documentation Index
> Fetch the complete documentation index at: https://buildbuddy-io-buildbuddy.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# RBE with GitHub Actions

> Integrate BuildBuddy Remote Build Execution with your GitHub Actions CI pipeline

Using BuildBuddy with Github Actions is an easy way to get started using BuildBuddy with a CI system. For an even easier way to get started, see the [BuildBuddy Workflows Setup Guide](https://buildbuddy-io-buildbuddy.mintlify.site/workflows-setup.md).

## Setup instructions

There are three steps:

**1. Create a workflow file**

Set up your GitHub Actions workflow configuration

**2. Update your .bazelrc**

Add BuildBuddy configuration to your Bazel settings

**3. Set up GitHub Secret**

Store your BuildBuddy API key securely in GitHub

### Workflow file

All you have to do is create a file `.github/workflows/main.yaml`

```yaml .github/workflows/main.yaml theme={null}
name: CI

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Install bazelisk
        run: |
          curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.1.0/bazelisk-linux-amd64"
          mkdir -p "${GITHUB_WORKSPACE}/bin/"
          mv bazelisk-linux-amd64 "${GITHUB_WORKSPACE}/bin/bazel"
          chmod +x "${GITHUB_WORKSPACE}/bin/bazel"
      - name: Build
        run: |
          "${GITHUB_WORKSPACE}/bin/bazel" build \
              --config=ci \
              --remote_header=x-buildbuddy-api-key=${{ secrets.BUILDBUDDY_ORG_API_KEY }} \
              //...
      - name: Test
        run: |
          "${GITHUB_WORKSPACE}/bin/bazel" test \
              --config=ci \
              --remote_header=x-buildbuddy-api-key=${{ secrets.BUILDBUDDY_ORG_API_KEY }} \
              //...
```

### Updating your .bazelrc

You'll then need to add the following configuration to your `.bazelrc`

```bash .bazelrc theme={null}
build:ci --build_metadata=ROLE=CI
build:ci --bes_results_url=https://app.buildbuddy.io/invocation/
build:ci --bes_backend=grpcs://remote.buildbuddy.io
```

### Github secrets

Finally, you'll need to create a GitHub Secret containing your BuildBuddy API Key.

**1. Get your API key**

Log in to your [BuildBuddy account](https://app.buildbuddy.io) and visit your [Quickstart page](https://app.buildbuddy.io/docs/setup/) to get your BuildBuddy API key.

**2. Add secret to GitHub**

Add your BuildBuddy API Key as GitHub Secret named `BUILDBUDDY_ORG_API_KEY`. For more information on setting up Github Secrets, [click here](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets).

## More

### Github commit statuses

If you'd like BuildBuddy to publish commit statuses to your repo, you can do so by [logging in](https://app.buildbuddy.io) and clicking `Link Github Account` in the user menu in the top right.

### Visibility

By default, authenticated builds are only visible to members of your BuildBuddy organization. If you'd like your BuildBuddy results pages to be visible to members outside of your organization, you can add the following line to your `.bazelrc`:

```bash .bazelrc theme={null}
build:ci --build_metadata=VISIBILITY=PUBLIC
```

### Remote build execution

If you'd like to use BuildBuddy's Remote Build Execution capabilities in your CI workflow, you can add the following lines to your `.bazelrc`:

```bash .bazelrc theme={null}
build:remote --remote_cache=grpcs://remote.buildbuddy.io
build:remote --remote_executor=grpcs://remote.buildbuddy.io
build:remote --remote_upload_local_results
build:remote --host_platform=@buildbuddy_toolchain//:platform
build:remote --platforms=@buildbuddy_toolchain//:platform
build:remote --crosstool_top=@buildbuddy_toolchain//:toolchain
build:remote --jobs=100

build:ci --config=remote
```

And the following lines to your `WORKSPACE` file:

```python WORKSPACE theme={null}
http_archive(
    name = "io_buildbuddy_buildbuddy_toolchain",
    integrity = "sha256-5zVDos35dx9w9zmrcenyTg8tKwSg1/nUAZPLK8mo5KI=",
    urls = ["https://github.com/buildbuddy-io/buildbuddy-toolchain/releases/download/v0.0.3/buildbuddy-toolchain-v0.0.3.tar.gz"],
)

load("@io_buildbuddy_buildbuddy_toolchain//:deps.bzl", "buildbuddy_deps")

buildbuddy_deps()

load("@io_buildbuddy_buildbuddy_toolchain//:rules.bzl", "buildbuddy")

buildbuddy(name = "buildbuddy_toolchain")
```

> [!NOTE]
>
> If you're using Java, or have a complex project - you'll likely need to configure the toolchain flags a bit. For more information, see our [Remote Build Execution guide](https://buildbuddy-io-buildbuddy.mintlify.site/rbe-setup.md).


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