From c292f51957814f1e108a30167f88fd172d3383b2 Mon Sep 17 00:00:00 2001 From: "Dominik M. Kwiatek" Date: Mon, 20 Apr 2020 21:02:48 +0100 Subject: [PATCH] Set up GitHub Actions (#72) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add GitHub Actions config * Add extra dependencies and use environment variable for DB config Moved the env vars up to outside of the postgres service so this might not work * Pass environment variables for Postgres credentials to Postgres container * Pass service ports to application Have a suspicion that Redis one won't work as justask.yml is probably not using ERB * Add database.yml.postgres with port * Cache gems; pass Redis URL as env var * Add host to DB config * Pass DB credentials for db:setup * Use 127.0.0.1 instead of localhost to force TCP; Use bundler config without instead of --without * I can't read 🗑 * 🤔 * 💻🔨 I have no idea what I'm doing… * Testing env defined outside steps * Move templated vars down * Add build badge --- .github/workflows/retrospring.yml | 69 +++++++++++++++++++++++++++++++ README.md | 1 + config/database.yml.postgres | 8 ++-- config/initializers/15_sidekiq.rb | 6 ++- 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/retrospring.yml diff --git a/.github/workflows/retrospring.yml b/.github/workflows/retrospring.yml new file mode 100644 index 00000000..bf6914fb --- /dev/null +++ b/.github/workflows/retrospring.yml @@ -0,0 +1,69 @@ +name: Retrospring + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:10.12 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: justask_test + ports: + - 5432/tcp + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + redis: + image: redis + ports: + - 6379:6379 + options: --entrypoint redis-server + + env: + RAILS_ENV: test + POSTGRES_HOST: localhost + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: justask_test + + steps: + - uses: actions/checkout@v2 + - uses: actions/cache@v1 + with: + path: vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems- + - name: Set up Ruby 2.7 + uses: actions/setup-ruby@v1 + with: + ruby-version: 2.7.x + - name: Install dependencies + run: sudo apt-get install -y libpq-dev libxml2-dev libxslt1-dev libmagickwand-dev imagemagick + - name: Copy default configuration + run: | + cp config/database.yml.postgres config/database.yml + cp config/justask.yml.example config/justask.yml + - name: Install gems + run: | + gem install bundler + bundle config path vendor/bundle + bundle config set without 'production' + bundle install --jobs 4 --retry 3 + - name: Set up database + run: bundle exec rake db:setup + env: + POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }} + - name: Run tests + run: bundle exec rake spec + env: + POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }} + REDIS_URL: "redis://localhost:${{ job.services.redis.ports[6379] }}" diff --git a/README.md b/README.md index dbd63a31..ff811b59 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Retrospring +![Retrospring](https://github.com/Retrospring/retrospring/workflows/Retrospring/badge.svg) This is the source code that powers Retrospring. This is a detached fork of [nilsding/justask](https://github.com/nilsding/justask), where we continue diff --git a/config/database.yml.postgres b/config/database.yml.postgres index 2126da56..eaf84191 100644 --- a/config/database.yml.postgres +++ b/config/database.yml.postgres @@ -28,7 +28,9 @@ development: test: &test adapter: postgresql encoding: unicode - database: justask_test + database: <%= ENV['POSTGRES_DB'] %> + host: <%= ENV.fetch('POSTGRES_HOST', 'localhost') %> pool: 5 - username: postgres - password: + username: <%= ENV['POSTGRES_USER'] %> + password: <%= ENV['POSTGRES_PASSWORD'] %> + port: <%= ENV.fetch('POSTGRES_PORT', 5432) %> diff --git a/config/initializers/15_sidekiq.rb b/config/initializers/15_sidekiq.rb index 2dd4a530..f0985236 100644 --- a/config/initializers/15_sidekiq.rb +++ b/config/initializers/15_sidekiq.rb @@ -1,7 +1,9 @@ +redis_url = ENV.fetch("REDIS_URL") { APP_CONFIG["redis_url"] } + Sidekiq.configure_server do |config| - config.redis = { url: APP_CONFIG['redis_url'] } + config.redis = { url: redis_url } end Sidekiq.configure_client do |config| - config.redis = { url: APP_CONFIG['redis_url'] } + config.redis = { url: redis_url } end \ No newline at end of file