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

ci: Validation of OpenAPI files using GitHub Actions #6

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
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
78 changes: 78 additions & 0 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: folksonomy
POSTGRES_PORT: 5432
ports: ['5432:5432']
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8' # Version range or exact version of a Python version to use, using SemVer's version range syntax
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
# Note you can specify username, pass, and db name according to the action readme
# - uses: harmon758/postgresql-action@v1
# with:
# postgresql version: '11' See https://hub.docker.com/_/postgres for available versions
# postgresql user: postgres
# postgresql password: postgres
# postgresql db: 'folksonomy'
- name: psycopg2 prerequisites
run: sudo apt-get install libpq-dev
- name: Create database
run: |
PGPASSWORD=postgres psql -U postgres -h 127.0.0.1 -d folksonomy -f ./db/db_setup.sql
- name: Install PostgreSQL client
run: |
sudo apt-get install --yes postgresql-client
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- 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 treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- run: python ./generate_openapi_json.py | tee openapi.json
# Runs a single command using the runners shell
- name: swagger-cli
uses: vaibhav-jain/spectral-action/@v2.6
with:
file_path: ./openapi.json #examples/swagger.yaml
- name: Test with pytest
env:
DATABASE_URL: 'postgres://postgres:postgres@localhost:5432/folksonomy'
PGUSER: "postgres"
PGPASSWORD: "postgres"
PGDB: "folksonomy"
PGPORT: 5432
PGURL: "localhost"
run: |
pytest
2 changes: 1 addition & 1 deletion folksonomy/api.py
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@
@app.on_event("startup")
async def startup():
global db, cur
db = psycopg2.connect("dbname=folksonomy")
db = psycopg2.connect(database="folksonomy", user="postgres" , password="postgres" , host="127.0.0.1")
db.set_session(autocommit=True)
cur = db.cursor()