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
16 changes: 13 additions & 3 deletions .github/workflows/publish-release-from-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ jobs:
run: ./gradlew check

- name: Build release artifacts
run: ./gradlew build publishToMavenLocal -Pversion=${{ steps.determine-tag.outputs.tag }}
run: ./gradlew build publishToMavenLocal

- name: Find built artifacts
id: find-artifacts
run: |
VERSION="${{ steps.determine-tag.outputs.tag }}"
TAG="${{ steps.determine-tag.outputs.tag }}"
# Strip 'v' prefix to get the actual version used by Gradle
VERSION="${TAG#v}"

# Find the built JAR files (version includes 'v' prefix from generateVersion())
# Find the built JAR files (version does NOT include 'v' prefix)
MAIN_JAR=$(find build/libs -name "*-${VERSION}.jar" ! -name "*-sources.jar" ! -name "*-javadoc.jar" | head -1)
SOURCES_JAR=$(find build/libs -name "*-${VERSION}-sources.jar" | head -1)
JAVADOC_JAR=$(find build/libs -name "*-${VERSION}-javadoc.jar" | head -1)
Expand Down Expand Up @@ -163,3 +165,11 @@ jobs:
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
GPG_SIGNING_PASSWORD: ${{ secrets.GPG_SIGNING_PASSWORD }}

