Skip to content

Commit 1dbbb97

Browse files
committed
feat(ci): follow rails more closely
- Add a `RAILS_TAG` environment variable to specify the Rails reference to test against. - Update CI workflows to dynamically determine supported CockroachDB versions from the official CockroachDB docs. - Weekly run CI.
1 parent 27ebc9e commit 1dbbb97

File tree

4 files changed

+78
-33
lines changed

4 files changed

+78
-33
lines changed

.github/workflows/ci.yml

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ on:
99
# Triggers the workflow on pull request events.
1010
pull_request:
1111
types: [opened, reopened, synchronize]
12-
12+
schedule:
13+
- cron: 12 13 * * 1 # Weekly
1314
# Allows you to run this workflow manually from the Actions tab
1415
workflow_dispatch:
1516

@@ -19,7 +20,77 @@ concurrency:
1920
cancel-in-progress: true
2021

2122
jobs:
22-
# Since the name of the matrix job depends on the version, we define another job with a more stable name.
23+
orchestrate:
24+
runs-on: ubuntu-latest
25+
name: Prepare Tests
26+
outputs:
27+
supported_crdbs: ${{ steps.crdb.outputs.crdbs }}
28+
latest_crdb: ${{ steps.crdb.outputs.latest }}
29+
steps:
30+
- id: crdb
31+
name: Determine Supported CockroachDB Versions
32+
shell: ruby -rcsv -rjson -rnet/http -ruri {0}
33+
run: |
34+
p ENV["GITHUB_OUTPUT"]
35+
link = "https://raw.githubusercontent.com/cockroachdb/docs/7c75d7596ae144c30f341b5b337b5775088f29df/src/current/_data/versions.csv"
36+
37+
uri = URI.parse(link)
38+
data = Net::HTTP.get(uri)
39+
csv = CSV.parse(data, headers: true)
40+
41+
versions = csv.filter_map do |row|
42+
support = row["asst_supp_exp_date"]
43+
support = row["maint_supp_exp_date"] if support == "N/A"
44+
45+
row["major_version"] if Date.parse(support) >= Date.today
46+
end
47+
p versions
48+
49+
File.write(ENV["GITHUB_OUTPUT"], "crdbs=#{JSON.generate(versions)}\n", mode: ?a)
50+
File.write(ENV["GITHUB_OUTPUT"], "latest=#{JSON.generate(versions.max)}\n", mode: ?a)
51+
52+
53+
puts File.read(ENV["GITHUB_OUTPUT"])
54+
55+
test:
56+
runs-on: ubuntu-latest
57+
needs: orchestrate
58+
continue-on-error: ${{ matrix.experimental }}
59+
strategy:
60+
fail-fast: false
61+
matrix:
62+
# https://www.cockroachlabs.com/docs/releases/release-support-policy
63+
crdb: ${{ fromJSON(needs.orchestrate.outputs.supported_crdbs) }}
64+
ruby: ["3.4"]
65+
rails: ["8-1-stable"]
66+
experimental: [false]
67+
include:
68+
- crdb: ${{ fromJSON(needs.orchestrate.outputs.latest_crdb) }}
69+
ruby: "3.4"
70+
rails: "main"
71+
experimental: true
72+
name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }} rails=${{ matrix.rails }})
73+
steps:
74+
- name: Set Up Actions
75+
uses: actions/checkout@v4
76+
- uses: ./.github/actions/test-runner
77+
id: test
78+
with:
79+
crdb: ${{ matrix.crdb }}
80+
ruby: ${{ matrix.ruby }}
81+
env:
82+
RAILS_TAG: ${{ matrix.rails }}
83+
JSON_REPORTER: "report.json"
84+
- name: Upload Report
85+
if: ${{ failure() && steps.test.conclusion == 'failure' }}
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: report-${{ matrix.crdb }}-${{ matrix.ruby }}
89+
path: report.json
90+
# Since the name of the matrix job depends on the
91+
# version, we define another job with a more stable
92+
# name. We also aggregate failed tests to display
93+
# in the Github Summary.
2394
test_results:
2495
if: ${{ always() }}
2596
runs-on: ubuntu-latest
@@ -92,29 +163,3 @@ jobs:
92163
echo '```json' >>$GITHUB_STEP_SUMMARY
93164
jq --slurp --compact-output '.' reports/*/report.json >>$GITHUB_STEP_SUMMARY
94165
echo '```' >>$GITHUB_STEP_SUMMARY
95-
96-
test:
97-
runs-on: ubuntu-latest
98-
strategy:
99-
fail-fast: false
100-
matrix:
101-
# https://www.cockroachlabs.com/docs/releases/release-support-policy
102-
crdb: [v24.3, v25.1, v25.2, v25.3]
103-
ruby: ["3.4"]
104-
name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }})
105-
steps:
106-
- name: Set Up Actions
107-
uses: actions/checkout@v4
108-
- uses: ./.github/actions/test-runner
109-
id: test
110-
with:
111-
crdb: ${{ matrix.crdb }}
112-
ruby: ${{ matrix.ruby }}
113-
env:
114-
JSON_REPORTER: "report.json"
115-
- name: Upload Report
116-
if: ${{ failure() && steps.test.conclusion == 'failure' }}
117-
uses: actions/upload-artifact@v4
118-
with:
119-
name: report-${{ matrix.crdb }}-${{ matrix.ruby }}
120-
path: report.json

.github/workflows/flaky.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ jobs:
2828
name: Prepare Matrix
2929
steps:
3030
- id: generate-matrix
31+
name: Generate Test Matrix
3132
run: |
3233
crdb=$(jq --raw-input --compact-output 'split(" ")' <<<"${{ github.event.inputs.crdb }}")
3334
ruby=$(jq --raw-input --compact-output 'split(" ")' <<<"${{ github.event.inputs.ruby }}")
3435
crdb_len=$(wc -w <<<"${{ github.event.inputs.crdb }}")
3536
ruby_len=$(wc -w <<<"${{ github.event.inputs.ruby }}")
3637
(( seeds_count = ${{github.event.inputs.max}} / ( crdb_len * ruby_len ) ))
3738
seeds=$(shuf --input-range=1-65535 --head-count=$seeds_count | jq --slurp --compact-output)
38-
echo $seeds
3939
echo "crdb=$crdb" >> $GITHUB_OUTPUT
4040
echo "ruby=$ruby" >> $GITHUB_OUTPUT
4141
echo "seeds=$seeds" >> $GITHUB_OUTPUT
@@ -64,7 +64,7 @@ jobs:
6464
ruby: ${{ matrix.ruby }}
6565
TESTOPTS: --fail-fast
6666
env:
67-
JSON_REPORTER: "report.json"
67+
JSON_REPORTER: 'report.json'
6868
SEED: ${{ matrix.seed }}
6969
- name: Upload Report
7070
if: ${{ failure() && steps.test.conclusion == 'failure' }}

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module RailsTag
2020
def gemspec_requirement
2121
File
2222
.foreach(File.expand_path("activerecord-cockroachdb-adapter.gemspec", __dir__), chomp: true)
23-
.find { _1[/add_dependency\s.activerecord.,\s.(.*)./] }
23+
.find { _1[/add_dependency\s.activerecord.,\s["'](.*?)["']/] }
2424

2525
Gem::Requirement.new(Regexp.last_match(1))
2626
end
@@ -46,7 +46,7 @@ group :development, :test do
4646
# We need to load the gem from git to have access to activerecord's test files.
4747
# You can use `path: "some/local/rails"` if you want to test the gem against
4848
# a specific rails codebase.
49-
gem "rails", github: "rails/rails", tag: RailsTag.call
49+
gem "rails", github: "rails/rails", ref: ENV.fetch("RAILS_TAG", RailsTag.call)
5050

5151
# Needed for the test suite
5252
gem "msgpack", ">= 1.7.0"

activerecord-cockroachdb-adapter.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
1414
spec.description = "Allows the use of CockroachDB as a backend for ActiveRecord and Rails apps."
1515
spec.homepage = "https://github.com/cockroachdb/activerecord-cockroachdb-adapter"
1616

17-
spec.add_dependency "activerecord", "~> 8.1.0"
17+
spec.add_dependency "activerecord", "~> 8.1.0" unless ENV.key?("RAILS_TAG")
1818
spec.add_dependency "pg", "~> 1.5"
1919
spec.add_dependency "rgeo-activerecord", "~> 8.1.0"
2020

0 commit comments

Comments
 (0)