Skip to content

Instantly share code, notes, and snippets.

@herko
Created May 20, 2021 08:11
Show Gist options
  • Save herko/1f4fccdb08dfb5e27e36fcedccaa7e38 to your computer and use it in GitHub Desktop.
Save herko/1f4fccdb08dfb5e27e36fcedccaa7e38 to your computer and use it in GitHub Desktop.
Github CI
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
name: Ruby
on:
push:
branches: [ main ]
jobs:
test:
name: "Run test suite"
runs-on: ubuntu-latest
services:
db:
image: postgres:12
ports: ['5432:5432']
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
with:
ruby-version: '2.7.x'
- name: Install dependencies
run: |
sudo apt-get -yqq install libpq-dev
- name: Setup bundler cache
uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gem-use-ruby-${{ hashFiles('**/Gemfile.lock') }}
- name: Install ruby dependencies
env:
RAILS_ENV: test
run: |
gem install bundler -v 2.2.4
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Run linters
run: |
bundle exec standardrb
- name: Setup database
env:
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
RAILS_ENV: test
run: |
bundle exec rails db:setup
- name: Run general test suite
env:
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
run: |
bundle exec rails test
deploy:
name: "Deploy to production"
needs: [test]
runs-on: ubuntu-latest
steps:
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
chmod 700 ~/.ssh
echo "$SSH_KEY" > ~/.ssh/production.key
chmod 600 ~/.ssh/production.key
cat >>~/.ssh/config <<END
Host production
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/production.key
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_KEY: ${{ secrets.SSH_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
- name: Run deploy commands
run: |
ssh production '
sudo systemctl stop api_herko_sk-production.service
cd $APP_PATH
git fetch && git reset --hard origin/main
./bin/bundle
bundle exec rails db:setup
bundle exec rails db:migrate
sudo systemctl start api_herko_sk-production.service
'
env:
APP_PATH: ${{ secrets.PRODUCTION_APP_PATH }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment