Skip to content

Commit c3ee555

Browse files
hartsickesoterik
andauthored
Run tests and lint via Github actions, consolidate test + non-test database containers
* Sets up Github Actions to run tests and linting on CI on every push * Only specifies to minor version for Ruby in CI, because of inconsistent availability on Ubuntu versions * Updates linter rules to match current use, and fixes rubocop errors * Regenerates bundle and rake binstubs * Remove separate testdb container * Use existing db container for database. Differentiate connection information by env vars and a separate database name (action_center_test). Also removes test db migration logic from the Docker entrypoint, assuming that we will load the schema in. Updates the CI file accordingly. * Relies on secrets.yml to make env vars available to application across environments * Deletes unneeded test-specific db configuration for env var; relies on environment to set instead * As much as possible, sets any config needed for test in the test env for secrets.yml * Deletes unused but confusing .env.test * Copy rather than Add Dockerfile to allow for caching and reduce risk. * COPY will cache contents in order of declaration, which should help reduce the amount of time it takes to build the image. ADD copies everything anew each time without caching. Also, Docker warns that ADD could unintentionally introduce security risks, including downloading remote files and unpacking archives. https://www.docker.com/blog/docker-best-practices-understanding-the-differences-between-add-and-copy-instructions-in-dockerfiles/ * Remove unused travis.yml file * Remove FactoryBot line that was initiating db connection on app startup * Was preventing us from creating a database with bin/rails db:create because it tried to connect to that same database before it was able to be created. * Remove unmaintained congress images. Repo last updated ~10 years ago, so images were broken anyway. * Move database env vars to database.yml. Try to reduce number of places where they appear. --------- Co-authored-by: sylph <[email protected]>
1 parent 79fbe84 commit c3ee555

File tree

23 files changed

+285
-161
lines changed

23 files changed

+285
-161
lines changed

.env.example

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,12 @@ force_ssl=false
99
time_zone="Pacific Time (US & Canada)"
1010

1111
# Database configuration (required)
12-
db_adapter=postgresql
13-
db_database=postgres
1412
db_username=postgres
1513
db_password=mysecretpassword
1614
db_port=5432
1715
db_host=db
1816
DB_AUTO_MIGRATE=false # or true, depending on if you want to run migrations every time the container starts
1917

20-
# Test database configuration
21-
test_db_password=mysecrettestpassword
22-
test_db_username=postgres
23-
test_db_database=postgres
24-
test_db_adapter=postgresql
25-
test_db_port=5432
26-
test_db_host=testdb
27-
TEST_DB_AUTO_MIGRATE=false
28-
2918
# Social media (required)
3019
twitter_handle=example
3120
twitter_related="example examplelive"

.env.test

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "Setup"
2+
description: "Installs dependencies"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Install Ruby and gems
7+
uses: ruby/setup-ruby@v1
8+
with:
9+
ruby-version: "3.3"
10+
bundler-cache: true
11+
- name: Install npm
12+
uses: actions/setup-node@v4
13+
with:
14+
cache: npm
15+
cache-dependency-path: 'package-lock.json'
16+
- name: Install JS dependencies
17+
shell: bash
18+
run: npm ci

.github/workflows/rails_ci.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This workflow uses actions that are not certified by GitHub. They are
2+
# provided by a third-party and are governed by separate terms of service,
3+
# privacy policy, and support documentation.
4+
#
5+
# This workflow will install a prebuilt Ruby version, install dependencies, and
6+
# run tests and linters.
7+
name: "Ruby on Rails CI"
8+
on: push
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
env:
13+
RAILS_ENV: test
14+
15+
db_host: localhost
16+
db_port: 5432
17+
db_username: testuser
18+
db_password: password
19+
services:
20+
postgres:
21+
image: postgres:latest
22+
ports:
23+
- "5432:5432"
24+
env:
25+
POSTGRES_USER: testuser
26+
POSTGRES_PASSWORD: password
27+
options: >-
28+
--health-cmd pg_isready
29+
--health-interval 10s
30+
--health-timeout 500ms
31+
--health-retries 15
32+
steps:
33+
- uses: actions/checkout@v4
34+
- name: Install dependencies
35+
uses: ./.github/actions/setup-action
36+
- name: Set up database schema
37+
run: bin/rails db:create db:schema:load
38+
- name: Run tests
39+
run: bundle exec rspec
40+
41+
lint:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: Install dependencies
46+
uses: ./.github/actions/setup-action
47+
- name: Generate binstubs
48+
run: bundle binstubs rubocop
49+
# - name: Security audit dependencies
50+
# run: bin/bundler-audit --update
51+
# - name: Security audit application code
52+
# run: bin/brakeman -q -w2
53+
- name: Lint Ruby files
54+
run: bin/rubocop --parallel

