Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger CI #4

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9dc49b9
run ci for develop branch too
Reimirno Oct 24, 2023
fc379eb
separate dev dep
Reimirno Oct 24, 2023
6d6bb64
add auditing deps
Reimirno Oct 24, 2023
446d4ba
add e2e test and flask commands
Reimirno Oct 24, 2023
b048042
attempt to access env var
Reimirno Oct 24, 2023
770811e
attempt to export env var
Reimirno Oct 24, 2023
3d57b30
attempt to export var and secret separately
Reimirno Oct 24, 2023
88539bf
resolve folder permission err 13
Reimirno Oct 24, 2023
a192846
configure correct workflow permission
Reimirno Oct 24, 2023
90bd8b2
see pytest exit code
Reimirno Oct 24, 2023
35ab71b
make sure pipe propagates error
Reimirno Oct 24, 2023
47fe1f9
configure headless chrome
Reimirno Oct 24, 2023
d203214
remove gh env
Reimirno Oct 24, 2023
446f0fd
remove safety check action; running it via cli instead
Reimirno Oct 24, 2023
2fd6c92
break audit to 5 jobs
Reimirno Oct 24, 2023
6ee107d
composite action refactor attempt
Reimirno Oct 24, 2023
c2d556c
use local action
Reimirno Oct 24, 2023
ed47276
check out before runnign local action
Reimirno Oct 24, 2023
ab22913
refactor composite action
Reimirno Oct 24, 2023
c4064c8
break down lint and test job
Reimirno Oct 24, 2023
3a34251
pytest matrix
Reimirno Oct 24, 2023
8c655a2
upload and download report artifacts
Reimirno Oct 25, 2023
9d628f7
configure artifact download path
Reimirno Oct 25, 2023
e6a4d1a
post comments separately
Reimirno Oct 25, 2023
9c95af5
fix typo
Reimirno Oct 25, 2023
1e8c679
add codeql
Reimirno Oct 25, 2023
1471cc6
try flake8 commenter
Reimirno Oct 25, 2023
bdb57e8
suppress flake8 errors
Reimirno Oct 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
max-line-length = 127
exclude = .git,__pycache__,.venv,build,dist,docs
exclude = .git,__pycache__,venv,build,dist,docs
ignore = E722, F401
max-complexity = 10
20 changes: 20 additions & 0 deletions .github/actions/bootstrap/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "bootstrap"
description: "Sets up Python, exports all Github environments and installs dependencies"
inputs:
dev-dep:
description: "Whether to install development dependencies"
required: false
default: "true"
runs:
using: "composite"
steps:
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
if [ "${{ inputs.dev-dep }}" = "true" ]; then pip install -r requirements-dev.txt; fi
shell: bash
47 changes: 47 additions & 0 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Audit

on:
push:
branches: ["main", "master", "develop"]
pull_request:
branches: ["main", "master", "develop"]

permissions:
contents: read

