diff --git a/.circleci/config.yml b/.circleci/config.yml index 8d3ba56ee..461d0efbd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -98,6 +98,8 @@ jobs: - restore_cache: *restore_bundler_cache - restore_cache: *restore_yarn_cache + - run: ../../bin/checkout-and-link-starter-repo + # Install dependencies - ruby/bundle-install - run: bin/link @@ -144,6 +146,8 @@ jobs: - restore_cache: *restore_bundler_cache - restore_cache: *restore_yarn_cache + - run: ../../bin/checkout-and-link-starter-repo + # Install dependencies - ruby/bundle-install - run: bundle clean --force @@ -195,6 +199,8 @@ jobs: - restore_cache: *restore_bundler_cache - restore_cache: *restore_yarn_cache + - run: ../../bin/checkout-and-link-starter-repo + # Install dependencies - ruby/bundle-install - run: bin/link diff --git a/bin/checkout-and-link-core-repo b/bin/checkout-and-link-core-repo new file mode 100755 index 000000000..1226adb8e --- /dev/null +++ b/bin/checkout-and-link-core-repo @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +# Default to the main branch if we don't find a matching branch on the starter repository. +CORE_REPO_BRANCH="main" + +# Look for a matching branch on the starter repository when running tests on CircleCI. +CI_BRANCH=$CIRCLE_BRANCH +if [[ -v CI_BRANCH ]] +then + # Default to the main branch if we don't find a matching branch on the starter repository. + BRANCH_NAMES_JSON=$(curl -H "Accept: application.vnd.github+json" "https://api.github.com/repos/bullet-train-co/bullet_train-core/branches?per_page=100") + #echo "This is what we're getting from the GitHub API:" + #echo "${BRANCH_NAMES_JSON}" + BRANCH_NAMES=$(echo $BRANCH_NAMES_JSON | jq -r '.[].name') + echo "These are the branches on the core repo:" + echo "${BRANCH_NAMES}" + + for BRANCH in $BRANCH_NAMES; do + if [ ${BRANCH} == $CIRCLE_BRANCH ] + then + CORE_REPO_BRANCH=$BRANCH + break + fi + done +fi + + +if [ $CORE_REPO_BRANCH == "main" ] +then + # Do nothing and use the published version of the gems? +else + + echo "Cloning from ${CORE_REPO_BRANCH}..." + git clone -b $CORE_REPO_BRANCH --depth 1 https://github.com/bullet-train-co/bullet_train.git . + + # TODO: Maybe generate this list automatically based on the subdirectories in core that contain a .gemspec? + packages=( + "bullet_train" + "bullet_train-api" + "bullet_train-fields" + "bullet_train-has_uuid" + "bullet_train-incoming_webhooks" + "bullet_train-integrations" + "bullet_train-integrations-stripe" + "bullet_train-obfuscates_id" + "bullet_train-outgoing_webhooks" + "bullet_train-roles" + "bullet_train-scope_questions" + "bullet_train-scope_validator" + "bullet_train-sortable" + "bullet_train-super_load_and_authorize_resource" + "bullet_train-super_scaffolding" + "bullet_train-themes" + "bullet_train-themes-light" + "bullet_train-themes-tailwind_css" + ) + + for package in "${packages[@]}" + do + : + grep -v "gem \"$package\"" Gemfile > Gemfile.tmp + mv Gemfile.tmp Gemfile + echo "gem \"$package\", path: \"../../$package\"" >> Gemfile + done + + updates="${packages[@]}" + bundle lock --update $updates + +fi + +