Created
June 10, 2024 11:53
-
-
Save rafaelqueiroz88/fd55413ecdcd320ae88f110c868fd56b to your computer and use it in GitHub Desktop.
Ruby on Rails + Github Actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Ruby on Rails trigger Github Actions" | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
ruby-version: ['3.2.2'] | |
services: | |
postgres: | |
image: postgres | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
- 5432:5432 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Verifying Gemfile | |
run: rm Gemfile && mv Gemfile_cp Gemfile | |
- name: Verifying Ruby Version | |
run: rm .ruby-version && touch .ruby-version && echo 3.2.2 >> .ruby-version | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
bundler-cache: true | |
- name: Install Bundler | |
run: gem install bundler && bundle config set frozen false | |
- name: Run Bundle Install | |
run: bundle install | |
- name: Run Database Create and Migrate | |
run: bundle exec rails db:create db:migrate | |
env: | |
POSTGRES_HOST: localhost | |
POSTGRES_PORT: 5432 | |
rubocop: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
ruby-version: ['3.2.2'] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Verifying Gemfile | |
run: rm Gemfile && mv Gemfile_cp Gemfile | |
- name: Verifying Ruby Version | |
run: rm .ruby-version && touch .ruby-version && echo 3.2.2 >> .ruby-version | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
bundler-cache: false | |
- name: Install Bundler | |
run: gem install bundler | |
- name: Run Bundle Install | |
run: bundle install | |
- name: prevent freeze | |
run: bundle config unset deployment | |
- name: Verifying Rubocop setup | |
run: rm .rubocop.yml && mv .rubocop.yml_cp .rubocop.yml | |
- name: Lint Ruby files | |
env: | |
PROJECT_NAME: ${{ secrets.PROJECT_NAME }} | |
run: | | |
echo $PROJECT_NAME | |
bundle exec rubocop | |
rspec: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
ruby-version: ['3.2.2'] | |
services: | |
postgres: | |
image: postgres | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
- 5432:5432 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Verifying Gemfile | |
run: rm Gemfile && mv Gemfile_cp Gemfile | |
- name: Verifying Ruby Version | |
run: rm .ruby-version && touch .ruby-version && echo 3.2.2 >> .ruby-version | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
bundler-cache: false | |
- name: Install Bundler | |
run: gem install bundler | |
- name: Run Bundle Install | |
run: bundle install | |
- name: Prevent freeze | |
run: bundle config unset deployment | |
- name: Setup test database | |
run: bundle exec rails db:create db:migrate | |
env: | |
POSTGRES_HOST: localhost | |
POSTGRES_PORT: 5432 | |
- name: Run Rspec | |
run: bundle exec rspec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In my case, I'm using Ruby 3.3.1, so I need to change to 3.2.2, that's why my Gemfile and .ruby-version needs to be clean and replaced
Place it at: your_project_root/.github/workflows/some-supercool-name-workflow.yml