Skip to content

Commit e8e364e

Browse files
authored
feat: ability to supply the API key in environment (#451)
1 parent e029fdf commit e8e364e

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

packages/cli/README.md

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ _**Note: The setup uses [mcp-remote](https://github.com/geelen/mcp-remote) as a
300300

301301
## Using in CI/CD Pipelines (Beta)
302302

303-
The Bucket CLI is designed to work seamlessly in CI/CD pipelines. For automated environments where interactive login is not possible, use the `--api-key` option.
303+
The Bucket CLI is designed to work seamlessly in CI/CD pipelines. For automated environments where interactive login is not possible, use the `--api-key` option,
304+
or specify the API key in `BUCKET_API_KEY` environment variable.
304305

305306
```bash
306307
# Generate types in CI/CD
@@ -315,31 +316,18 @@ npx bucket apps list --api-key $BUCKET_API_KEY
315316
- API keys are bound to one app only. Commands such as `apps list` will only return the bound app.
316317
- Store API keys securely using your CI/CD platform's secret management.
317318

318-
### Primary Use Case: Type Validation in CI/CD
319-
320-
Use the `--check-only` flag with `features types` to validate that generated types are up-to-date:
321-
322-
```bash
323-
# Check if types are current (exits with non-zero code if not)
324-
npx bucket features types --check-only --api-key $BUCKET_API_KEY --app-id ap123456789
325-
```
326-
327-
This is particularly useful for:
328-
329-
- **Pull Request validation**: Ensure developers have regenerated types after feature changes.
330-
- **Build verification**: Confirm types are synchronized before deployment.
331-
- **Automated quality checks**: Catch type drift in your CI pipeline.
332-
333319
Example CI workflow:
334320

335321
```yaml
336322
# GitHub Actions example
337-
- name: Validate Bucket types
338-
run: npx bucket features types --check-only --api-key ${{ secrets.BUCKET_API_KEY }}
339-
340-
- name: Generate types if validation fails
341-
if: failure()
323+
- name: Generate types
342324
run: npx bucket features types --api-key ${{ secrets.BUCKET_API_KEY }}
325+
326+
# GitHub Actions example (using environment):
327+
- name: Generate types (environment)
328+
run: npx bucket features types
329+
env:
330+
BUCKET_API_KEY: ${{ secrets.BUCKET_CI_API_KEY }}
343331
```
344332
345333
## Development

packages/cli/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,18 @@ async function main() {
4949

5050
// Pre-action hook
5151
program.hook("preAction", async (_, actionCommand) => {
52-
const { debug, baseUrl, apiUrl, apiKey } = program.opts<Options>();
52+
const {
53+
debug,
54+
baseUrl,
55+
apiUrl,
56+
apiKey: explicitApiKey,
57+
} = program.opts<Options>();
5358
const cleanedBaseUrl = stripTrailingSlash(baseUrl?.trim());
5459
const cleanedApiUrl = stripTrailingSlash(apiUrl?.trim());
5560

56-
if (apiKey) {
61+
const apiKey = explicitApiKey ?? process.env.BUCKET_API_KEY;
62+
63+
if (typeof apiKey === "string" && apiKey.length > 0) {
5764
console.info(
5865
chalk.yellow(
5966
"API key supplied. Using it instead of normal personal authentication.",

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bucketco/cli",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"packageManager": "[email protected]",
55
"description": "CLI for Bucket service",
66
"main": "./dist/index.js",

0 commit comments

Comments
 (0)