Skip to content

Commit

Permalink
Add CI/CD workflows for GitHub Actions
Browse files Browse the repository at this point in the history
Fixes #764
Partially addresses #1010
  • Loading branch information
jagthedrummer committed Oct 20, 2023
1 parent 8329e11 commit 37a9db9
Show file tree
Hide file tree
Showing 11 changed files with 428 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/_database_schema_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow will ensure that when we run `rails db:migrate` that no changes are made to `db/schema.rb`.
#
# This workflow is pimarily meant to be called by other workflows, but it can be run manually.
name: "🔎 ~ Database Schema Check"
on:
workflow_call:
workflow_dispatch:

jobs:
check:
runs-on: ubuntu-latest
env:
RAILS_ENV: test
BUNDLE_JOBS: 2
BUNDLE_RETRY: 3
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Database Schema Check
id: db-schema-check
run : bash ./.circleci/db_schema_check
30 changes: 30 additions & 0 deletions .github/workflows/_deploy_heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow will deploy an app to heroku.
#
# The name of the app to deploy must be passed in.
# HEROKU_API_KEY & HEROKU_EMAIL should be added to your repo secrets to provide deployment credentials.
#
# This workflow is pimarily meant to be called by other workflows, but it can be run manually.
name: 🚢 ~ Deploy to Heroku

on:
workflow_call:
inputs:
heroku-app-name:
required: true
type: string
workflow_dispatch:
inputs:
heroku-app-name:
required: true
type: string

jobs:
heroku:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: akhileshns/[email protected] # This is the action
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: ${{ inputs.heroku-app-name }} #Must be unique in Heroku
heroku_email: ${{secrets.HEROKU_EMAIL}}
12 changes: 12 additions & 0 deletions .github/workflows/_reusable_workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is a dummy workflow that's just here to add a bit of organization to the workflow list.
# Too bad they don't allow you to hide workflows or something.
name: " 🚫 |----- Reusable Worflows Below"
on:
workflow_call:

jobs:
nothing:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
125 changes: 125 additions & 0 deletions .github/workflows/_run_super_scaffolding_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# This workflow will run a few super scaffolding commands and then run tests against the generated code.
#
# This workflow is pimarily meant to be called by other workflows, but it can be run manually.
name: 🏗️ ~ Run super scaffolding tests
on:
workflow_call:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Set N number of parallel jobs you want to run tests on.
# Use higher number if you have slow tests to split them on more parallel jobs.
# Remember to update ci_node_index below to 0..N-1
ci_node_total: [7]
# set N-1 indexes for parallel jobs
# When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc
ci_node_index: [0, 1, 2, 3, 4, 5, 6]
services:
postgres:
image: postgres:11-alpine
ports:
- "5432:5432"
env:
POSTGRES_DB: rails_test
POSTGRES_USER: rails
POSTGRES_PASSWORD: password
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis
ports:
- "6379:6379"
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
RAILS_ENV: test
DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test"
BUNDLE_JOBS: 2
BUNDLE_RETRY: 3
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

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

- name: Cache yarn cache directory
uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Cache node_modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: asset cache
uses: actions/cache@v3
with:
path: |
public/assets
tmp/cache/assets/sprockets
key: asset-cache-${{ runner.os }}-${{ github.ref }}-${{ github.sha }}
restore-keys: |
asset-cache-${{ runner.os }}-${{ github.ref }}-${{ github.sha }}
asset-cache-${{ runner.os }}-${{ github.ref }}-
asset-cache-${{ runner.os }}-
- name: Set up database schema
run: bin/rails db:schema:load

- run: yarn install
- run: yarn build
- run: yarn build:css

# TODO: This might be a bad idea. Maybe we should just have spring in the Gemfile all the time.
- name: Allow adding of spring
run: bundle config unset deployment

- name: Add spring
run: bundle add spring

- name: 'Setup Super Scaffolding System Test'
run: bundle exec test/bin/setup-super-scaffolding-system-test
env:
CIRCLE_NODE_INDEX: ${{ matrix.ci_node_index }}

- name: 'Run Super Scaffolding Test'
run: bundle exec rails test test/system/super_scaffolding_test.rb

- name: 'Run Super Scaffolding Partial Test'
run: bundle exec rails test test/system/super_scaffolding_partial_test.rb

- name: 'Run Super Scaffolding Incoming Webhooks Test'
run: bundle exec rails test test/controllers/webhooks/incoming/some_provider_webhooks_controller_test.rb

