Skip to content

Commit

Permalink
ci: CodeQL, lint, format (#26)
Browse files Browse the repository at this point in the history
* chore(ci): add CodeQL analysis

* chore(ci): lint with mypy

* chore(ci): format with Black and isort

* chore(ci): lint on push to all branches

* Formatted using isort and black

* chore(ci/lint): install requirements

Co-authored-by: Auto format <[email protected]>
  • Loading branch information
hizkifw and Auto format authored Apr 23, 2022
1 parent 723b400 commit 6221e2f
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 16 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 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: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '0 0 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-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.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# 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.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
5 changes: 4 additions & 1 deletion .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: docker-build

on:
push: {}
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
docker:
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Format

on: [ push ]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Python 3.10
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Install dependencies
run: |
pip install --upgrade pip
pip install black isort
- name: Format
run: |
black .
isort **/**.py
git config --global user.name 'Auto format'
git config --global user.email '[email protected]'
git diff --quiet && git diff --staged --quiet || git commit -am 'Formatted using isort and black' && git push
31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint

on:
push: {}
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install mypy
- name: Analysing the code with mypy
run: |
mypy .
15 changes: 8 additions & 7 deletions fc2_live_dl/FC2LiveDL.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/usr/bin/env python3

from datetime import datetime
import http.cookies
import asyncio
import aiohttp
import pathlib
import http.cookies
import json
import time
import os
import pathlib
import time
from datetime import datetime

import aiohttp

from .util import Logger, sanitize_filename
from .ffmpeg import FFMpeg
from .fc2 import FC2LiveStream, FC2WebSocket
from .ffmpeg import FFMpeg
from .hls import HLSDownloader
from .util import Logger, sanitize_filename


class FC2LiveDL:
Expand Down
4 changes: 2 additions & 2 deletions fc2_live_dl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from importlib.metadata import version
import argparse
import asyncio
import json
import sys
from importlib.metadata import version

from .util import Logger, SmartFormatter
from .FC2LiveDL import FC2LiveDL
from .util import Logger, SmartFormatter

try:
__version__ = version(__name__)
Expand Down
7 changes: 4 additions & 3 deletions fc2_live_dl/fc2.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import asyncio
import base64
import html
import json
import time
import html
from .util import Logger, AsyncMap

from .util import AsyncMap, Logger


class FC2WebSocket:
Expand Down Expand Up @@ -57,7 +58,7 @@ async def get_hls_information(self):
while msg is None and tries < max_tries:
msg = await self._send_message_and_wait("get_hls_information", timeout=5)

backoff_delay = 2 ** tries
backoff_delay = 2**tries
tries += 1

if msg is None:
Expand Down
1 change: 1 addition & 0 deletions fc2_live_dl/ffmpeg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import signal

from .util import Logger


Expand Down
3 changes: 2 additions & 1 deletion fc2_live_dl/hls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio
import time
from .util import Logger

from .fc2 import FC2WebSocket
from .util import Logger


class HLSDownloader:
Expand Down
4 changes: 2 additions & 2 deletions fc2_live_dl/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import asyncio
import re
import sys
import asyncio
import argparse
from datetime import datetime


Expand Down

0 comments on commit 6221e2f

Please sign in to comment.