Add CI workflow with Python, JavaScript tests, linting, and build ver… #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ['3.9', '3.10', '3.11', '3.12'] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Cache pip dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install pytest pytest-cov | |
| - name: Create config directory | |
| run: | | |
| mkdir -p ~/.config/helpful-tools | |
| - name: Run unit tests | |
| run: | | |
| python -m pytest tests/ \ | |
| --ignore=tests/text-diff/test_text_diff_frontend.py \ | |
| --ignore=tests/jwt-decoder/ \ | |
| --ignore=tests/cron-parser/ \ | |
| --ignore=tests/regex/ \ | |
| --ignore=tests/scientific-calculator/ \ | |
| -v \ | |
| --tb=short \ | |
| --cov=src \ | |
| --cov-report=xml \ | |
| --cov-report=term-missing | |
| env: | |
| PYTHONPATH: ${{ github.workspace }}/src:${{ github.workspace }} | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v4 | |
| if: matrix.python-version == '3.11' | |
| with: | |
| files: ./coverage.xml | |
| fail_ci_if_error: false | |
| verbose: true | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install linting tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install flake8 | |
| - name: Run flake8 | |
| run: | | |
| flake8 src/ --count --select=E9,F63,F7,F82 --show-source --statistics | |
| flake8 src/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
| js-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run JavaScript tests | |
| run: npm test | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: [test, lint, js-test] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Verify application starts | |
| run: | | |
| timeout 10 python app.py --port 8888 & | |
| sleep 5 | |
| curl -f http://127.0.0.1:8888/health || exit 1 | |
| env: | |
| PYTHONPATH: ${{ github.workspace }}/src:${{ github.workspace }} |