- name: Test Summary
uses: test-summary/action@v2
with:
paths: "test/reports/**/TEST-*.xml"
if: always()
115 changes: 115 additions & 0 deletions .github/workflows/_run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# This workflow runs the main test suite.
#
# This workflow is pimarily meant to be called by other workflows, but it can be run manually.
name: "🧪 ~ Run tests"
on:
workflow_call:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Set N number of parallel jobs you want to run tests on.
# Use higher number if you have slow tests to split them on more parallel jobs.
# Remember to update ci_node_index below to 0..N-1
ci_node_total: [7]
# set N-1 indexes for parallel jobs
# When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc
ci_node_index: [0, 1, 2, 3, 4, 5, 6]
services:
postgres:
image: postgres:11-alpine
ports:
- "5432:5432"
env:
POSTGRES_DB: rails_test
POSTGRES_USER: rails
POSTGRES_PASSWORD: password
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis
ports:
- "6379:6379"
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
RAILS_ENV: test
DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test"
BUNDLE_JOBS: 2
BUNDLE_RETRY: 3
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

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

- name: Cache yarn cache directory
uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Cache node_modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: asset cache
uses: actions/cache@v3
with:
path: |
public/assets
tmp/cache/assets/sprockets
key: asset-cache-${{ runner.os }}-${{ github.ref }}-${{ github.sha }}
restore-keys: |
asset-cache-${{ runner.os }}-${{ github.ref }}-${{ github.sha }}
asset-cache-${{ runner.os }}-${{ github.ref }}-
asset-cache-${{ runner.os }}-
- name: Set up database schema
run: bin/rails db:schema:load

- run: yarn install
- run: yarn build
- run: yarn build:css

- name: Run Tests
id: run-tests
env:
AUTH_ENDPOINT: https://no-site.nowhere
AWS_REGION: us-east-1
CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
CI_NODE_INDEX: ${{ matrix.ci_node_index }}
continue-on-error: false
run : ./bin/parallel-ci
shell: bash

- name: Test Summary
uses: test-summary/action@v2
with:
paths: "test/reports/**/TEST-*.xml"
if: always()
27 changes: 27 additions & 0 deletions .github/workflows/_standardrb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow will run standardrb.
#
# This workflow is pimarily meant to be called by other workflows, but it can be run manually.
name: "🔬 ~ Standardrb"
on:
workflow_call:
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
env:
RAILS_ENV: test
BUNDLE_JOBS: 2
BUNDLE_RETRY: 3
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Run Standardrb
id: run-standardrb
run : bundle exec standardrb
47 changes: 47 additions & 0 deletions .github/workflows/ci-cd-pipeline-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This workflow will run whenever commits land on the main branch.
#
# It will run tests and a few safety checks.
#
# If everything passes it can be set to auto-deploy to your production app on Heroku.
#
# This workflow is primarily meant to be triggered automatically, but it can be run manually.
name: " 🎥 Main CI/CD Pipeline (prod)"
on:
workflow_dispatch:
push:
branches: [ "main" ]

jobs:
mini_test:
name: 🧪 MiniTest
uses: ./.github/workflows/_run_tests.yml
secrets: inherit
super_scaffolding:
name: 🏗️ Super Scaffolding Tests
uses: ./.github/workflows/_run_super_scaffolding_tests.yml
secrets: inherit
standardrb:
name: 🔬 Standardrb
uses: ./.github/workflows/_standardrb.yml
secrets: inherit
db_schema:
name: 🔎 DB Schema Check
uses: ./.github/workflows/_database_schema_check.yml
secrets: inherit
# If you'd like to auto-deploy to your production environment you can uncomment this next block.
# You'll need to set HEROKU_EMAIL and HEROKU_API_KEY in your repo secrets.
# Be sure to set the app name correctly below.
# deploy:
# name: 🚢 Deploy to Heroku
# uses: ./.github/workflows/_deploy_heroku.yml
# needs: [mini_test, super_scaffolding, standardrb, db_schema]
# secrets: inherit
# with:
# heroku-app-name: ""
deploy:
name: 🚢 Deploy to Heroku
uses: ./.github/workflows/_deploy_heroku.yml
needs: [mini_test, super_scaffolding, standardrb, db_schema]
secrets: inherit
with:
heroku-app-name: "bullettrain-co"
Loading

0 comments on commit 37a9db9

Please sign in to comment.