- name: Wait for Maven Central sync
run: |
TAG="${{ steps.determine-tag.outputs.tag }}"
# Strip 'v' prefix to get the Maven version
VERSION="${TAG#v}"
echo "Waiting for version $VERSION to sync to Maven Central. THIS CAN TAKE MANY HOURS! Godspeed"
./scripts/wait-for-maven.sh "$VERSION"
18 changes: 10 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ dependencies {
*
* This is written into braintrust.properties at build time and shipped into the distributed sdk jar
*
* - if we are on a tag (i.e. v0.0.3), use the tag
* - otherwise, use $mostRecentTag-$currentCommitSha
* - if we are on a tag (i.e. v0.0.3), use the tag WITHOUT the 'v' prefix (0.0.3)
* - otherwise, use $mostRecentTag-$currentCommitSha (without 'v' prefix)
*
* Additionally, if the git workspace is not clean, append -DIRTY to the version
*
* Examples
* - v0.0.3
* - v0.0.3-c4af682
* - v0.0.3-c4af682-DIRTY
* - 0.0.3 (from tag v0.0.3)
* - 0.0.3-c4af682 (from tag v0.0.3)
* - 0.0.3-c4af682-DIRTY
*/
def generateVersion() {
// Check if workspace is clean
Expand Down Expand Up @@ -125,8 +125,8 @@ def generateVersion() {

def version
if (currentTag != null) {
// We're on a tag, use the tag name
version = currentTag
// We're on a tag, use the tag name (strip 'v' prefix if present)
version = currentTag.startsWith('v') ? currentTag.substring(1) : currentTag
} else {
// Not on a tag, find the most recent tag
def mostRecentTag = null
Expand All @@ -142,7 +142,9 @@ def generateVersion() {
}

if (mostRecentTag != null) {
version = "${mostRecentTag}-${gitSha}"
// Strip 'v' prefix if present
def cleanTag = mostRecentTag.startsWith('v') ? mostRecentTag.substring(1) : mostRecentTag
version = "${cleanTag}-${gitSha}"
} else {
version = gitSha
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -euo pipefail

Expand Down
118 changes: 118 additions & 0 deletions scripts/wait-for-maven.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env bash

set -euo pipefail

# Script to wait for a Maven artifact to become available on Maven Central
# Usage: ./scripts/wait-for-maven.sh <version>
# Example: ./scripts/wait-for-maven.sh 0.0.3

VERSION="${1:-}"

if [[ -z "$VERSION" ]]; then
echo "Error: Version is required" >&2
echo "Usage: $0 <version>" >&2
echo "Example: $0 0.0.3" >&2
exit 1
fi

# Configuration
GROUP_ID="dev.braintrust"
ARTIFACT_ID="braintrust-sdk-java"
MAX_DURATION_SECONDS=18000 # 5 hours
SLEEP_DURATION=300 # 5 minutes

# Convert group ID to path format (dev.braintrust -> dev/braintrust)
GROUP_PATH="${GROUP_ID//./\/}"

# Maven Central artifact URL
MAVEN_CENTRAL_URL="https://repo1.maven.org/maven2/${GROUP_PATH}/${ARTIFACT_ID}/${VERSION}/${ARTIFACT_ID}-${VERSION}.pom"

echo "================================================"
echo " Waiting for Maven Central"
echo "================================================"
echo "Group ID: ${GROUP_ID}"
echo "Artifact ID: ${ARTIFACT_ID}"
echo "Version: ${VERSION}"
echo "Max time: 5 hours"
echo ""
echo "Checking: ${MAVEN_CENTRAL_URL}"
echo ""

# Record start time
START_TIME=$(date +%s)
attempt=0

while true; do
# Calculate elapsed time
CURRENT_TIME=$(date +%s)
ELAPSED_SECONDS=$((CURRENT_TIME - START_TIME))
ELAPSED_MINUTES=$((ELAPSED_SECONDS / 60))

# Check if we've exceeded the max duration
if [[ $ELAPSED_SECONDS -ge $MAX_DURATION_SECONDS ]]; then
break
fi

attempt=$((attempt + 1))
echo "[Attempt ${attempt}] Checking Maven Central... (${ELAPSED_MINUTES} minutes elapsed)"

# Check if the artifact exists (HTTP 200)
http_code=$(curl -s -o /dev/null -w "%{http_code}" "${MAVEN_CENTRAL_URL}")

if [[ "$http_code" == "200" ]]; then
echo ""
echo "✓ Success! Artifact is available on Maven Central"
echo ""

# Trigger javadoc.io to update
JAVADOC_URL="https://javadoc.io/doc/${GROUP_ID}/${ARTIFACT_ID}/${VERSION}"
echo "Triggering javadoc.io update..."
echo "URL: ${JAVADOC_URL}"

# Fire and forget - we don't wait for javadoc.io
curl -s -o /dev/null "${JAVADOC_URL}" || true

echo ""
echo "================================================"
echo " Maven Central Sync Complete!"
echo "================================================"
echo "Maven Central: https://central.sonatype.com/artifact/${GROUP_ID}/${ARTIFACT_ID}/${VERSION}"
echo "Javadoc: ${JAVADOC_URL}"
echo ""

exit 0
elif [[ "$http_code" == "404" ]]; then
echo " → Not found yet (HTTP 404)"
else
echo " → Unexpected HTTP status: ${http_code}"
fi

# Calculate remaining time
REMAINING_SECONDS=$((MAX_DURATION_SECONDS - ELAPSED_SECONDS))

# If we have time left, sleep for 5 minutes (or less if timeout is near)
if [[ $REMAINING_SECONDS -gt 0 ]]; then
SLEEP_TIME=$SLEEP_DURATION
if [[ $REMAINING_SECONDS -lt $SLEEP_DURATION ]]; then
SLEEP_TIME=$REMAINING_SECONDS
fi
echo " → Sleeping for $((SLEEP_TIME / 60)) minutes..."
echo ""
sleep "$SLEEP_TIME"
fi
done

echo ""
echo "================================================"
echo " Timeout!"
echo "================================================"
echo "Artifact did not appear on Maven Central after 5 hours."
echo "This might indicate a publishing issue."
echo ""
echo "Please check:"
echo "1. Sonatype Central Portal: https://central.sonatype.com/publishing"
echo "2. Build logs for errors"
echo "3. Maven Central manually: ${MAVEN_CENTRAL_URL}"
echo ""

exit 1