.travis.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

Dockerfile

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ RUN apt-get update && \
2424
COPY package.json package-lock.json ./
2525
RUN npm install
2626

27-
ADD Gemfile* ./
27+
COPY Gemfile* ./
2828

2929
RUN gem install bundler && bundle install
3030

31-
ADD bin/ ./bin
32-
ADD config/ ./config
33-
ADD config.ru ./
34-
ADD Rakefile ./
35-
ADD db/ ./db
36-
ADD lib/ ./lib
37-
ADD public/ ./public
38-
ADD app/ ./app
39-
ADD features/ ./features
40-
ADD script/ ./script
41-
ADD spec/ ./spec
42-
ADD vendor/ ./vendor
43-
ADD docker/ ./docker
44-
ADD .rubocop.yml ./.rubocop.yml
45-
ADD .sass-lint.yml ./.sass-lint.yml
31+
COPY bin/ ./bin
32+
COPY config/ ./config
33+
COPY config.ru ./
34+
COPY Rakefile ./
35+
COPY db/ ./db
36+
COPY lib/ ./lib
37+
COPY public/ ./public
38+
COPY app/ ./app
39+
COPY features/ ./features
40+
COPY script/ ./script
41+
COPY spec/ ./spec
42+
COPY vendor/ ./vendor
43+
COPY docker/ ./docker
44+
COPY .rubocop.yml ./.rubocop.yml
45+
COPY .sass-lint.yml ./.sass-lint.yml
4646

4747
RUN usermod -u 1000 www-data
4848

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ gem "uglifier", ">= 1.3.0" # compressor for JavaScript assets
2626

2727
source "https://rails-assets.org" do
2828
gem "rails-assets-chartjs", "~> 2"
29-
gem "rails-assets-congress-images-102x125"
3029
gem "rails-assets-EpicEditor", "~> 0"
3130
gem "rails-assets-html5shiv", "3.7.2"
3231
gem "rails-assets-ionicons", "~> 2"

Gemfile.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ GEM
99
specs:
1010
rails-assets-EpicEditor (0.2.3)
1111
rails-assets-chartjs (2.9.4)
12-
rails-assets-congress-images-102x125 (0.1.2)
1312
rails-assets-html5shiv (3.7.2)
1413
rails-assets-ionicons (2.0.1)
1514
rails-assets-jquery (2.1.3)
@@ -610,7 +609,6 @@ DEPENDENCIES
610609
rails (~> 7.0.0)
611610
rails-assets-EpicEditor (~> 0)!
612611
rails-assets-chartjs (~> 2)!
613-
rails-assets-congress-images-102x125!
614612
rails-assets-html5shiv (= 3.7.2)!
615613
rails-assets-ionicons (~> 2)!
616614
rails-assets-jquery (= 2.1.3)!

app/controllers/concerns/logged_invisible_captcha.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ module LoggedInvisibleCaptcha
33

44
def on_spam(options = {})
55
log_failure
6-
super(options)
6+
super
77
end
88

99
def on_timestamp_spam(options = {})
1010
log_failure
11-
super(options)
11+
super
1212
end
1313

1414
def log_failure

app/helpers/action_page_helper.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ def email_friends_url(action_page)
3030
"mailto:?subject=#{u subject}&body=#{u message}"
3131
end
3232

33-
def rep_photo_src(bioguide_id)
34-
asset_path "congress-images-102x125/i/#{bioguide_id}.jpg"
35-
end
36-
3733
def rep_tweet_link(rep)
3834
tweet_link("@#{rep.twitter_id}", class: "btn-tweet rep")
3935
end

0 commit comments

Comments
 (0)