Skip to content

Commit

Permalink
Fix github action
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadser committed Jul 16, 2024
1 parent 0c0c51a commit b778f7a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 20 deletions.
65 changes: 51 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Ruby
name: Ruby with PostgreSQL

on:
push:
Expand All @@ -22,19 +15,63 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6', '2.7', '3.0']
ruby-version: ['3.3.0']

services:
db:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_db
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
- name: Set up Ruby and PostgreSQL
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
mirror: 'bd' # Use the Brazilian mirror for faster downloads

- name: Install PostgreSQL client
run: |
sudo apt-get install postgresql-client
- name: Wait for PostgreSQL to be ready
run: |
until pg_isready -h localhost -p 5432 -U postgres; do
echo "Waiting for PostgreSQL to start..."
sleep 1
done
- name: Generate creds file
run: |
EDITOR="mate --wait" ./bin/rails credentials:edit
- name: Install Node.js and Yarn
run: |
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g yarn
- name: Yarn install
run: |
yarn install
- name: Precompile assets
run: |
SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
- name: Setup database schema
run: |
# Replace with your database setup commands (e.g., migrations)
bundle exec rake db:create db:schema:load
- name: Run tests
run: bundle exec rspec

- name: Run rubocop
run: bundle exec rubocop -DES
14 changes: 8 additions & 6 deletions config/initializers/active_record_encryption.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# frozen_string_literal: true

begin
credentials = Rails.application.credentials

unless credentials.dig(:active_record_encryption, :primary_key) &&
credentials.dig(:active_record_encryption, :deterministic_key) &&
credentials.dig(:active_record_encryption, :key_derivation_salt)
credentials.dig(:active_record_encryption, :deterministic_key) &&
credentials.dig(:active_record_encryption, :key_derivation_salt)
new_keys = {
active_record_encryption: {
primary_key: SecureRandom.hex(16),
Expand All @@ -13,16 +15,16 @@
}

encrypted = ActiveSupport::EncryptedConfiguration.new(
config_path: "config/credentials.yml.enc",
key_path: "config/master.key",
env_key: "RAILS_MASTER_KEY",
config_path: 'config/credentials.yml.enc',
key_path: 'config/master.key',
env_key: 'RAILS_MASTER_KEY',
raise_if_missing_key: true
)

current_credentials = YAML.load(encrypted.read) || {}
updated_credentials = current_credentials.deep_merge(new_keys)
encrypted.write(updated_credentials.to_yaml)
end
rescue => e
rescue StandardError
nil
end

0 comments on commit b778f7a

Please sign in to comment.