Skip to content

Instantly share code, notes, and snippets.

@skelz0r

skelz0r/ci.yml Secret

Created January 16, 2021 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skelz0r/1edd3b9aef22fde307ed2031684e14be to your computer and use it in GitHub Desktop.
Save skelz0r/1edd3b9aef22fde307ed2031684e14be to your computer and use it in GitHub Desktop.
env:
CI: true
RUBY_VERSION: 2.7.2
COVERAGE: true
name: Rails tests
on:
push:
branches-exclude:
- master
- dependabot/*
pull_request:
jobs:
test-and-lint:
name: RSpec
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: rails_app
POSTGRES_PASSWORD: "password"
POSTGRES_DB: rails_app_test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup ruby
uses: actions/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
- name: Get Yarn Cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Cache Node Modules
id: node-modules-cache
uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install postgres client
run: sudo apt-get install libpq-dev
- name: Cache Gems
uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Cache Assets
id: assets-cache
uses: actions/cache@v1
with:
path: public/packs-test
key: ${{ runner.os }}-assets-${{ steps.extract_branch.outputs.branch }}
restore-keys: |
${{ runner.os }}-assets-
- name: Bundle install
run: |
gem install bundler
bundle config path vendor/bundle
bundler install --jobs 4 --retry 3
- name: Yarn install
run: bin/rails yarn:install
- name: Compile Assets
shell: bash
run: |
bundle exec rails webpacker:compile
- name: Create database
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
run: |
bundler exec rails db:create RAILS_ENV=test
bundler exec rails db:schema:load RAILS_ENV=test
- name: Run tests
run: bundler exec rspec
- name: Rubocop Linter Action
uses: andrewmcodes/rubocop-linter-action@v3.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Brakeman
uses: devmasx/brakeman-linter-action@v1.0.0
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Force push develop to master
run: |
if [ `git branch --show-current` = "develop" ] ; then
git reset --hard && \
git push --force origin develop:master && \
git fetch && \
[[ ! -s \"$(git rev-parse --git-dir)/shallow\" ]] || git fetch --unshallow
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment