Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ Map branches to **existing Rivet Cloud clusters**. Optionally deploy every other

## Setup

Add these GitHub Actions secrets:
Rivet Cloud authenticates the workflow with GitHub's OIDC token, so no Rivet secret is stored in GitHub:

1. In the cluster's settings, add a GitHub Actions trust for the repository and the branch or environment that deploys, with the deploy scope.
2. Grant the job `id-token: write`, as in the workflow below.

Each run exchanges its OIDC token for a credential that lasts 15 minutes and has only the trust's scopes.

Alternatively, set `rivet-token` to a Rivet Cloud credential with cluster deployment access (not an Engine admin token). The action passes it to the [Rivet CLI](https://rivet.dev/docs/cli/) through `RIVET_CLOUD_TOKEN`.

For Fly previews, add this GitHub Actions secret:

- `RIVET_CLOUD_TOKEN`: a Rivet Cloud credential with cluster deployment access in your organization. An Engine admin token cannot deploy builds. The action uses the [Rivet CLI](https://rivet.dev/docs/cli/) and passes this secret through `RIVET_CLOUD_TOKEN`.
- `FLY_API_TOKEN`: a Fly organization token that can create, deploy, and delete preview apps. Only needed for Fly previews.

Use the published CLI with v3 support, for example `rivet-cli-version: '3.0.0'`.
Expand Down Expand Up @@ -34,12 +42,12 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: rivet-dev/deploy-action@v2.0.0-rc.1
with:
rivet-token: ${{ secrets.RIVET_CLOUD_TOKEN }}
rivet-cli-version: '3.0.0'
rivet-org: my-org
branch-clusters: |
Expand Down Expand Up @@ -74,7 +82,8 @@ Fly creates one Machine with a 20 GiB persistent volume. Increasing `fly-volume-
| Input | Default | Purpose |
| --- | --- | --- |
| `branch-clusters` | `{}` | Branch → cluster mapping |
| `rivet-token`, `rivet-org` | — | Required for mapped Cloud deployments |
| `rivet-org` | — | Required for mapped Cloud deployments |
| `rivet-token` | — | Cloud credential; omit to use the cluster's GitHub Actions trust (`id-token: write`) |
| `rivet-cli-version` | `latest` | CLI release with v3 cluster support; pin for reproducibility |
| `rivet-cli-path` | — | Use a preinstalled v3 CLI instead of downloading one |
| `docker-build-path` | `.` | Build context, relative to checkout |
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inputs:
description: 'JSON map of exact branch names to cluster names or {cluster, region, pool} objects'
default: '{}'
rivet-token:
description: 'Rivet Cloud credential with cluster deployment access (not an Engine admin token)'
description: 'Rivet Cloud credential with cluster deployment access (not an Engine admin token). Omit it to use the cluster''s GitHub Actions trust; needs `id-token: write`'
rivet-org:
description: 'Organization slug for mapped Rivet Cloud clusters'
rivet-cli-version:
Expand Down
3 changes: 2 additions & 1 deletion src/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export async function deployCloud(
target: Cluster,
command: Run = run,
): Promise<{ buildId: string; url: string }> {
if (!config.cloudToken || !config.cloudOrg) throw new Error("Cloud deployments need rivet-token and rivet-org; use a Cloud deployment credential, not an Engine admin token");
if (!config.cloudOrg) throw new Error("Cloud deployments need rivet-org");
if (!config.cloudToken && !config.githubOidc) throw new Error("Cloud deployments need a Cloud deployment credential: grant the workflow `id-token: write` and add a GitHub Actions trust to the cluster, or set rivet-token (not an Engine admin token)");
const program = config.cliPath || "bun";
const prefix = config.cliPath ? [] : ["x", "--package", `@rivetkit/cli@${config.cliVersion}`, "rivet"];
const options = { cwd: config.workspace, env: { RIVET_CLOUD_TOKEN: config.cloudToken, NO_COLOR: "1" } };
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export function readConfig(env: NodeJS.ProcessEnv, event: Event) {
cliVersion,
cliPath: env.RIVET_CLI_PATH || "",
cloudToken: env.RIVET_CLOUD_TOKEN || "",
// Set only when the workflow grants `id-token: write`.
githubOidc: !!env.ACTIONS_ID_TOKEN_REQUEST_URL,
cloudOrg: env.RIVET_ORG || "",
githubToken: env.GITHUB_TOKEN || "",
};
Expand Down
13 changes: 12 additions & 1 deletion tests/cloud.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,18 @@ test('preinstalled CLI bypasses package installation and a failed rollout is not
});

test('missing deployment credentials fail without starting the CLI', async () => {
await expect(deployCloud({ ...config, cloudToken: '' }, { cluster: 'production' }, async () => { throw new Error('must not start'); })).rejects.toThrow('Cloud deployment credential');
await expect(deployCloud({ ...config, cloudToken: '', githubOidc: false }, { cluster: 'production' }, async () => { throw new Error('must not start'); })).rejects.toThrow('Cloud deployment credential');
});

test('without rivet-token the CLI exchanges the GitHub OIDC token', async () => {
const { buildId } = await deployCloud({ ...config, cloudToken: '', githubOidc: true }, { cluster: 'production' }, async (_program, args, options) => {
expect(options?.env?.RIVET_CLOUD_TOKEN).toBe('');
if (args.includes('--help')) return '--cluster --build-context';
if (args.includes('/v2/clusters/{cluster}/regions')) return JSON.stringify({ items: [{ region: 'one' }] });
if (args.includes('deploy')) return 'test-build\n';
return JSON.stringify({ build_id: 'test-build', endpoints: { public: 'https://app.example.test' } });
});
expect(buildId).toBe('test-build');
});

test('concurrent pool changes cannot produce a misleading success URL', async () => {
Expand Down
Loading