Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CircleCI with tests linked to starter repository #100

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
138 changes: 138 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
version: 2.1
orbs:
ruby: circleci/[email protected]
node: circleci/[email protected]
browser-tools: circleci/[email protected]
jq: circleci/[email protected]
aliases:
- &restore_bundler_cache
name: Restore Bundler cache
keys:
- gem-cache-v1-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- gem-cache-v1-{{ .Branch }}-
- gem-cache-v1-
- &restore_yarn_cache
name: Restore Yarn cache
keys:
- yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-packages-v1-{{ .Branch }}-
- yarn-packages-
- &save_bundle_cache
name: Save Bundle cache
key: gem-cache-v1-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- &save_yarn_cache
name: Save Yarn cache
key: yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- node_modules
- &restore_tmp_bundler_cache
name: Restore Bundler cache
keys:
- tmp-starter-gem-cache-v1-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- tmp-starter-gem-cache-v1-{{ .Branch }}-
- tmp-starter-gem-cache-v1-
- &restore_tmp_yarn_cache
name: Restore Yarn cache
keys:
- tmp-starter-yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
- tmp-starter-yarn-packages-v1-{{ .Branch }}-
- tmp-starter-yarn-packages-
- &save_tmp_bundle_cache
name: Save Bundle cache
key: tmp-starter-gem-cache-v1-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths:
- tmp/starter/vendor/bundle
- &save_tmp_yarn_cache
name: Save Yarn cache
key: tmp-starter-yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- tmp/starter/node_modules
- &ruby_node_browsers_docker_image
- image: cimg/ruby:3.2.2-browsers
environment:
PGHOST: localhost
PGUSER: untitled_application
RAILS_ENV: test
- &postgres_docker_image
- imuge: circleci/postgres
environment:
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: untitled_application_test
POSTGRES_USER: untitled_application
- &wait_for_docker
# We run this because the DB might not be available for a while due to a race condition.
run: dockerize -wait tcp://localhost:5432 -timeout 1m
jobs:
'Local Minitest':
docker:
# We currently don't have any system tests, so we don't need the browser image.
# - <<: *ruby_node_browsers_docker_image
- <<: *postgres_docker_image
executor: ruby/default
steps:
- checkout

# Install dependencies
- run: "bundle install"
- run: "bundle clean --force"
- *wait_for_docker
- run:
name: Run unit tests
command: bundle exec rails test

'Local Standard Ruby':
# docker:
# - <<: *ruby_node_browsers_docker_image
steps:
- checkout
- ruby/install-deps:
clean-bundle: true
- run:
name: Check Standard Ruby
command: bundle exec standardrb

'Starter Repo Minitest':
docker:
- <<: *ruby_node_browsers_docker_image
- <<: *postgres_docker_image
- image: circleci/redis
executor: ruby/default
working_directory: tmp/starter
parallelism: 16
steps:
- checkout:
path: ~/project
- browser-tools/install-browser-tools:
firefox-version: 108.0.1

# TODO: This is a workaround to get git clone working, but it shouldn't be here.
# https://github.com/CircleCI-Public/browser-tools-orb/issues/63
- run:
command: rm LICENSE.chromedriver

- run: ./bin/checkout-and-link-starter-repo

- ruby/install-deps:
clean-bundle: true
- node/install-packages:
pkg-manager: yarn
- run: yarn build:css

- *wait_for_docker

- run:
name: Run tests with Knapsack Pro
command: bundle exec rails "knapsack_pro:queue:minitest[--verbose]"
environment:
RAILS_ENV: test
KNAPSACK_PRO_CI_NODE_TOTAL: 16

workflows:
version: 2
build:
jobs:
- 'Local Minitest'
- 'Local Standard Ruby'
- 'Starter Repo Minitest'
52 changes: 52 additions & 0 deletions bin/checkout-and-link-starter-repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

# TODO: This is overkill for the magic_test repository so it should be cleaned up,
# we just need to clone the starter repository so the file is the same as what you find in bullet_train-core.

# Default to the main branch if we don't find a matching branch on the starter repository.
STARTER_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
BRANCH_RESPONSE=$(curl --head -H "Accept: application.vnd.github+json" https://api.github.com/repos/bullet-train-co/bullet_train/branches/$CI_BRANCH)

if echo $BRANCH_RESPONSE | grep "200"; then
STARTER_REPO_BRANCH=$CI_BRANCH
fi
fi

echo "Cloning from ${STARTER_REPO_BRANCH}..."
git clone -b $STARTER_REPO_BRANCH --depth 1 https://github.com/bullet-train-co/bullet_train.git .

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
4 changes: 0 additions & 4 deletions test/magic_test_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@ class MagicTestTest < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::MagicTest::VERSION
end

def test_it_does_something_useful
assert false
end
end