jobs:
check-broken-dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Bootstrap
uses: ./.github/actions/bootstrap
- name: Audit with pip
run: |
pip check
check-package-updates:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Bootstrap
uses: ./.github/actions/bootstrap
- name: Audit with pip
run: |
pip list --outdated
audit-with-safety:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Bootstrap
uses: ./.github/actions/bootstrap
- name: Audit with safety
run: |
safety check
audit-with-pip-audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Bootstrap
uses: ./.github/actions/bootstrap
- name: Audit with pip-audit
uses: pypa/[email protected]
81 changes: 81 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: ["master", "main", "develop"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["master", "main", "develop"]
schedule:
- cron: "45 22 * * 5"

jobs:
analyze:
name: Analyze
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ["python"]
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
24 changes: 24 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Lint

on:
push:
branches: ["main", "master", "develop"]
pull_request:
branches: ["main", "master", "develop"]

permissions:
contents: read

jobs:
lint-with-flake8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Bootstrap
uses: ./.github/actions/bootstrap
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# --exit-zero to treats all errors as warnings.
flake8 . --exit-zero --count --statistics
44 changes: 0 additions & 44 deletions .github/workflows/lint_and_test.yml

This file was deleted.

49 changes: 49 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Test

on:
push:
branches: ["main", "master", "develop"]
pull_request:
branches: ["main", "master", "develop"]

permissions:
contents: read
pull-requests: write
issues: write

jobs:
unit-test-with-pytest:
strategy:
matrix:
test-type: ["unit", "e2e"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Bootstrap
uses: ./.github/actions/bootstrap
- name: Exports all Github Environment Secrets
uses: oNaiPs/secrets-to-env-action@v1
with:
secrets: ${{ toJSON(secrets) }}
- name: Exports all Github Environment Variables
uses: oNaiPs/secrets-to-env-action@v1
with:
secrets: ${{ toJSON(vars) }}
- name: Prepare reports directory
run: |
mkdir -p reports
touch reports/pytest-${{ matrix.test-type }}.txt
touch reports/pytest-coverage-${{ matrix.test-type }}.txt
- name: Run tests with pytest and generate reports
run: |
# make sure pipe propogates exit code to fail on test failure
set -o pipefail
pytest --junitxml=reports/pytest-${{ matrix.test-type }}.xml --cov-report=term-missing:skip-covered --cov=server tests/${{ matrix.test-type }}/ | tee reports/pytest-coverage-${{ matrix.test-type }}.txt
set +o pipefail
- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
with:
title: Coverage for ${{ matrix.test-type }} tests
create-new-comment: true
pytest-coverage-path: reports/pytest-coverage-${{ matrix.test-type }}.txt
junitxml-path: reports/pytest-${{ matrix.test-type }}.xml
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,13 @@ ADMIN

You can create an Ok OAuth client [here](https://okpy.org/admin/clients/), though it will need to be approved by an Ok admin before it can be used.

## (Temporarily keeping it here) Testing and CI

run test and get coverage report

```
pytest --cov=server tests/
```

print existing coverage report
## (Temporarily keeping it here)

```
coverage report
flask e2e
flask unit
flask test
flask cov
flask audit
flask lint
```
7 changes: 7 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
click==7.1.2
pytest==7.4.2
pytest-cov==4.1.0
flake8
safety
pip-audit
selenium
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
click==7.1.2 # dev packages
pytest==7.4.2 # dev packages
pytest-cov==4.1.0 # dev packages
markupsafe==2.0.1
email_validator==2.0.0
Flask==1.1.4
Expand Down
1 change: 1 addition & 0 deletions server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ def handle_invalid_access_token(e):
import server.utils.auth # noqa
import server.models # noqa
import server.views # noqa
import tests.conftest # noqa
54 changes: 54 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os

import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

from server import app as flask_app
from server.models import db as sqlalchemy_db
Expand Down Expand Up @@ -37,3 +39,55 @@ def db(app):

sqlalchemy_db.session.remove()
sqlalchemy_db.drop_all()


@pytest.fixture()
def driver():
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=options)
yield driver
driver.close()


@flask_app.cli.command('e2e')
def run_e2e():
print('Running end-to-end tests...')
pytest.main(['-s', 'tests/e2e'])


@flask_app.cli.command('unit')
def run_unit():
print('Running unit tests...')
pytest.main(['-s', 'tests/unit'])


@flask_app.cli.command('test')
def run_all():
print('Running all tests...')
pytest.main(['-s', 'tests'])


@flask_app.cli.command('cov')
def run_cov():
print('Running all tests with coverage...')
pytest.main(['-s', '--cov=server', 'tests'])


@flask_app.cli.command('audit')
def run_audit():
print('Checking for broken dependencies...')
os.system('pip check')
print('Checking for outdated dependencies...')
os.system('pip list --outdated')
print('Auditing with pip-audit...')
os.system('pip-audit')
print('Auditing with safety...')
os.system('safety check')


@flask_app.cli.command('lint')
def run_lint():
print('Running flake8 linter...')
os.system('flake8 server tests')
Empty file added tests/e2e/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions tests/e2e/test_web.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def test_webdriver_health(driver):
"""
Test that webdriver works
"""
driver.get('https://www.google.com')
assert 'Google' in driver.title
Empty file added tests/unit/__init__.py
Empty file.
File renamed without changes.
Loading