Skip to content

Instantly share code, notes, and snippets.

@mattvague
Created February 26, 2021 01:49
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 mattvague/dd19cbf078ec1d441959a55febc6b597 to your computer and use it in GitHub Desktop.
Save mattvague/dd19cbf078ec1d441959a55febc6b597 to your computer and use it in GitHub Desktop.
name: ci
on:
push:
paths-ignore:
- 'README.md'
- 'docs/**'
env:
PGUSER: postgres
PGPASSWORD: postgres
jobs:
cancel:
name: 'Cancel Previous Runs'
runs-on: ubuntu-20.04
timeout-minutes: 3
steps:
- uses: styfle/cancel-workflow-action@0.8.0
with:
workflow_id: 3553203
yarn:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: '12'
- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Yarn install
run: yarn install --frozen-lockfile
env:
CYPRESS_INSTALL_BINARY: 0
bundle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
assets:
timeout-minutes: 10
runs-on: ubuntu-latest
needs: [yarn, bundle]
env:
RAILS_ENV: ci
RACK_ENV: ci
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
id: assets-cache
with:
path: |
public/packs
tmp/cache/webpacker
key: assets-cache-v3-${{ runner.os }}-${{ hashFiles('app/javascript/**/*', 'yarn.lock', 'cypress/**/*') }}
restore-keys: |
assets-cache-v3-${{ runner.os }}-
- uses: actions/setup-node@v2-beta
with:
node-version: '14'
- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- uses: ruby/setup-ruby@v1
if: steps.assets-cache.outputs.cache-hit != 'true'
with:
bundler-cache: true
- name: Remove Old Assets
if: steps.assets-cache.outputs.cache-hit != 'true'
run: bin/rails webpacker:clean
- name: Compile Assets
if: steps.assets-cache.outputs.cache-hit != 'true'
run: bin/rails webpacker:compile
lint:
runs-on: ubuntu-latest
needs: [yarn]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: '12'
- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- run: yarn lint
check-types:
runs-on: ubuntu-latest
needs: [yarn]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: '12'
- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- run: yarn tsc
rspec:
timeout-minutes: 3
env:
RAILS_ENV: test
runs-on: ubuntu-latest
needs: [bundle]
services:
postgres:
image: postgres:12
env:
POSTGRES_USER: ${{ env.PGUSER }}
POSTGRES_PASSWORD: ${{ env.PGPASSWORD }}
POSTGRES_DB: learning-app-api_test
ports:
- 5432/tcp
# options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
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: [2]
# 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]
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Build DB
env:
PGPORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port
run: bin/rails db:schema:load
- name: Run Rspec Tests
env:
PGPORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port
KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }}
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }}
KNAPSACK_PRO_FIXED_QUEUE_SPLIT: true
run: bin/rake knapsack_pro:queue:rspec
cypress:
env:
RAILS_ENV: ci
RACK_ENV: ci
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ github.token }}
WEBPACKER_COMPILE: false
CI: 1
CYPRESS_CI: true
TERM: xterm
TS_NODE_PROJECT: 0
runs-on: ubuntu-latest
timeout-minutes: 20
needs: [bundle,yarn,assets]
services:
postgres:
image: postgres:12
env:
POSTGRES_USER: ${{ env.PGUSER }}
POSTGRES_PASSWORD: ${{ env.PGPASSWORD }}
POSTGRES_DB: your_app_db_name
ports:
- 5432/tcp
redis:
image: redis
ports:
- 6379/tcp
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
fail-fast: false
matrix:
ci_node_total: [5]
# 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]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: '12'
- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- uses: actions/cache@v2
with:
path: |
public/packs
tmp/cache/webpacker
key: assets-cache-v3-${{ runner.os }}-${{ hashFiles('app/javascript/**/*', 'yarn.lock', 'cypress/**/*') }}
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Build DB
env:
PGPORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port
run: bin/rails db:schema:load
- name: Run Rails Server in background
run: bin/rails server -p 3000 &
env:
PGPORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port
REDIS_URL: redis://localhost:${{ job.services.redis.ports[6379] }}
- run: npx cypress -v > .cypress-version
- uses: actions/cache@v2
with:
path: ~/.cache/Cypress
key: cypress-cache-v3-${{ runner.os }}-${{ hashFiles('.cypress-version') }}
- run: yarn cypress install
- name: Setup /etc/hosts
run: sudo ./bin/setup_hosts
- uses: actions/setup-node@v2-beta
with:
node-version: '12'
- run: yarn wait-on 'http-get://localhost:3000/graphql' -t 30000
- name: Run tests with Knapsack Pro
env:
KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS }}
KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }}
KNAPSACK_PRO_FIXED_QUEUE_SPLIT: true
KNAPSACK_PRO_TEST_FILE_PATTERN: "{cypress/**/*,app/javascript/**/*.component}.spec.{js,ts,tsx}"
run: yarn knapsack-pro-cypress --record --spec cypress/integration/scenarios/student/do-quiz/check-answer.spec.js
- uses: actions/upload-artifact@v2
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
- uses: actions/upload-artifact@v2
if: failure()
with:
name: cypress-videos
path: cypress/videos
- uses: actions/upload-artifact@v2
if: failure()
with:
name: cypress-logs
path: cypress/logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment