Skip to content

Commit 939cc6f

Browse files
BuonOmorafiss
authored andcommitted
chore(ci): switch to github actions
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
1 parent 269001e commit 939cc6f

File tree

19 files changed

+146
-63
lines changed

19 files changed

+146
-63
lines changed

.github/workflows/ci.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Inspired from:
2+
# - https://github.com/cockroachdb/sqlalchemy-cockroachdb/blob/master/.github/workflows/ci.yml
3+
# - https://github.com/rgeo/activerecord-postgis-adapter/blob/master/.github/workflows/tests.yml
4+
name: Test
5+
6+
on:
7+
# Triggers the workflow on push or pull request events.
8+
push:
9+
# This should disable running the workflow on tags, according to the
10+
# on.<push|pull_request>.<branches|tags> GitHub Actions docs.
11+
branches:
12+
- "*"
13+
pull_request:
14+
types: [opened, reopened, synchronize]
15+
16+
# Allows you to run this workflow manually from the Actions tab
17+
workflow_dispatch:
18+
19+
# This allows a subsequently queued workflow run to interrupt previous runs.
20+
concurrency:
21+
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
22+
cancel-in-progress: true
23+
24+
jobs:
25+
test:
26+
runs-on: ubuntu-latest
27+
strategy:
28+
matrix:
29+
crdb: [v23.1.5]
30+
ruby: [ruby-head]
31+
name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }})
32+
steps:
33+
- name: Set Up Actions
34+
uses: actions/checkout@v3
35+
- name: Install GEOS
36+
run: sudo apt-get install libgeos-dev
37+
- name: Set Up Ruby
38+
uses: ruby/setup-ruby@v1
39+
with:
40+
ruby-version: ${{ matrix.ruby }}
41+
bundler-cache: true
42+
- name: Install and Start Cockroachdb
43+
run: |
44+
# Download CockroachDB
45+
wget -qO- https://binaries.cockroachdb.com/cockroach-${{ matrix.crdb }}.linux-amd64.tgz | tar xvz
46+
47+
export PATH=./cockroach-${{ matrix.crdb }}.linux-amd64/:$PATH
48+
readonly urlfile=cockroach-url
49+
50+
# Start a CockroachDB server and wait for it to become ready.
51+
rm -f "$urlfile"
52+
rm -rf cockroach-data
53+
# Start CockroachDB.
54+
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 &
55+
# Ensure CockroachDB is stopped on script exit.
56+
# Wait until CockroachDB has started.
57+
for i in {0..3}; do
58+
[[ -f "$urlfile" ]] && break
59+
backoff=$((2 ** i))
60+
echo "server not yet available; sleeping for $backoff seconds"
61+
sleep $backoff
62+
done
63+
cockroach sql --insecure -e "
64+
CREATE DATABASE activerecord_unittest;
65+
CREATE DATABASE activerecord_unittest2;
66+
SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;
67+
SET CLUSTER SETTING sql.stats.histogram_collection.enabled = false;
68+
SET CLUSTER SETTING jobs.retention_time = '180s';
69+
SET CLUSTER SETTING sql.defaults.experimental_alter_column_type.enabled = 'true';
70+
71+
ALTER RANGE default CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
72+
ALTER TABLE system.public.jobs CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
73+
ALTER RANGE meta CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
74+
ALTER RANGE system CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
75+
ALTER RANGE liveness CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
76+
77+
SET CLUSTER SETTING kv.range_merge.queue_interval = '50ms';
78+
SET CLUSTER SETTING kv.raft_log.disable_synchronization_unsafe = 'true';
79+
SET CLUSTER SETTING jobs.registry.interval.cancel = '180s';
80+
SET CLUSTER SETTING jobs.registry.interval.gc = '30s';
81+
SET CLUSTER SETTING kv.range_split.by_load_merge_delay = '5s';
82+
83+
SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true';
84+
"
85+
- name: Test
86+
run: bundle exec rake test

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module RailsTag
1414

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

