Skip to content

Commit

Permalink
Fix Github actions so that CI functions again (#15)
Browse files Browse the repository at this point in the history
The `services` key should be part of a job.

See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idservices.

* CI: Try to fix workflow definition

The `services` key should be part of a job.

See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idservices.

* CI: Update to ubuntu-22.04

* CI: Update to ubuntu-22.04

* Use setup-ruby action for installing gems

See https://github.com/ruby/setup-ruby/tree/master?tab=readme-ov-file#caching-bundle-install-automatically

* Try to configure Redis connection for specs

* Map redis service port

* Go back to default Redis URL

Now that the port is exposed on localhost, this should work.

* Configure postgres service container

* CI: Update deprecated actions

* Test with latest Ruby v3.2

* CI: Try to fix connection to MySQL

* Fix RSpec setup

* Clean up syntax

* Migration: Fix index definition
  • Loading branch information
franzliedke committed Nov 2, 2023
1 parent 278eb7e commit 83a2a3d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 59 deletions.
87 changes: 31 additions & 56 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,25 @@ on:
env:
BUNDLE_PATH: vendor/bundle

services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
redis:
image: redis
options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5

jobs:
lint:
name: Code Style
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
strategy:
matrix:
ruby:
- '2.7'
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Gemfile Cache
uses: actions/cache@v2
with:
path: Gemfile.lock
key: ${{ runner.os }}-gemlock-${{ matrix.ruby }}-${{ hashFiles('Gemfile', 'idempo.gemspec') }}
restore-keys: |
${{ runner.os }}-gemlock-${{ matrix.ruby }}-
- name: Bundle Cache
id: cache-gems
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ hashFiles('Gemfile', 'Gemfile.lock', 'idempo.gemspec') }}
restore-keys: |
${{ runner.os }}-gems-${{ matrix.ruby }}-
${{ runner.os }}-gems-
- name: Bundle Install
if: steps.cache-gems.outputs.cache-hit != 'true'
run: bundle install --jobs 4 --retry 3
bundler-cache: true
- name: Rubocop Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.cache/rubocop_cache
key: ${{ runner.os }}-rubocop-${{ hashFiles('.rubocop.yml') }}
Expand All @@ -65,38 +35,43 @@ jobs:
run: bundle exec rubocop
test:
name: Specs
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
strategy:
matrix:
ruby:
- '2.6'
- '3.0'
- '3.2'
services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
ports:
- 5432:5432
redis:
image: redis
options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
ports:
- 6379:6379
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Gemfile Cache
uses: actions/cache@v2
with:
path: Gemfile.lock
key: ${{ runner.os }}-gemlock-${{ matrix.ruby }}-${{ hashFiles('Gemfile', 'idempo.gemspec') }}
restore-keys: |
${{ runner.os }}-gemlock-${{ matrix.ruby }}-
- name: Bundle Cache
id: cache-gems
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ hashFiles('Gemfile', 'Gemfile.lock', 'idempo.gemspec') }}
restore-keys: |
${{ runner.os }}-gems-${{ matrix.ruby }}-
${{ runner.os }}-gems-
- name: Bundle Install
if: steps.cache-gems.outputs.cache-hit != 'true'
run: bundle install --jobs 4 --retry 3
bundler-cache: true
- name: RSpec
run: bundle exec rspec
env:
MYSQL_HOST: 127.0.0.1
MYSQL_PORT: 3306
2 changes: 1 addition & 1 deletion lib/idempo/active_record_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class Idempo::ActiveRecordBackend
def self.create_table(via_migration)
via_migration.create_table 'idempo_responses', charset: 'utf8mb4', collation: 'utf8mb4_unicode_ci' do |t|
t.string :idempotent_request_key, index: true, unique: true, null: false
t.string :idempotent_request_key, index: {unique: true}, null: false
t.datetime :expire_at, index: true, null: false # Needs an index for cleanup
t.binary :idempotent_response_payload, size: :medium
t.timestamps
Expand Down
10 changes: 8 additions & 2 deletions spec/idempo/active_record_backend_mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@

RSpec.describe Idempo::ActiveRecordBackend do
before :all do
connection = if ENV['CI']
{host: ENV['MYSQL_HOST'], port: ENV['MYSQL_PORT'], adapter: 'mysql2'}
else
{adapter: 'mysql2'}
end

seed_db_name = Random.new(RSpec.configuration.seed).hex(4)
ActiveRecord::Base.establish_connection(adapter: 'mysql2', username: 'root')
ActiveRecord::Base.establish_connection(**connection, username: 'root')
ActiveRecord::Base.connection.create_database('idempo_tests_%s' % seed_db_name, charset: :utf8mb4)
ActiveRecord::Base.connection.close
ActiveRecord::Base.establish_connection(adapter: 'mysql2', encoding: 'utf8mb4', charset: 'utf8mb4', collation: 'utf8mb4_unicode_ci', username: 'root', database: 'idempo_tests_%s' % seed_db_name)
ActiveRecord::Base.establish_connection(**connection, encoding: 'utf8mb4', charset: 'utf8mb4', collation: 'utf8mb4_unicode_ci', username: 'root', database: 'idempo_tests_%s' % seed_db_name)

ActiveRecord::Schema.define(version: 1) do |via_definer|
Idempo::ActiveRecordBackend.create_table(via_definer)
Expand Down

0 comments on commit 83a2a3d

Please sign in to comment.