Skip to content

Commit

Permalink
Chore: Switch from Circle to Github Actions for CI (#4734)
Browse files Browse the repository at this point in the history
Because:
- It's _slightly_ faster
- The configuration is more approachable
- We get unlimited free usage since the repo is public

This commit:
- Adds a GitHub actions workflow for running our linters and tests
- Adds bin stubs for rubocop, erblint and rspec
  • Loading branch information
KevinMulhern authored Aug 10, 2024
1 parent 8085a75 commit 18d51fd
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 87 deletions.
85 changes: 0 additions & 85 deletions .circleci/config.yml

This file was deleted.

91 changes: 91 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: CI

on:
pull_request:
branches: ["*"]
push:
branches: [main]

concurrency: ci-${{ github.ref }}

jobs:
linters:
name: Linters
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Ruby and install gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn

- name: Install packages
run: |
yarn install --pure-lockfile
- name: Run linters
run: |
bin/rubocop --parallel
bin/erblint --lint-all
yarn run eslint
tests:
name: Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15.7
env:
POSTGRES_USER: postgres
POSTGRES_DB: theodinproject_test
POSTGRES_PASSWORD: "password"
ports: ["5432:5432"]

redis:
image: redis
ports: ["6379:6379"]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Ruby and install gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn

- name: Install packages
run: |
yarn install --pure-lockfile
- name: Build assets
run: |
bin/rails javascript:build
bin/rails css:build
- name: Setup test database
env:
RAILS_ENV: test
DATABASE_URL: postgres://postgres:password@localhost:5432/theodinproject_test
run: |
bin/rails db:schema:load
- name: Run tests
env:
RAILS_ENV: test
DATABASE_URL: postgres://postgres:password@localhost:5432/theodinproject_test
run: bin/rspec
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Our community can be found on the [TOP Discord server](https://discord.gg/fbFCkY

## Contributing

[![Build Status](https://circleci.com/gh/TheOdinProject/theodinproject.svg?style=svg)](https://app.circleci.com/pipelines/github/TheOdinProject/theodinproject)
![Build status](https://github.com/TheOdinProject/theodinproject/actions/workflows/ci.yml/badge.svg)

The Odin Project depends on open-source contributions to improve, grow, and thrive. We welcome contributors of all experience levels and backgrounds to help maintain this awesome curriculum and community. If you would like to contribute to our curriculum, be sure to thoroughly read our [contributing guide](https://github.com/TheOdinProject/theodinproject/blob/main/CONTRIBUTING.md).

Expand Down
27 changes: 27 additions & 0 deletions bin/erblint
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'erblint' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("erb_lint", "erblint")
27 changes: 27 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rspec-core", "rspec")
27 changes: 27 additions & 0 deletions bin/rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rubocop' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rubocop", "rubocop")
7 changes: 6 additions & 1 deletion spec/support/precompile_assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
examples = RSpec.world.filtered_examples.values.flatten
has_no_system_tests = examples.none? { |example| example.metadata[:type] == :system }

if ENV['CI']
$stdout.puts "\n🚀️️ CI detected. Skip assets compilation.\n"
next
end

if has_no_system_tests
$stdout.puts "\n🚀️️ No system test selected. Skip assets compilation.\n"
next
Expand All @@ -14,7 +19,7 @@
start = Time.current
begin
$stdout.reopen(File.new('/dev/null', 'w'))
system('bin/rails assets:precompile')
system('bin/rails test:prepare') # invokes css:build and javascript:build
ensure
$stdout.reopen(original_stdout)
$stdout.puts "Finished in #{(Time.current - start).round(2)} seconds"
Expand Down

0 comments on commit 18d51fd

Please sign in to comment.