Skip to content

Commit

Permalink
Rewrite github actions to use reusable workflows
Browse files Browse the repository at this point in the history
Also use docker image on staging deploy
  • Loading branch information
gmmcal committed Oct 17, 2023
1 parent 1b52d2d commit 1780ca2
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 317 deletions.
400 changes: 200 additions & 200 deletions .github/workflows/cypress.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
staging:
name: 'Deploy: Staging'
runs-on: ubuntu-20.04
needs: docker_production

if: github.event_name == 'push'

Expand Down
77 changes: 12 additions & 65 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
name: Build

on:
- push
- pull_request
workflow_call:
inputs:
tag-name:
type: string
required: false
default: "gmmcal/gmmcal"
target:
type: string
required: false
default: test

jobs:
docker:
build:
name: 'Docker: Build'
runs-on: ubuntu-20.04

Expand All @@ -28,67 +36,6 @@ jobs:
push: true
context: .
target: test
tags: "gmmcal/gmmcal:test"
tags: ${{ inputs.tag-name }}:${{ inputs.target }}
cache-from: type=registry,ref=gmmcal/gmmcal:buildcache
cache-to: type=registry,ref=gmmcal/gmmcal:buildcache,mode=max

rubocop:
name: 'Lint: Rubocop'
runs-on: ubuntu-20.04
needs: docker

steps:
- name: Run rubocop
run: |
docker run --rm gmmcal/gmmcal:test bundle exec rubocop --config .rubocop.yml .
reek:
name: 'Lint: Reek'
runs-on: ubuntu-20.04
needs: docker

steps:
- name: Run reek
run: |
docker run --rm gmmcal/gmmcal:test bundle exec reek --config .reek.yml .
brakeman:
name: 'Lint: Brakeman'
runs-on: ubuntu-20.04
needs: docker

steps:
- name: Run brakeman
run: |
docker run --rm gmmcal/gmmcal:test bundle exec brakeman
scsslint:
name: 'Lint: SCSSLint'
runs-on: ubuntu-20.04
needs: docker

steps:
- name: Run SCSSLint
run: |
docker run --rm gmmcal/gmmcal:test bundle exec scss-lint --config .scss-lint.yml
tests:
name: 'Unit: Backend'
runs-on: ubuntu-20.04
needs: docker

services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: gmmcalcombr_test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Run rubocop
run: |
docker run --network=${{ job.services.postgres.network }} -e DATABASE_URL='postgres://postgres:postgres@postgres:5432/gmmcalcombr_test' -e DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true --rm gmmcal/gmmcal:test
55 changes: 8 additions & 47 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,16 @@
name: Lint

on:
- pull_request
workflow_call:
inputs:
command:
type: string
required: true

jobs:
bundler-audit:
name: 'Lint: Bundler Audit'
rubocop:
runs-on: ubuntu-20.04

container:
image: ruby:3.2.2

steps:
- uses: actions/checkout@v3

- name: Install Bundler Audit
run: gem install bundler-audit

- name: Update advisory database
run: bundler-audit update

- name: Run bundler-audit
run: bundler-audit

eslint:
name: 'Lint: ESLint'
runs-on: ubuntu-20.04

container:
image: node:18

