Skip to content

Commit

Permalink
Expansion of testing and addition of coverage per Summer 2020 key res…
Browse files Browse the repository at this point in the history
…ults (#188)

* add pytest-cov

* failing test

* repeat

* #187

* testing measure

* fix workflow name

* i guess checks != github actions

* remove repeat

* fix test

* add coveralls to requirements

* fix workflow syntax

* add TestData

* use TestData for classinfo

* use plainto_tsquery

* commend unused functions

* fix tests

* more tests for classinfo

* more tests

* change TestData to module scope

* add test script for running tests

* singleton comparison

* unreachable code

* Add reload_data and clear_db to TestData. Add tests for semester_date_mapping

* add cypress

* add coverage reporting for cypress

* move lint from pr-cd to ci

* wait for all checks before running pr-cd

* beep boop Github Action Master Branch CI Prettier hard at work

* accesslint slowwwww

* add workflow for cypress with coverage

* override baseurl in ci

* ci check needs cypress and add env var for coveralls

* remove examples

* fixes to cypress workflow

* remove working dir

* don't use docker for api workflow

* forgot python setup

* add DB_PORT

* db fixes

* more fixes

* fix db setup

* add coveralls upload

* use codecov instead of coveralls

* use bash codecov for js

* add codecov badge to readme

* config for codecov

* Renaming jobs

* move test_build to ci and remove testing workflow fail

Co-authored-by: I'm a Github Action <beepboop@github.com>
  • Loading branch information
123joshuawu and I'm a Github Action authored Aug 21, 2020
1 parent 0650390 commit 37c6805
Show file tree
Hide file tree
Showing 39 changed files with 9,836 additions and 117 deletions.
14 changes: 14 additions & 0 deletions .coveragec
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[run]
omit =
# ignore all tests
tests/*
conftest.py

# ignore db and web
src/data/*
src/web/*

# ignore non application code
scripts/*
ops/*
bin/*
194 changes: 185 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,45 @@ name: CI
on: push

jobs:
BackendUnitTests:
name: Run unit unit tests on backend
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
persist-credentials: false
ref: ${{ github.head_ref }}
- name: Run prettier on src/web
working-directory: src/web
run: |
PRETTIER_VERSION=$(cat package.json | \
grep \"prettier\" | \
tr -d '[:space:]' | \
awk -F: '{print substr($2, 2, length($2) - 3)}')
if ! npx prettier@$PRETTIER_VERSION "**/*.(js|vue)" --check;
then
echo "Running prettier"
npx prettier@$PRETTIER_VERSION "**/*.(js|vue)" --write
echo "Setting up git"
git config --global user.name "I'm a Github Action"
git config --global user.email "beepboop@github.com"
git remote set-url origin https://x-access-token:${{ secrets.LINT_PAT }}@github.com/${{ github.repository }}
echo "Committing changes"
git commit -am "beep boop Github Action Master Branch CI Prettier hard at work"
git push
echo "Changes pushed"
exit 1
else
echo "Files are clean"
fi
backend-unit-tests:
needs: lint
name: Run backend unit tests
runs-on: ubuntu-18.04

services:
Expand Down Expand Up @@ -45,20 +82,159 @@ jobs:
- name: Install dependencies
run: pip install -r src/api/requirements.txt -r tests/requirements.txt

- name: Create database tables
- name: Run unit tests with coverage
env:
DB_PORT: ${{ job.services.postgres.ports[5432] }}
DB_USER: postgres
DB_PASS: postgres
TEST_CSV: rpi_data/summer-2020.csv
PGHOST: localhost
PGPORT: ${{ job.services.postgres.ports[5432] }}
PGUSER: postgres
PGPASSWORD: postgres
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
bash build.sh
working-directory: ./src/data
bash scripts/test.sh
bash <(curl -s https://codecov.io/bash)
cypress:
needs: lint
name: Run integration tests using cypress
runs-on: ubuntu-latest

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

steps:
- uses: actions/checkout@v2

- name: Setup database
working-directory: src/data
env:
PGHOST: localhost
PGPORT: ${{ job.services.postgres.ports[5432] }}
PGUSER: postgres
PGPASSWORD: postgres
run: |
bash build.sh
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8

- name: Update pip
run: python -m pip install --upgrade pip

- name: Load cache for pip
uses: actions/cache@v1
with:
path: ~/.cache/pip
key: |
${{ runner.os }}-backend-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-backend-pip-
- name: Install dependencies
run: pip install -r src/api/requirements.txt

- name: Run unit tests
run: pytest --ignore="src/yacs-web" -s
- name: Start API
working-directory: src/api
env:
DB_PORT: ${{ job.services.postgres.ports[5432] }}
DB_USER: postgres
DB_PASS: postgres
TEST_CSV: rpi_data/summer-2020.csv
DB_PORT: ${{ job.services.postgres.ports[5432] }}
run: |
python app.py &
curl \
--retry 5 \
--retry-delay 1 \
--retry-connrefused \
http://localhost:5000
- name: Start web
working-directory: src/web
run: |
npm ci
npm run serve:test &
- name: Seed test data
working-directory: rpi_data
run: |
function load_semester() {
curl \
--location \
--request POST \
'http://localhost:8080/api/bulkCourseUpload' \
--form "file=@$1" \
--form 'isPubliclyVisible=true' \
--max-time 60 \
-v
}
load_semester "summer-2020.csv"
load_semester "fall-2020.csv"
- name: Run cypress
uses: cypress-io/github-action@v2
with:
working-directory: tests/integration
wait-on: "http://localhost:8080"

- uses: actions/upload-artifact@v1
if: failure()
with:
name: cypress-screenshots
path: tests/integration/cypress/screenshots
# Test run video was always captured, so this action uses "always()" condition
- uses: actions/upload-artifact@v1
if: always()
with:
name: cypress-videos
path: tests/integration/cypress/videos

- uses: actions/upload-artifact@v1
with:
name: nyc-report
path: tests/integration/coverage/lcov-report

- name: Upload coverage
working-directory: tests/integration
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
npm run report-coverage
bash <(curl -s https://codecov.io/bash)
test-build:
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build production
run: |
docker-compose \
-f docker-compose.yml \
-f docker-compose.production.yml \
build
publish-action-status:
needs: [backend-unit-tests, cypress, test-build]
if: always()
runs-on: ubuntu-latest

steps:
- uses: technote-space/workflow-conclusion-action@v1
- name: Publish status checks
uses: LouisBrunner/checks-action@v0.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: CI
conclusion: ${{ env.WORKFLOW_CONCLUSION }}
75 changes: 35 additions & 40 deletions .github/workflows/pr-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,51 @@ on:
branches: [master]

jobs:
lint:
wait-checks:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
# action doesn't support multiple checks yet so
# use a step for each check
- name: Wait for ci to complete
uses: fountainhead/action-wait-for-check@v1.0.0
id: wait-for-ci
with:
persist-credentials: false
ref: ${{ github.head_ref }}
- name: Run prettier on src/web
working-directory: src/web
run: |
PRETTIER_VERSION=$(cat package.json | \
grep \"prettier\" | \
tr -d '[:space:]' | \
awk -F: '{print substr($2, 2, length($2) - 3)}')
token: ${{ secrets.GITHUB_TOKEN }}
checkName: CI
ref: ${{ github.event.pull_request.head.sha }}

if ! npx prettier@$PRETTIER_VERSION "**/*.(js|vue)" --check;
then
echo "Running prettier"
npx prettier@$PRETTIER_VERSION "**/*.(js|vue)" --write
- name: Check if ci was successful
if: steps.wait-for-ci.outputs.conclusion != 'success'
run: exit 1

echo "Setting up git"
git config --global user.name "I'm a Github Action"
git config --global user.email "beepboop@github.com"
git remote set-url origin https://x-access-token:${{ secrets.LINT_PAT }}@github.com/${{ github.repository }}
echo "Committing changes"
git commit -am "beep boop Github Action Master Branch CI Prettier hard at work"
git push
echo "Changes pushed"
- name: Wait for codefactor to complete
uses: fountainhead/action-wait-for-check@v1.0.0
id: wait-for-codefactor
with:
token: ${{ secrets.GITHUB_TOKEN }}
checkName: CodeFactor
ref: ${{ github.event.pull_request.head.sha }}

exit 1
else
echo "Files are clean"
fi
- name: Check if codefactor was successful
if: steps.wait-for-codefactor.outputs.conclusion != 'success'
run: exit 1

test_build:
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build production
run: |
docker-compose \
-f docker-compose.yml \
-f docker-compose.production.yml \
build
# sorry accesslint u too slow
# - name: Wait for accesslint to complete
# uses: fountainhead/action-wait-for-check@v1.0.0
# id: wait-for-accesslint
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# checkName: AccessLint
# ref: ${{ github.event.pull_request.head.sha }}
#
# - name: Check if accesslint was successful
# if: steps.wait-for-accesslint.outputs.conclusion != 'success'
# run: exit 1

temp_deploy:
needs: test_build
needs: wait-checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ node_modules/
.python-version
*.ipynb*
courses20.xml
.coverage
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
![](https://github.com/YACS-RCOS/yacs.n/workflows/CI/badge.svg)
[![CodeFactor](https://www.codefactor.io/repository/github/yacs-rcos/yacs.n/badge)](https://www.codefactor.io/repository/github/yacs-rcos/yacs.n)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![codecov](https://codecov.io/gh/YACS-RCOS/yacs.n/branch/master/graph/badge.svg)](https://codecov.io/gh/YACS-RCOS/yacs.n)

YACS with support for multi and sub-semesters for any school

Expand Down
20 changes: 20 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
codecov:
require_ci_to_pass: yes

coverage:
precision: 2
round: down
range: "70...100"

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

comment: false
# layout: "reach,diff,flags,tree"
# behavior: default
# require_changes: no
Loading

0 comments on commit 37c6805

Please sign in to comment.