Skip to content

Commit 9dfa8bd

Browse files
[feat] replaced our wonky env setup with infisical (#170)
Co-authored-by: Codebuff <noreply@codebuff.com>
1 parent 72fbb9d commit 9dfa8bd

File tree

98 files changed

+625
-715
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+625
-715
lines changed

.env.example

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 88 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Tests are parallelized to run faster by splitting them into separate jobs that run concurrently
33
#
44
# See the workflow visualization in knowledge file
5-
# ```
65

76
name: CI
87

@@ -12,11 +11,6 @@ on:
1211
pull_request:
1312
branches: ['main']
1413

15-
env:
16-
CODEBUFF_GITHUB_ACTIONS: 'true'
17-
NEXT_PUBLIC_CB_ENVIRONMENT: 'local'
18-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19-
2014
# Define reusable job template
2115
jobs:
2216
build:
@@ -44,14 +38,28 @@ jobs:
4438
- name: Install dependencies
4539
run: bun install --frozen-lockfile
4640

47-
- name: Set Environment Variables
41+
- name: Set environment variables
42+
env:
43+
SECRETS_CONTEXT: ${{ toJSON(secrets) }}
4844
run: |
49-
echo "${{ secrets.ENV_LOCAL }}" > .env.local
45+
VAR_NAMES=$(node scripts/generate-ci-env.js)
46+
echo "$SECRETS_CONTEXT" | jq -r --argjson vars "$VAR_NAMES" '
47+
to_entries | .[] | select(.key as $k | $vars | index($k)) | .key + "=" + .value
48+
' >> $GITHUB_ENV
49+
echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV
50+
echo "NEXT_PUBLIC_CB_ENVIRONMENT=test" >> $GITHUB_ENV
51+
echo "NEXT_PUBLIC_INFISICAL_UP=true" >> $GITHUB_ENV
52+
echo "CODEBUFF_GITHUB_TOKEN=${{ secrets.CODEBUFF_GITHUB_TOKEN }}" >> $GITHUB_ENV
5053
5154
- name: Build and typecheck
5255
run: |
5356
bun run build
5457
58+
# - name: Open interactive debug shell
59+
# if: ${{ failure() }}
60+
# uses: mxschmitt/action-tmate@v3
61+
# timeout-minutes: 15 # optional guard
62+
5563
# Template for test jobs
5664
test:
5765
needs: build
@@ -87,18 +95,87 @@ jobs:
8795
- name: Install dependencies
8896
run: bun install --frozen-lockfile
8997

90-
- name: Set Environment Variables
98+
- name: Set environment variables
99+
env:
100+
SECRETS_CONTEXT: ${{ toJSON(secrets) }}
91101
run: |
92-
echo "${{ secrets.ENV_LOCAL }}" > .env.local
102+
VAR_NAMES=$(node scripts/generate-ci-env.js)
103+
echo "$SECRETS_CONTEXT" | jq -r --argjson vars "$VAR_NAMES" '
104+
to_entries | .[] | select(.key as $k | $vars | index($k)) | .key + "=" + .value
105+
' >> $GITHUB_ENV
106+
echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV
107+
echo "NEXT_PUBLIC_CB_ENVIRONMENT=test" >> $GITHUB_ENV
108+
echo "NEXT_PUBLIC_INFISICAL_UP=true" >> $GITHUB_ENV
109+
echo "CODEBUFF_GITHUB_TOKEN=${{ secrets.CODEBUFF_GITHUB_TOKEN }}" >> $GITHUB_ENV
93110
94111
- name: Run ${{ matrix.package }} tests
95112
uses: nick-fields/retry@v3
96113
with:
97114
timeout_minutes: 10
98115
max_attempts: 5
99-
command: cd ${{ matrix.package }} && bun test $(find src -name *.test.ts)
116+
command: cd ${{ matrix.package }} && bun test $(find src -name '*.test.ts' ! -name '*.integration.test.ts')
100117

101118
# - name: Open interactive debug shell
102119
# if: ${{ failure() }}
103120
# uses: mxschmitt/action-tmate@v3
104121
# timeout-minutes: 15 # optional guard
122+
123+
# Template for test jobs
124+
# test-integration:
125+
# needs: build
126+
# strategy:
127+
# matrix:
128+
# package: [npm-app, backend, common]
129+
# include:
130+
# - package: npm-app
131+
# - package: backend
132+
# - package: common
133+
# name: test-integration-${{ matrix.package }}
134+
# runs-on: ubuntu-latest
135+
# steps:
136+
# - name: Checkout repository
137+
# uses: actions/checkout@v3
138+
139+
# - name: Set up Bun
140+
# uses: oven-sh/setup-bun@v2
141+
# with:
142+
# bun-version: '1.2.12'
143+
144+
# - name: Cache dependencies
145+
# uses: actions/cache@v3
146+
# with:
147+
# path: |
148+
# node_modules
149+
# */node_modules
150+
# packages/*/node_modules
151+
# key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lockb') }}
152+
# restore-keys: |
153+
# ${{ runner.os }}-deps-
154+
155+
# - name: Install dependencies
156+
# run: bun install --frozen-lockfile
157+
158+
# - name: Set environment variables
159+
# env:
160+
# SECRETS_CONTEXT: ${{ toJSON(secrets) }}
161+
# run: |
162+
# VAR_NAMES=$(node scripts/generate-ci-env.js)
163+
# echo "$SECRETS_CONTEXT" | jq -r --argjson vars "$VAR_NAMES" '
164+
# to_entries | .[] | select(.key as $k | $vars | index($k)) | .key + "=" + .value
165+
# ' >> $GITHUB_ENV
166+
# echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV
167+
# echo "NEXT_PUBLIC_CB_ENVIRONMENT=test" >> $GITHUB_ENV
168+
# echo "NEXT_PUBLIC_INFISICAL_UP=true" >> $GITHUB_ENV
169+
# echo "CODEBUFF_GITHUB_TOKEN=${{ secrets.CODEBUFF_GITHUB_TOKEN }}" >> $GITHUB_ENV
170+
171+
# - name: Run ${{ matrix.package }} tests
172+
# uses: nick-fields/retry@v3
173+
# with:
174+
# timeout_minutes: 10
175+
# max_attempts: 5
176+
# command: cd ${{ matrix.package }} && bun test $(find src -name '*.integration.test.ts')
177+
178+
# # - name: Open interactive debug shell
179+
# # if: ${{ failure() }}
180+
# # uses: mxschmitt/action-tmate@v3
181+
# # timeout-minutes: 15 # optional guard

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ tags
1212
node_modules
1313
dev
1414
dist
15+
dist-env
1516
tsconfig.tsbuildinfo
1617
.manicode
1718
__mock-projects__

.infisical.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"workspaceId": "d1bc0497-df33-483e-b55c-0fd3eaca705f",
3+
"defaultEnvironment": "dev",
4+
"gitBranchToEnvironmentMapping": null
5+
}

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ If you want to set up Codebuff for local development:
6666

