Skip to content

Update ci.yml

Update ci.yml #4

Workflow file for this run

readme-badge:

Check failure on line 1 in .github/workflows/ci.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/ci.yml

Invalid workflow file

The workflow is not valid. .github/workflows/ci.yml (Line: 1, Col: 1): Unexpected value 'readme-badge'

Check failure on line 1 in .github/workflows/ci.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/ci.yml

Invalid workflow file

The workflow is not valid. .github/workflows/ci.yml (Line: 1, Col: 1): Unexpected value 'readme-badge'
name: Update README Badge
runs-on: ubuntu-latest
needs: [build]
if: ${{ success() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create badges directory
run: |
mkdir -p .github/badges
- name: Generate CI badge
uses: schneegans/dynamic-badges-action@v1.6.0
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: ${{ secrets.GIST_ID }}
filename: snatch-ci-status.json
label: CI
message: passing
color: green
# This requires setting up secrets GIST_SECRET and GIST_ID
# Instructions will be provided in the responsename: CI Pipeline
on:
push:
branches:
- main
paths:
- 'Snatch.py'
- 'setup.py'
- 'setup_ffmpeg.py'
- 'interactive_mode.py'
- 'test_run.py'
- 'requirements.txt'
- '.github/workflows/**'
pull_request:
branches:
- main
paths:
- 'Snatch.py'
- 'setup.py'
- 'setup_ffmpeg.py'
- 'interactive_mode.py'
- 'test_run.py'
- 'requirements.txt'
- '.github/workflows/**'
schedule:
- cron: '0 0 * * 0' # Run weekly on Sundays
workflow_dispatch: # Allow manual triggering
jobs:
lint:
name: Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip' # Enable pip caching
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 black isort pylint
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Check formatting with Black
run: black --check Snatch.py setup.py setup_ffmpeg.py interactive_mode.py test_run.py
continue-on-error: true
- name: Check imports with isort
run: isort --check-only --profile black Snatch.py setup.py setup_ffmpeg.py interactive_mode.py test_run.py
continue-on-error: true
- name: Lint with flake8
run: |
# Stop the build if there are Python syntax errors or undefined names
flake8 Snatch.py setup.py setup_ffmpeg.py interactive_mode.py test_run.py --count --select=E9,F63,F7,F82 --show-source --statistics
# Exit-zero treats all errors as warnings
flake8 Snatch.py setup.py setup_ffmpeg.py interactive_mode.py test_run.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Check with pylint
run: |
pylint --disable=all --enable=unused-import,unused-variable,unused-argument,undefined-variable Snatch.py setup.py setup_ffmpeg.py interactive_mode.py test_run.py
continue-on-error: true
- name: Generate linting reports
run: |
mkdir -p reports
flake8 Snatch.py setup.py setup_ffmpeg.py interactive_mode.py test_run.py --output-file=reports/flake8.txt
pylint Snatch.py setup.py setup_ffmpeg.py interactive_mode.py test_run.py -f json > reports/pylint.json || true
- name: Upload linting reports
uses: actions/upload-artifact@v4
with:
name: linting-reports
path: reports/
test:
name: Test
runs-on: ${{ matrix.os }}
needs: lint
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ['3.8', '3.9', '3.10', '3.11']
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
shell: bash
- name: Install FFmpeg (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg
- name: Install FFmpeg (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install ffmpeg -y
- name: Verify FFmpeg installation
run: |
ffmpeg -version
shell: bash
- name: Run basic tests
run: |
python test_run.py
continue-on-error: true
- name: Test with pytest if available
run: |
if [ -d "tests" ]; then
pytest --cov=. --cov-report=xml
else
echo "No tests directory found. Skipping pytest."
echo "Consider adding proper tests for better code quality."
fi
shell: bash
continue-on-error: true
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: ${{ matrix.os }},python${{ matrix.python-version }}
name: ${{ matrix.os }}-python${{ matrix.python-version }}
fail_ci_if_error: false
continue-on-error: true
security-scan:
name: Security Scanning
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install bandit safety
- name: Run Bandit security scanner
run: |
bandit -r Snatch.py setup.py setup_ffmpeg.py interactive_mode.py -f json -o bandit-results.json
continue-on-error: true
- name: Check dependencies for vulnerabilities
run: |
safety check -r requirements.txt --output json --save safety-results.json
continue-on-error: true
- name: Upload security scan results
uses: actions/upload-artifact@v4
with:
name: security-scan-results
path: |
bandit-results.json
safety-results.json
build:
name: Build Package
needs: [test, security-scan]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for proper versioning
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build wheel setuptools twine
- name: Build package
run: |
python setup.py sdist bdist_wheel
- name: Check package with twine
run: |
twine check dist/*
continue-on-error: true
- name: Store built package
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
- name: Test installation from wheel
run: |
pip install dist/*.whl