Skip to content

Commit

Permalink
chore(ci): switch to github actions
Browse files Browse the repository at this point in the history
When this project was first started, Github Actions were not an
option. Now that they are, and that teamcity is less accessible
(lesser used, needs connection, ci link is not up to date), we
are switching to gh actions.

Fixes #279
  • Loading branch information
BuonOmo committed Jul 26, 2023
1 parent 269001e commit 176961c
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 9 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Inspired from:
# - https://github.com/cockroachdb/sqlalchemy-cockroachdb/blob/master/.github/workflows/ci.yml
# - https://github.com/rgeo/activerecord-postgis-adapter/blob/master/.github/workflows/tests.yml
name: Test

on:
# Triggers the workflow on push or pull request events.
push:
# This should disable running the workflow on tags, according to the
# on.<push|pull_request>.<branches|tags> GitHub Actions docs.
branches:
- "*"
pull_request:
types: [opened, reopened, synchronize]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# This allows a subsequently queued workflow run to interrupt previous runs.
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
crdb: [v23.1.5]
ruby: [ruby-head]
name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }})
steps:
- name: Set Up Actions
uses: actions/checkout@v3
- name: Install GEOS
run: sudo apt-get install libgeos-dev
- name: Set Up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Install and Start Cockroachdb
run: |
# Download CockroachDB
wget -qO- https://binaries.cockroachdb.com/cockroach-${{ matrix.crdb }}.linux-amd64.tgz | tar xvz
export PATH=./cockroach-${{ matrix.crdb }}.linux-amd64/:$PATH
readonly urlfile=cockroach-url
# Start a CockroachDB server and wait for it to become ready.
rm -f "$urlfile"
rm -rf cockroach-data
# Start CockroachDB.
cockroach start-single-node --max-sql-memory=25% --cache=25% --insecure --host=localhost --spatial-libs=./cockroach-${{ matrix.crdb }}.linux-amd64/lib --listening-url-file="$urlfile" >/dev/null 2>&1 &
# Ensure CockroachDB is stopped on script exit.
# Wait until CockroachDB has started.
for i in {0..3}; do
[[ -f "$urlfile" ]] && break
backoff=$((2 ** i))
echo "server not yet available; sleeping for $backoff seconds"
sleep $backoff
done
cockroach sql --insecure -e "
CREATE DATABASE activerecord_unittest;
CREATE DATABASE activerecord_unittest2;
SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;
SET CLUSTER SETTING sql.stats.histogram_collection.enabled = false;
SET CLUSTER SETTING jobs.retention_time = '180s';
SET CLUSTER SETTING sql.defaults.experimental_alter_column_type.enabled = 'true';
ALTER RANGE default CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
ALTER TABLE system.public.jobs CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
ALTER RANGE meta CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
ALTER RANGE system CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
ALTER RANGE liveness CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
SET CLUSTER SETTING kv.range_merge.queue_interval = '50ms';
SET CLUSTER SETTING kv.raft_log.disable_synchronization_unsafe = 'true';
SET CLUSTER SETTING jobs.registry.interval.cancel = '180s';
SET CLUSTER SETTING jobs.registry.interval.gc = '30s';
SET CLUSTER SETTING kv.range_split.by_load_merge_delay = '5s';
SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true';
"
- name: Test
run: bundle exec rake test
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module RailsTag

def gemspec_requirement
File
.foreach("activerecord-cockroachdb-adapter.gemspec", chomp: true)
.foreach(File.expand_path("activerecord-cockroachdb-adapter.gemspec", __dir__), chomp: true)
.find { _1[/add_dependency\s.activerecord.,\s.(.*)./] }

Gem::Requirement.new(Regexp.last_match(1))
Expand Down
4 changes: 2 additions & 2 deletions test/cases/adapters/postgresql/active_schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def test_add_index
end

private
def method_missing(method_symbol, *arguments)
ActiveRecord::Base.connection.send(method_symbol, *arguments)
def method_missing(...)
ActiveRecord::Base.connection.send(...)
end
end
end
6 changes: 3 additions & 3 deletions test/cases/connection_adapters/schema_cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setup
# See test/excludes/ActiveRecord/ConnectionAdapters/SchemaCacheTest.rb
def test_yaml_loads_5_1_dump
body = File.open(schema_dump_path).read
cache = YAML.load(body)
cache = YAML.unsafe_load(body)

assert_no_queries do
assert_equal 11, cache.columns("posts").size
Expand All @@ -32,7 +32,7 @@ def test_yaml_loads_5_1_dump
# See test/excludes/ActiveRecord/ConnectionAdapters/SchemaCacheTest.rb
def test_yaml_loads_5_1_dump_without_indexes_still_queries_for_indexes
body = File.open(schema_dump_path).read
@cache = YAML.load(body)
@cache = YAML.unsafe_load(body)

# Simulate assignment in railtie after loading the cache.
old_cache, @connection.schema_cache = @connection.schema_cache, @cache
Expand All @@ -51,7 +51,7 @@ def test_yaml_loads_5_1_dump_without_indexes_still_queries_for_indexes
# See test/excludes/ActiveRecord/ConnectionAdapters/SchemaCacheTest.rb
def test_yaml_loads_5_1_dump_without_database_version_still_queries_for_database_version
body = File.open(schema_dump_path).read
@cache = YAML.load(body)
@cache = YAML.unsafe_load(body)

# Simulate assignment in railtie after loading the cache.
old_cache, @connection.schema_cache = @connection.schema_cache, @cache
Expand Down
4 changes: 2 additions & 2 deletions test/cases/helper_cockroachdb.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'bundler/setup'
Bundler.require :development
require 'bundler'
Bundler.setup

# Turn on debugging for the test environment
ENV['DEBUG_COCKROACHDB_ADAPTER'] = "1"
Expand Down
2 changes: 1 addition & 1 deletion test/support/rake_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_files
ar_test_files = ENV.fetch('TEST_FILES_AR', '')
cr_test_files = ENV.fetch('TEST_FILES', '')

return all_test_file if ar_test_files.empty? && cr_test_files.empty?
return all_test_files if ar_test_files.empty? && cr_test_files.empty?

ar_test_files = ar_test_files.
split(',').
Expand Down

0 comments on commit 176961c

Please sign in to comment.