steps:
- uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-gmmcal-${{ hashFiles('/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-gmmcal-
- name: Run yarn install
run: yarn install

- name: Run ESLint - Application
run: yarn eslint

- name: Run ESLint - Tests
run: yarn eslint:tests
- name: Execute linter
run: docker run --rm gmmcal/gmmcal:test ${{ inputs.command }}
117 changes: 117 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Pipeline

on:
- pull_request

jobs:
build:
name: Build image
uses: gmmcal/gmmcal.com.br/.github/workflows/docker.yml@reusable

rubocop:
name: 'Lint: Rubocop'
uses: gmmcal/gmmcal.com.br/.github/workflows/lint.yml@reusable
with:
command: bundle exec rubocop --config .rubocop.yml .
needs: build

# reek:
# name: 'Lint: Reek'
# runs-on: ubuntu-20.04
# needs: build

# steps:
# - name: Run reek
# run: |
# docker run --rm gmmcal/gmmcal:test bundle exec reek --config .reek.yml .

# brakeman:
# name: 'Lint: Brakeman'
# runs-on: ubuntu-20.04
# needs: build

# steps:
# - name: Run brakeman
# run: |
# docker run --rm gmmcal/gmmcal:test bundle exec brakeman

# scsslint:
# name: 'Lint: SCSSLint'
# runs-on: ubuntu-20.04
# needs: build

# steps:
# - name: Run SCSSLint
# run: |
# docker run --rm gmmcal/gmmcal:test bundle exec scss-lint --config .scss-lint.yml

# tests:
# name: 'Unit: Backend'
# runs-on: ubuntu-20.04
# needs: build

# services:
# postgres:
# image: postgres:16
# env:
# POSTGRES_USER: postgres
# POSTGRES_PASSWORD: postgres
# POSTGRES_DB: gmmcalcombr_test
# ports:
# - 5432:5432
# options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

# steps:
# - name: Run rubocop
# run: |
# docker run --network=${{ job.services.postgres.network }} -e DATABASE_URL='postgres://postgres:postgres@postgres:5432/gmmcalcombr_test' -e DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true --rm gmmcal/gmmcal:test

# bundler-audit:
# name: 'Lint: Bundler Audit'
# runs-on: ubuntu-20.04

# container:
# image: ruby:3.2.2

# steps:
# - uses: actions/checkout@v3

# - name: Install Bundler Audit
# run: gem install bundler-audit

# - name: Update advisory database
# run: bundler-audit update

# - name: Run bundler-audit
# run: bundler-audit

# eslint:
# name: 'Lint: ESLint'
# runs-on: ubuntu-20.04

# container:
# image: node:18

# steps:
# - uses: actions/checkout@v4

# - name: Get yarn cache directory path
# id: yarn-cache-dir-path
# run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

# - uses: actions/cache@v3
# id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
# with:
# path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
# key: ${{ runner.os }}-yarn-gmmcal-${{ hashFiles('/yarn.lock') }}
# restore-keys: |
# ${{ runner.os }}-yarn-gmmcal-

# - name: Run yarn install
# run: yarn install

# - name: Run ESLint - Application
# run: yarn eslint

# - name: Run ESLint - Tests
# run: yarn eslint:tests
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server", "-b", "0.0.0.0"]
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]

# Backend Test image
FROM base as test
Expand Down
9 changes: 7 additions & 2 deletions bin/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#!/bin/bash -e

# If running the rails server then create or migrate existing database
# ./bin/rails server (executed on production image)
if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then
./bin/rails db:migrate
fi

# bundle exec rails <anything> (executed on development image)
if [ "${3}" == "rails" ]; then
./bin/rails db:prepare
./bin/rails db:seed:all
fi

# bundle exec rspec
# bundle exec rspec (executed on test image)
if [ "${3}" == "rspec" ]; then
./bin/rails db:migrate
fi
Expand Down
9 changes: 7 additions & 2 deletions render.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ services:
pullRequestPreviewsEnabled: false
plan: free
region: frankfurt
domains:
- www.gustavocunha.dev
envVars:
- key: DATABASE_URL
fromDatabase:
Expand All @@ -34,12 +36,15 @@ services:
- type: web
name: gustavocunha-staging
env: ruby
buildCommand: "bundle install; bundle exec rake assets:precompile; bundle exec rake assets:clean; bundle exec rake db:migrate db:seed:all db:cache:clear;"
startCommand: "bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-production}"
runtime: image
image:
url: gmmcal/gmmcal:latest
autoDeploy: false
pullRequestPreviewsEnabled: true
plan: free
region: frankfurt
domains:
- staging.gustavocunha.dev
envVars:
- key: DATABASE_URL
fromDatabase:
Expand Down

0 comments on commit 1780ca2

Please sign in to comment.