Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(ci): make SDK generation reruns safe (#15574)

Hassieb Pakzad8242934a3bd1
diff --git a/.github/workflows/sdk-api-spec.yml b/.github/workflows/sdk-api-spec.yml
index 7c53ac4187..d566b25451 100644
--- a/.github/workflows/sdk-api-spec.yml
+++ b/.github/workflows/sdk-api-spec.yml
@@ -88,7 +88,7 @@ jobs:
fi
# Create new branch and commit changes
- BRANCH_NAME="api-spec-bot-${GITHUB_SHA::7}"
+ BRANCH_NAME="api-spec-bot-${GITHUB_SHA::7}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
git checkout -b "$BRANCH_NAME"
git add .
git commit -m "feat(api): update API spec from langfuse/langfuse ${GITHUB_SHA::7}"
@@ -149,7 +149,7 @@ jobs:
fi
# Create new branch and commit changes
- BRANCH_NAME="api-spec-bot-${GITHUB_SHA::7}"
+ BRANCH_NAME="api-spec-bot-${GITHUB_SHA::7}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
git checkout -b "$BRANCH_NAME"
git add .
git commit -m "feat(api): update API spec from langfuse/langfuse ${GITHUB_SHA::7}" --no-verify
@@ -194,13 +194,6 @@ jobs:
"$GIT_BIN" -C "$PUSH_REPO" init -q
"$GIT_BIN" -C "$PUSH_REPO" fetch --no-tags "$BUNDLE_PATH" "$BRANCH_NAME:refs/heads/$BRANCH_NAME"
- # Close existing api-spec-bot PRs
- "$GH_BIN" pr list --repo langfuse/langfuse-python --author langfuse-bot --state open --json number --jq '.[].number' | while read -r pr_number; do
- if [ -n "$pr_number" ]; then
- "$GH_BIN" pr close --repo langfuse/langfuse-python "$pr_number"
- fi
- done
-
# Resolve the reviewer before pushing so a transient GitHub API failure cannot orphan a branch.
ORIGINAL_AUTHOR="$("$GH_BIN" api "repos/langfuse/langfuse/commits/${GITHUB_SHA}" --jq '.author.login // empty')"
REVIEWER_ARGS=()
@@ -216,12 +209,20 @@ jobs:
-c core.hooksPath=/dev/null \
push "https://x-access-token:${GH_TOKEN}@github.com/langfuse/langfuse-python.git" "$BRANCH_NAME"
- "$GH_BIN" pr create \
+ NEW_PR_URL="$("$GH_BIN" pr create \
--repo langfuse/langfuse-python \
--head "$BRANCH_NAME" \
--title "feat(api): update API spec from langfuse/langfuse ${GITHUB_SHA::7}" \
--body "" \
- "${REVIEWER_ARGS[@]}"
+ "${REVIEWER_ARGS[@]}")"
+ NEW_PR_NUMBER="${NEW_PR_URL##*/}"
+
+ # Only retire stale bot PRs after their replacement exists.
+ "$GH_BIN" pr list --repo langfuse/langfuse-python --author langfuse-bot --state open --json number --jq '.[].number' | while read -r pr_number; do
+ if [ -n "$pr_number" ] && [ "$pr_number" != "$NEW_PR_NUMBER" ]; then
+ "$GH_BIN" pr close --repo langfuse/langfuse-python "$pr_number"
+ fi
+ done
push-typescript-sdk:
needs: generate-sdk-api-specs
@@ -250,13 +251,6 @@ jobs:
"$GIT_BIN" -C "$PUSH_REPO" init -q
"$GIT_BIN" -C "$PUSH_REPO" fetch --no-tags "$BUNDLE_PATH" "$BRANCH_NAME:refs/heads/$BRANCH_NAME"
- # Close existing api-spec-bot PRs
- "$GH_BIN" pr list --repo langfuse/langfuse-js --author langfuse-bot --state open --json number --jq '.[].number' | while read -r pr_number; do
- if [ -n "$pr_number" ]; then
- "$GH_BIN" pr close --repo langfuse/langfuse-js "$pr_number"
- fi
- done
-
# Resolve the reviewer before pushing so a transient GitHub API failure cannot orphan a branch.
ORIGINAL_AUTHOR="$("$GH_BIN" api "repos/langfuse/langfuse/commits/${GITHUB_SHA}" --jq '.author.login // empty')"
REVIEWER_ARGS=()
@@ -272,12 +266,20 @@ jobs:
-c core.hooksPath=/dev/null \
push "https://x-access-token:${GH_TOKEN}@github.com/langfuse/langfuse-js.git" "$BRANCH_NAME"
- "$GH_BIN" pr create \
+ NEW_PR_URL="$("$GH_BIN" pr create \
--repo langfuse/langfuse-js \
--head "$BRANCH_NAME" \
--title "feat(api): update API spec from langfuse/langfuse ${GITHUB_SHA::7}" \
--body "" \
- "${REVIEWER_ARGS[@]}"
+ "${REVIEWER_ARGS[@]}")"
+ NEW_PR_NUMBER="${NEW_PR_URL##*/}"
+
+ # Only retire stale bot PRs after their replacement exists.
+ "$GH_BIN" pr list --repo langfuse/langfuse-js --author langfuse-bot --state open --json number --jq '.[].number' | while read -r pr_number; do
+ if [ -n "$pr_number" ] && [ "$pr_number" != "$NEW_PR_NUMBER" ]; then
+ "$GH_BIN" pr close --repo langfuse/langfuse-js "$pr_number"
+ fi
+ done
notify-slack-on-failure:
needs: