Skip to content

ci: add ci workflow #15

ci: add ci workflow

ci: add ci workflow #15

Workflow file for this run

name: CI
on:
pull_request:
push:
branches: [ main ]
jobs:
scan_ruby:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true
- name: Scan for common Rails security vulnerabilities using static analysis
run: bundle exec brakeman --no-pager
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true
- name: Lint code for consistent style
run: bundle exec rubocop -f github || true # 等修好再移除 || true
rspec_test:
runs-on: ubuntu-latest
# ref: https://docs.github.com/en/actions/use-cases-and-examples/using-containerized-services/creating-postgresql-service-containers
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:14
# Provide the password for postgres
env:
POSTGRES_PASSWORD: rails_github_actions_pa55w0rd
POSTGRES_USER: rails_github_actions
POSTGRES_DB: rails_github_actions_test
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get -yqq install libpq-dev
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true
# ref: https://blog.niclin.tw/2019/10/31/building-a-rails-ci-piepline-and-run-rspec-on-github-actions/
- name: Setup test database
env:
RAILS_ENV: test
PG_USERNAME: rails_github_actions
PG_PASSWORD: rails_github_actions_pa55w0rd
PG_HOST: localhost
PG_PORT: 5432
PG_DATABASE: rails_github_actions_test
run: |
cp config/database.ci.yml config/database.yml
bundle exec rake db:create db:migrate
- name: Run rspec
env:
RAILS_ENV: test
run: bundle exec rspec