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
14 changes: 4 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,12 @@ commands:
- run:
name: Determine target branch for this pipeline
command: |
TARGET_BRANCH=""
if [ -n "${CIRCLE_PULL_REQUEST:-}" ]; then
TARGET_BRANCH=$(curl -s "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PULL_REQUEST##*/}" | jq -r .base.ref)
fi

# Fallbacks when not a PR or API did not return a branch
if [ -z "$TARGET_BRANCH" ] || [ "$TARGET_BRANCH" = "null" ]; then
TARGET_BRANCH="<< pipeline.git.branch >>"
fi
# Use the get-target-branch.sh script
source scripts/ops/get-target-branch.sh

echo "Resolved TARGET_BRANCH=$TARGET_BRANCH"
# Make TARGET_BRANCH available to subsequent steps
echo "export TARGET_BRANCH=$TARGET_BRANCH" >> "$BASH_ENV"
working_directory: packages/contracts-bedrock

setup-features:
description: "Set up dev and system feature environment variables. Features are auto-classified based on system_features registry."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
# shellcheck source=/dev/null
source "$SCRIPT_DIR/utils/semver-utils.sh"

# Determine the target branch.
# shellcheck source=/dev/null
source "$SCRIPT_DIR/../ops/get-target-branch.sh"

# Path to semver-lock.json.
SEMVER_LOCK="snapshots/semver-lock.json"

Expand All @@ -31,7 +35,6 @@ temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT

# Exit early if semver-lock.json has not changed.
TARGET_BRANCH="${TARGET_BRANCH:-develop}"
UPSTREAM_REF="origin/${TARGET_BRANCH}"
if ! {
git diff "$UPSTREAM_REF"...HEAD --name-only
Expand Down
15 changes: 15 additions & 0 deletions packages/contracts-bedrock/scripts/ops/get-target-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Determines the PR target branch and exports TARGET_BRANCH

TARGET_BRANCH=""
if [ -n "${CIRCLE_PULL_REQUEST:-}" ]; then
TARGET_BRANCH=$(curl -s "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PULL_REQUEST##*/}" | jq -r .base.ref)
fi

# Fallbacks when not a PR or API did not return a branch
if [ -z "$TARGET_BRANCH" ] || [ "$TARGET_BRANCH" = "null" ]; then
TARGET_BRANCH="${CIRCLE_BRANCH:-develop}"
fi

echo "Resolved TARGET_BRANCH=$TARGET_BRANCH" >&2
export TARGET_BRANCH
11 changes: 11 additions & 0 deletions packages/contracts-bedrock/scripts/ops/use-latest-fallback.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ set -euo pipefail
# - develop branch: Always build fresh (accuracy)
# - force-use-fresh-artifacts label: Override fallback (emergency escape hatch)

# Determine the target branch for this PR
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=/dev/null
source "$SCRIPT_DIR/get-target-branch.sh"

USE_FALLBACK=false

# Check if we're on a PR (not develop branch)
Expand Down Expand Up @@ -43,6 +48,12 @@ if [ "${CIRCLE_BRANCH:-}" != "develop" ]; then
fi
fi

echo "TARGET_BRANCH=$TARGET_BRANCH"
# Ensure that PRs targetting anything other than develop do not use the fallback
if [ "$TARGET_BRANCH" != "develop" ]; then
USE_FALLBACK=false
fi

# Pull artifacts with or without fallback
if [ "$USE_FALLBACK" = "true" ]; then
bash scripts/ops/pull-artifacts.sh --fallback-to-latest
Expand Down