6767
1. Clone the repository and navigate to the project directory.
6868

69-
2. Create a new `.env` file in the root directory. Copy the `.env.example` file and fill in the values for your environment.
69+
2. Set up your [Infisical](https://infisical.com/) user. Ask one of us to add you to the project. Then:
70+
1. Install the Infisical CLI: `npm install -g @infisical/cli`
71+
2. Log in to Infisical: `infisical login`
72+
3. When prompted, select the "US" region.
73+
4. After logging in, you can run any service. Infisical will automatically inject the necessary environment variables.
7074

7175
3. Install dependencies and build packages in order:
7276

backend/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
1313
moduleNameMapper: {
1414
'^common(.*)$': '<rootDir>/../common/src$1',
15+
'^@/env$': '<rootDir>/../env.ts',
1516
},
1617
moduleDirectories: ['node_modules', '../node_modules'],
1718
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],

backend/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"main": "dist/index.js",
66
"license": "UNLICENSED",
77
"scripts": {
8-
"start": "bun run -r tsconfig-paths/register src/index.ts",
9-
"dev": "bun --hot run -r tsconfig-paths/register src/index.ts",
8+
"start": "infisical run --log-level=warn -- bun src/index.ts",
9+
"dev": "infisical run --log-level=warn -- bun src/index.ts",
1010
"build": "tsc --build",
1111
"typecheck-this-package": "tsc --noEmit && tsc-alias",
1212
"typecheck": "bun run --cwd ../common build && bun run typecheck-this-package",
@@ -20,7 +20,6 @@
2020
"@codebuff/internal": "workspace:*",
2121
"@google-cloud/vertexai": "1.10.0",
2222
"@google/generative-ai": "0.24.1",
23-
"@t3-oss/env-core": "0.11.1",
2423
"ai": "4.3.16",
2524
"common": "workspace:*",
2625
"cors": "^2.8.5",
@@ -35,8 +34,7 @@
3534
"postgres": "3.4.4",
3635
"posthog-node": "^4.14.0",
3736
"ts-pattern": "5.3.1",
38-
"ws": "8.18.0",
39-
"zod": "3.23.8"
37+
"ws": "8.18.0"
4038
},
4139
"devDependencies": {
4240
"@types/bun": "^1.1.16",

backend/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
}
2020
}
2121
},
22-
"implicitDependencies": ["common"]
22+
"implicitDependencies": ["common", "@codebuff/internal"]
2323
}

backend/src/env.mjs

Lines changed: 0 additions & 45 deletions
This file was deleted.

backend/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from './admin/relabelRuns'
1212
import usageHandler from './api/usage'
1313
import { isRepoCoveredHandler } from './api/org'
14-
import { env } from './env.mjs'
14+
import { env } from '@/env'
1515
import { checkAdmin } from './util/check-auth'
1616
import { logger } from './util/logger'
1717
import {
@@ -103,7 +103,7 @@ let shutdownInProgress = false
103103
// Graceful shutdown handler for both SIGTERM and SIGINT
104104
function handleShutdown(signal: string) {
105105
flushAnalytics()
106-
if (process.env.NEXT_PUBLIC_CB_ENVIRONMENT === 'local') {
106+
if (env.NEXT_PUBLIC_CB_ENVIRONMENT === 'dev') {
107107
console.log('\nLocal environment detected. Not awaiting client exits.')
108108
server.close((error) => {
109109
console.log('Received error closing server', { error })

0 commit comments

Comments
 (0)