diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml new file mode 100644 index 0000000..5a05701 --- /dev/null +++ b/.github/workflows/pr-checks.yml @@ -0,0 +1,56 @@ +name: Pull Request Checks + +on: + pull_request: + branches: + - main + types: [opened, synchronize, reopened] + paths-ignore: + - 'docs/**' + - '*.md' + - 'README.md' + +jobs: + test_and_check_version: + name: Test and Check Version + runs-on: ubuntu-latest + + steps: + - name: Check out base branch + uses: actions/checkout@v4 + with: + ref: ${{ github.base_ref }} + path: 'main' + + - name: Check out PR branch + uses: actions/checkout@v4 + with: + path: 'pr' + + - name: Check for version increment + id: check_version + run: | + # Install jq, a tool for parsing JSON + sudo apt-get update && sudo apt-get install -y jq + + # Extract version from the main branch's package.json + main_version=$(jq -r .version main/package.json) + echo "Version on main: $main_version" + + # Extract version from the PR branch's package.json + pr_version=$(jq -r .version pr/package.json) + echo "Version on PR branch: $pr_version" + + if [ "$main_version" == "$pr_version" ]; then + echo "Version has not been incremented from main." + exit 1 + fi + + # The `sort -V` command handles version numbers correctly. + # It understands that 0.1.10 is greater than 0.1.9. + if [ "$(printf '%s\n' "$main_version" "$pr_version" | sort -V | head -n1)" != "$main_version" ]; then + echo "PR version ($pr_version) is not greater than main version ($main_version)." + exit 1 + fi + + echo "Version check passed!" diff --git a/package.json b/package.json index 40ebe7a..e8ab64f 100644 --- a/package.json +++ b/package.json @@ -43,5 +43,5 @@ "dev": "tsx watch src/index.ts", "format": "biome format --write" }, - "version": "0.0.6" + "version": "0.0.7" } diff --git a/src/overmind-client.ts b/src/overmind-client.ts index 70f58f0..859c234 100644 --- a/src/overmind-client.ts +++ b/src/overmind-client.ts @@ -27,6 +27,10 @@ type OvermindClientConfig = { appName?: string; }; +const LOCAL_API_KEY_PREFIX = "ovr_core_"; +const LOCAL_BASE_URL = "http://localhost:8000"; +const DEFAULT_BASE_URL = "https://api.overmindlab.ai"; + export class OvermindClient { public readonly appName: string; private version: string = version; @@ -36,14 +40,16 @@ export class OvermindClient { public experimentSlug?: string; constructor(config: OvermindClientConfig) { + // biome-ignore lint/style/noNonNullAssertion: must always set api key + this.apiKey = config.apiKey || process.env.OVERMIND_API_KEY!; + this.baseUrl = config.baseUrl || process.env.OVERMIND_API_URL || process.env.OVERMIND_TRACES_URL || - "https://api.overmindlab.ai"; - - // biome-ignore lint/style/noNonNullAssertion: must always set api key - this.apiKey = config.apiKey || process.env.OVERMIND_API_KEY!; + this.apiKey.startsWith(LOCAL_API_KEY_PREFIX) + ? LOCAL_BASE_URL + : DEFAULT_BASE_URL; this.appName = config.appName || "overmind-js"; if (!this.apiKey) { @@ -73,7 +79,7 @@ export class OvermindClient { const traceExporter = this.baseUrl ? new OTLPTraceExporter({ headers: { "X-API-TOKEN": this.apiKey }, - url: `${this.baseUrl}/api/v1/traces/create`, + url: `${this.baseUrl}/api/v1/traces`, }) : new ConsoleSpanExporter();