|
| 1 | +name: Test and Build LibCrypto |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + pull_request: |
| 7 | + branches: ["main"] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + test: |
| 12 | + name: Test on Python ${{ matrix.python-version }} |
| 13 | + runs-on: ubuntu-latest |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Python ${{ matrix.python-version }} |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: ${{ matrix.python-version }} |
| 27 | + cache: "pip" |
| 28 | + |
| 29 | + - name: Install dependencies |
| 30 | + run: | |
| 31 | + python -m pip install --upgrade pip |
| 32 | + pip install setuptools wheel |
| 33 | + pip install pytest pytest-cov |
| 34 | + pip install -r requirements.txt |
| 35 | +
|
| 36 | + - name: Install package in development mode |
| 37 | + run: | |
| 38 | + pip install -e . |
| 39 | +
|
| 40 | + - name: Run verification script |
| 41 | + run: | |
| 42 | + # Use the project's verification script which knows how to |
| 43 | + # differentiate internal 'cryptod' vs external pycryptodome. |
| 44 | + python verify_no_deps.py |
| 45 | +
|
| 46 | + - name: Run tests with pytest |
| 47 | + run: | |
| 48 | + pytest tests/ -v --tb=short |
| 49 | +
|
| 50 | + - name: Run tests with coverage |
| 51 | + if: matrix.python-version == '3.12' |
| 52 | + run: | |
| 53 | + pytest tests/ -v --cov=libcrypto --cov-report=term-missing --cov-report=xml |
| 54 | +
|
| 55 | + - name: Upload coverage to Codecov |
| 56 | + if: matrix.python-version == '3.12' |
| 57 | + uses: codecov/codecov-action@v4 |
| 58 | + with: |
| 59 | + file: ./coverage.xml |
| 60 | + flags: unittests |
| 61 | + name: codecov-umbrella |
| 62 | + fail_ci_if_error: false |
| 63 | + |
| 64 | + lint: |
| 65 | + name: Lint and Code Quality |
| 66 | + runs-on: ubuntu-latest |
| 67 | + |
| 68 | + steps: |
| 69 | + - name: Checkout repository |
| 70 | + uses: actions/checkout@v4 |
| 71 | + |
| 72 | + - name: Set up Python 3.12 |
| 73 | + uses: actions/setup-python@v5 |
| 74 | + with: |
| 75 | + python-version: "3.12" |
| 76 | + cache: "pip" |
| 77 | + |
| 78 | + - name: Install dependencies |
| 79 | + run: | |
| 80 | + python -m pip install --upgrade pip |
| 81 | + pip install flake8 |
| 82 | +
|
| 83 | + - name: Lint with flake8 |
| 84 | + run: | |
| 85 | + # Stop the build if there are Python syntax errors or undefined names |
| 86 | + flake8 src/libcrypto --count --select=E9,F63,F7,F82 --show-source --statistics |
| 87 | + # Exit-zero treats all errors as warnings |
| 88 | + flake8 src/libcrypto --count --exit-zero --max-complexity=12 --max-line-length=120 --statistics |
| 89 | +
|
| 90 | + - name: Check formatting with black (optional) |
| 91 | + continue-on-error: true |
| 92 | + run: | |
| 93 | + pip install black |
| 94 | + black --check src/libcrypto |
| 95 | +
|
| 96 | + - name: Check import sorting with isort (optional) |
| 97 | + continue-on-error: true |
| 98 | + run: | |
| 99 | + pip install isort |
| 100 | + isort --check-only src/libcrypto |
| 101 | +
|
| 102 | + build: |
| 103 | + name: Build Distribution |
| 104 | + runs-on: ubuntu-latest |
| 105 | + needs: [test, lint] |
| 106 | + |
| 107 | + steps: |
| 108 | + - name: Checkout repository |
| 109 | + uses: actions/checkout@v4 |
| 110 | + |
| 111 | + - name: Set up Python 3.12 |
| 112 | + uses: actions/setup-python@v5 |
| 113 | + with: |
| 114 | + python-version: "3.12" |
| 115 | + cache: "pip" |
| 116 | + |
| 117 | + - name: Install build dependencies |
| 118 | + run: | |
| 119 | + python -m pip install --upgrade pip |
| 120 | + pip install build twine |
| 121 | +
|
| 122 | + - name: Build package |
| 123 | + run: | |
| 124 | + python -m build |
| 125 | +
|
| 126 | + - name: Check distribution |
| 127 | + run: | |
| 128 | + twine check dist/* |
| 129 | +
|
| 130 | + - name: List distribution files |
| 131 | + run: | |
| 132 | + ls -lh dist/ |
| 133 | +
|
| 134 | + - name: Upload distribution artifacts |
| 135 | + uses: actions/upload-artifact@v4 |
| 136 | + with: |
| 137 | + name: python-package-distributions |
| 138 | + path: dist/ |
| 139 | + |
| 140 | + test-install: |
| 141 | + name: Test Installation |
| 142 | + runs-on: ${{ matrix.os }} |
| 143 | + needs: build |
| 144 | + strategy: |
| 145 | + fail-fast: false |
| 146 | + matrix: |
| 147 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 148 | + python-version: ["3.8", "3.12"] |
| 149 | + |
| 150 | + steps: |
| 151 | + - name: Set up Python ${{ matrix.python-version }} |
| 152 | + uses: actions/setup-python@v5 |
| 153 | + with: |
| 154 | + python-version: ${{ matrix.python-version }} |
| 155 | + |
| 156 | + - name: Download distribution artifacts |
| 157 | + uses: actions/download-artifact@v4 |
| 158 | + with: |
| 159 | + name: python-package-distributions |
| 160 | + path: dist/ |
| 161 | + |
| 162 | + - name: Install from wheel |
| 163 | + shell: bash |
| 164 | + run: | |
| 165 | + pip install dist/*.whl |
| 166 | +
|
| 167 | + - name: Test basic import |
| 168 | + run: | |
| 169 | + python -c "import libcrypto; from libcrypto import PrivateKey, Wallet, generate_mnemonic; print('✅ LibCrypto imported successfully')" |
| 170 | +
|
| 171 | + - name: Verify no external crypto dependencies |
| 172 | + run: | |
| 173 | + python -c "import sys; import libcrypto; has_ecdsa = 'ecdsa' in sys.modules; has_crypto = 'Crypto' in sys.modules; is_internal = 'libcrypto' in str(getattr(sys.modules.get('Crypto'), '__file__', '')) if has_crypto else False; assert not has_ecdsa, 'ecdsa should not be loaded'; assert not has_crypto or is_internal, 'external pycryptodome should not be loaded'; print('✅ No external crypto dependencies')" |
| 174 | +
|
| 175 | + - name: Test key generation |
| 176 | + run: | |
| 177 | + python -c "from libcrypto import PrivateKey; pk = PrivateKey(1); print(f'Public key: {pk.get_public_key().hex[:32]}...'); print('✅ Key generation works')" |
0 commit comments