diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..9bae740 --- /dev/null +++ b/.flake8 @@ -0,0 +1,10 @@ +[flake8] +max-line-length = 100 +# Hard errors only (syntax errors and undefined names) are enforced in CI. +# Style warnings are reported with --exit-zero. +exclude = + .git, + __pycache__, + migrations, + .venv, + venv diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8ad0be2 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,98 @@ +name: CI + +on: + push: + branches: ["main"] + tags: ["v*.*.*"] + pull_request: + branches: ["main"] + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - name: Install dependencies + run: pip install flake8 + + - name: Lint with flake8 + run: | + # Stop the build on syntax errors or undefined names + flake8 musicround/ --count --select=E9,F63,F7,F82 --show-source --statistics + # Warn on style issues (exit-zero means the step won't fail on style warnings) + flake8 musicround/ --count --exit-zero --statistics + + test: + name: Test + runs-on: ubuntu-latest + permissions: + contents: read + actions: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y ffmpeg + + - name: Install Python dependencies + run: pip install -r requirements.txt + + - name: Run tests with coverage + env: + FLASK_ENV: testing + SECRET_KEY: ci-test-secret-key + AUTOMATION_TOKEN: ci-test-automation-token + run: | + pytest tests/ -v --cov=musicround --cov-report=xml --cov-report=term-missing + + - name: Upload coverage report + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: coverage.xml + retention-days: 14 + + docker-build: + name: Docker Build (validation) + runs-on: ubuntu-latest + needs: [lint, test] + permissions: + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image + uses: docker/build-push-action@v6 + with: + context: . + push: false + tags: quizzicalbeats:ci + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 048bb9d..fae8cd3 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -23,8 +23,56 @@ env: jobs: - build: + ci: + name: Tests & Lint + runs-on: ubuntu-latest + permissions: + contents: read + actions: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y ffmpeg + + - name: Install Python dependencies + run: pip install -r requirements.txt + + - name: Lint with flake8 + run: | + pip install flake8 + # Stop the build on syntax errors or undefined names + flake8 musicround/ --count --select=E9,F63,F7,F82 --show-source --statistics + # Warn on style issues (exit-zero means the step won't fail on style warnings) + flake8 musicround/ --count --exit-zero --statistics + + - name: Run tests with coverage + env: + FLASK_ENV: testing + SECRET_KEY: ci-test-secret-key + AUTOMATION_TOKEN: ci-test-automation-token + run: | + pytest tests/ -v --cov=musicround --cov-report=xml --cov-report=term-missing + + - name: Upload coverage report + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: coverage.xml + retention-days: 14 + + build: + needs: [ci] runs-on: ubuntu-latest permissions: contents: read