2020
Gem::Requirement.new(Regexp.last_match(1))

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ p modified_fac.parse_wkt(wkt)
321321
#=> #<RGeo::Geographic::SphericalPolygonImpl>
322322
```
323323

324-
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.
324+
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.
325325

326326
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.
327327

lib/active_record/connection_adapters/cockroachdb/schema_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def new_column_from_field(table_name, field)
112112
# since type alone is not enough to format the column.
113113
# Ex. type_to_sql(:geography, limit: "Point,4326")
114114
# => "geography(Point,4326)"
115-
#
115+
#
116116
def type_to_sql(type, limit: nil, precision: nil, scale: nil, array: nil, **) # :nodoc:
117117
sql = \
118118
case type.to_s

test/cases/adapters/postgresql/active_schema_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def test_add_index
6464
end
6565

6666
private
67-
def method_missing(method_symbol, *arguments)
68-
ActiveRecord::Base.connection.send(method_symbol, *arguments)
67+
def method_missing(...)
68+
ActiveRecord::Base.connection.send(...)
6969
end
7070
end
7171
end

test/cases/adapters/postgresql/postgis_test.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ def test_spatial_factory_retrieval
148148
def test_point_to_json
149149
obj = klass.new
150150
assert_match(/"latlon":null/, obj.to_json)
151-
obj.latlon = factory.point(1.0, 2.0)
152-
assert_match(/"latlon":"POINT\s\(1\.0\s2\.0\)"/, obj.to_json)
151+
obj.latlon = factory.point(1.1, 2.0)
152+
# NOTE: rgeo opiniated in trimming numbers (e.g 1.0 would be trimmed to 1).
153+
# We follow this convention here.
154+
assert_match(/"latlon":"POINT\s\(1.1\s2\)"/, obj.to_json)
153155
end
154156

155157
def test_custom_column
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require "cases/helper_cockroachdb"
2+
3+
# Load dependencies from ActiveRecord test suite
4+
require "support/schema_dumping_helper"
5+
6+
module CockroachDB
7+
class PostgresqlQuotingTest < ActiveRecord::PostgreSQLTestCase
8+
def setup
9+
@conn = ActiveRecord::Base.connection
10+
@raise_int_wider_than_64bit = ActiveRecord.raise_int_wider_than_64bit
11+
end
12+
13+
# Replace the original test since numbers are quoted.
14+
def test_do_not_raise_when_int_is_not_wider_than_64bit
15+
value = 9223372036854775807
16+
assert_equal "'9223372036854775807'", @conn.quote(value)
17+
18+
value = -9223372036854775808
19+
assert_equal "'-9223372036854775808'", @conn.quote(value)
20+
end
21+
22+
# Replace the original test since numbers are quoted.
23+
def test_do_not_raise_when_raise_int_wider_than_64bit_is_false
24+
ActiveRecord.raise_int_wider_than_64bit = false
25+
value = 9223372036854775807 + 1
26+
assert_equal "'9223372036854775808'", @conn.quote(value)
27+
ActiveRecord.raise_int_wider_than_64bit = @raise_int_wider_than_64bit
28+
end
29+
end
30+
end

test/cases/connection_adapters/schema_cache_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def setup
1515
# See test/excludes/ActiveRecord/ConnectionAdapters/SchemaCacheTest.rb
1616
def test_yaml_loads_5_1_dump
1717
body = File.open(schema_dump_path).read
18-
cache = YAML.load(body)
18+
cache = YAML.unsafe_load(body)
1919

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

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

5656
# Simulate assignment in railtie after loading the cache.
5757
old_cache, @connection.schema_cache = @connection.schema_cache, @cache

test/cases/fixtures_test.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,13 @@ def before_setup
313313
firm_id bigint,
314314
firm_name character varying,
315315
credit_limit integer,
316+
status string,
316317
#{'a' * max_identifier_length} integer
317318
)
318319
")
319320

320321
Company.connection.drop_table :companies, if_exists: true
321-
Company.connection.exec_query("CREATE SEQUENCE companies_nonstd_seq")
322+
Company.connection.exec_query("CREATE SEQUENCE IF NOT EXISTS companies_nonstd_seq")
322323
Company.connection.exec_query("
323324
CREATE TABLE companies (
324325
id BIGINT PRIMARY KEY DEFAULT nextval('companies_nonstd_seq'),
@@ -329,7 +330,8 @@ def before_setup
329330
client_of bigint,
330331
rating bigint,
331332
account_id integer,
332-
description character varying
333+
description character varying,
334+
status integer
333335
)
334336
")
335337

@@ -361,6 +363,7 @@ def teardown
361363
t.references :firm, index: false
362364
t.string :firm_name
363365
t.integer :credit_limit
366+
t.string :status
364367
t.integer "a" * max_identifier_length
365368
end
366369

@@ -375,6 +378,7 @@ def teardown
375378
t.bigint :rating, default: 1
376379
t.integer :account_id
377380
t.string :description, default: ""
381+
t.integer :status, default: 0
378382
t.index [:name, :rating], order: :desc
379383
t.index [:name, :description], length: 10
380384
t.index [:firm_id, :type, :rating], name: "company_index", length: { type: 10 }, order: { rating: :desc }

test/cases/helper_cockroachdb.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
require 'bundler/setup'
2-
Bundler.require :development
1+
require 'bundler'
2+
Bundler.setup
3+
4+
require "minitest/excludes"
35

46
# Turn on debugging for the test environment
57
ENV['DEBUG_COCKROACHDB_ADAPTER'] = "1"

0 commit comments

Comments
 (0)