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 28, 2023
1 parent 269001e commit 3241169
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 53 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ p modified_fac.parse_wkt(wkt)
#=> #<RGeo::Geographic::SphericalPolygonImpl>
```

Be careful when performing calculations on potentially invalid geometries, as the results might be nonsensical. For example, the area returned of an hourglass made of 2 equivalent triangles with a self-intersection in the middle is 0.
Be careful when performing calculations on potentially invalid geometries, as the results might be nonsensical. For example, the area returned of an hourglass made of 2 equivalent triangles with a self-intersection in the middle is 0.

Note that when using the `spherical_factory`, there is a chance that valid geometries will be interpreted as invalid due to floating point issues with small geometries.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def new_column_from_field(table_name, field)
# since type alone is not enough to format the column.
# Ex. type_to_sql(:geography, limit: "Point,4326")
# => "geography(Point,4326)"
#
#
def type_to_sql(type, limit: nil, precision: nil, scale: nil, array: nil, **) # :nodoc:
sql = \
case type.to_s
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: 4 additions & 2 deletions test/cases/adapters/postgresql/postgis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ def test_spatial_factory_retrieval
def test_point_to_json
obj = klass.new
assert_match(/"latlon":null/, obj.to_json)
obj.latlon = factory.point(1.0, 2.0)
assert_match(/"latlon":"POINT\s\(1\.0\s2\.0\)"/, obj.to_json)
obj.latlon = factory.point(1.1, 2.0)
# NOTE: rgeo opiniated in trimming numbers (e.g 1.0 would be trimmed to 1).
# We follow this convention here.
assert_match(/"latlon":"POINT\s\(1.1\s2\)"/, obj.to_json)
end

def test_custom_column
Expand Down
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: 3 additions & 1 deletion test/cases/fixtures_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,13 @@ def before_setup
firm_id bigint,
firm_name character varying,
credit_limit integer,
status string,
#{'a' * max_identifier_length} integer
)
")

Company.connection.drop_table :companies, if_exists: true
Company.connection.exec_query("CREATE SEQUENCE companies_nonstd_seq")
Company.connection.exec_query("CREATE SEQUENCE IF NOT EXISTS companies_nonstd_seq")
Company.connection.exec_query("
CREATE TABLE companies (
id BIGINT PRIMARY KEY DEFAULT nextval('companies_nonstd_seq'),
Expand Down Expand Up @@ -361,6 +362,7 @@ def teardown
t.references :firm, index: false
t.string :firm_name
t.integer :credit_limit
t.string :status
t.integer "a" * max_identifier_length
end

Expand Down
6 changes: 4 additions & 2 deletions test/cases/helper_cockroachdb.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'bundler/setup'
Bundler.require :development
require 'bundler'
Bundler.setup

require "minitest/excludes"

# Turn on debugging for the test environment
ENV['DEBUG_COCKROACHDB_ADAPTER'] = "1"
Expand Down
2 changes: 1 addition & 1 deletion test/cases/relation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_relation_with_annotation_includes_comment_in_to_sql

def test_relation_with_annotation_filters_sql_comment_delimiters
post_with_annotation = Post.where(id: 1).annotate("**//foo//**")
assert_match %r{= '1' /\* foo \*/}, post_with_annotation.to_sql
assert_includes post_with_annotation.to_sql, "= '1' /* ** //foo// ** */"
end

def test_respond_to_for_non_selected_element
Expand Down
41 changes: 3 additions & 38 deletions test/excludes/PostgresqlRangeTest.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
exclude :test_create_int4range, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_timezone_awareness_tzrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_escaped_tsrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_update_tsrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_create_tsrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_infinity_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_update_int8range, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_ranges_correctly_escape_input, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_int8range_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_numrange_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_timezone_awareness_tsrange_preserve_usec, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_endless_range_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_int4range_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_update_daterange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_update_numrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_update_tsrange_preserve_usec, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_escaped_tstzrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_update_tstzrange_preserve_usec, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_ranges_correctly_unescape_output, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_where_by_attribute_with_range_in_array, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_tsrange_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_where_by_attribute_with_range, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_create_tsrange_preseve_usec, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_update_int4range, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_create_daterange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_create_tstzrange_preserve_usec, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_timezone_awareness_tsrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_daterange_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_update_all_with_ranges, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_custom_range_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_create_numrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_data_type_of_range_types, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_create_tstzrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_exclude_beginning_for_subtypes_without_succ_method_is_not_supported, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_tstzrange_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_update_tstzrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_create_int8range, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
exclude :test_create_tsrange_preserve_usec, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
message = "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791"
# No test is relevant in this class.
instance_methods.grep(/\Atest_/).each { exclude _1, message }
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 3241169

Please sign in to comment.