Skip to content
Merged
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
45 changes: 45 additions & 0 deletions .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: integration-tests

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
open-pr:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout parent repository
uses: actions/checkout@v4
with:
repository: braintrustdata/braintrust
path: braintrust
token: ${{ secrets.CROSS_REPO_TOKEN }}
fetch-depth: 0

- name: Configure Git in parent repository
run: |
cd braintrust
git config user.name "GitHub Actions Bot"
git config user.email "[email protected]"

- name: Initialize and update SDK submodule
run: |
cd braintrust
git submodule init
git submodule update --init --recursive
cd sdk
git remote set-url origin https://github.com/braintrustdata/braintrust-sdk.git
git fetch origin
git checkout ${{ github.event.pull_request.head.sha }}

- name: Create integration test PR
run: ./braintrust/sdk/scripts/create-integration-test-pr.sh
env:
GH_TOKEN: ${{ secrets.CROSS_REPO_TOKEN }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
COMMIT_HASH: ${{ github.event.pull_request.head.sha }}
PARENT_REPO_PATH: braintrust
1 change: 1 addition & 0 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
# Automatically activate our virtual environment
_.python.venv = "venv"


# See env.example to configure API keys.
_.file = ".env"
96 changes: 96 additions & 0 deletions scripts/create-integration-test-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash

# This script creates or updates a PR in the braintrust repository to update the SDK submodule.
#
# Required environment variables:
# - GH_TOKEN: GitHub token with permissions to create PRs in the braintrust repository
# - BRANCH_NAME: Name of the source branch in the SDK repository (e.g. "feature/new-feature")
# - COMMIT_HASH: The commit hash from the SDK repository to update the submodule to
# - PARENT_REPO_PATH: Path to the parent repository
#
# Usage:
# export GH_TOKEN=<github_token>
# export BRANCH_NAME=<branch_name>
# export COMMIT_HASH=<commit_hash>
# export PARENT_REPO_PATH=<parent_repo_path>
# ./scripts/create-integration-test-pr.sh

set -euo pipefail

# Check for required environment variables
if [ -z "${GH_TOKEN:-}" ]; then
echo "Error: GH_TOKEN environment variable is required"
exit 1
fi

if [ -z "${BRANCH_NAME:-}" ]; then
echo "Error: BRANCH_NAME environment variable is required"
exit 1
fi

if [ -z "${COMMIT_HASH:-}" ]; then
echo "Error: COMMIT_HASH environment variable is required"
exit 1
fi

if [ -z "${PARENT_REPO_PATH:-}" ]; then
echo "Error: PARENT_REPO_PATH environment variable is required"
exit 1
fi

# Generate the parent branch name
PARENT_BRANCH_NAME="${BRANCH_NAME}-sdk-gh-action"

cd "$PARENT_REPO_PATH"

# Create or switch to branch in parent repository
if git ls-remote --heads origin "$PARENT_BRANCH_NAME" | grep -q "$PARENT_BRANCH_NAME"; then
git checkout "$PARENT_BRANCH_NAME"
git pull origin "$PARENT_BRANCH_NAME"
else
git checkout -b "$PARENT_BRANCH_NAME" origin/main
fi

# Update submodule reference
git submodule init
git submodule update --init --recursive
cd sdk
git remote set-url origin https://github.com/braintrustdata/braintrust-sdk.git
git fetch origin

# Create a temporary branch to avoid detached HEAD state
git checkout -b temp_branch
git fetch origin "$COMMIT_HASH"
git checkout "$COMMIT_HASH"

# Get commit author and PR number
COMMIT_AUTHOR=$(git log -1 --format='%an <%ae>')
PR_NUMBER=$(gh pr list --head "$BRANCH_NAME" --json number --jq '.[0].number')
SDK_PR_URL="https://github.com/braintrustdata/braintrust-sdk/pull/${PR_NUMBER}"

cd ..
git add sdk

# Only commit if there are changes
if ! git diff --staged --quiet; then
git commit -m "Update SDK submodule to latest commit from $BRANCH_NAME"
git push origin "$PARENT_BRANCH_NAME"
fi

# Check for existing PR
PR_EXISTS=$(gh pr list --state open --head "$PARENT_BRANCH_NAME" --json number | jq 'length')

# Create Pull Request if not exists
if [ "$PR_EXISTS" = "0" ]; then

gh pr create \
--title "[bot] Update SDK submodule to $BRANCH_NAME" \
--body "This PR updates the SDK submodule to point to the latest commit from the branch $BRANCH_NAME.

Author: $COMMIT_AUTHOR
SDK PR: $SDK_PR_URL

Created automatically by GitHub Actions." \
--base main \
--head "$PARENT_BRANCH_NAME"
fi