From 44c8df9b02b8d0462839fe1bc776da9166196134 Mon Sep 17 00:00:00 2001 From: Roman Proskuryakov Date: Sun, 3 Dec 2023 20:05:12 +0300 Subject: [PATCH] Add CI including wheels and pyright --- .github/workflows/sdk-wheels.yml | 140 +++++++++++++++++++++++++++++++ .github/workflows/sdk.yml | 48 +++++++++++ sdk/Cargo.lock | 1 + sdk/Cargo.toml | 6 +- sdk/pyproject.toml | 6 +- sdk/test.py | 7 +- 6 files changed, 202 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/sdk-wheels.yml create mode 100644 .github/workflows/sdk.yml diff --git a/.github/workflows/sdk-wheels.yml b/.github/workflows/sdk-wheels.yml new file mode 100644 index 0000000..8ca9487 --- /dev/null +++ b/.github/workflows/sdk-wheels.yml @@ -0,0 +1,140 @@ +# This file is autogenerated by maturin v1.3.1 +# To update, run +# +# maturin generate-ci --platform linux --platform macos --platform windows --manifest-path ./sdk/Cargo.toml --output .github/workflows/sdk-wheels.yml github +# +name: SDK Wheels + +on: + push: + paths: + - 'sdk/**' + branches: + - main + - master + tags: + - '*' + pull_request: + paths: + - 'sdk/**' + workflow_dispatch: + +permissions: + contents: read + +jobs: + tests: + uses: ./.github/workflows/sdk.yml + linux: + needs: [tests] + runs-on: ubuntu-latest + strategy: + matrix: + target: [x86_64, x86] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.target }} + args: --release --out dist --find-interpreter --manifest-path ./sdk/Cargo.toml --features openssl/vendored + manylinux: auto + before-script-linux: | + # If we're running on rhel centos, install needed packages. + if command -v yum &> /dev/null; then + yum update -y && yum install -y perl-core libatomic + + # If we're running on i686 we need to symlink libatomic + # in order to build openssl with -latomic flag. + if [[ ! -d "/usr/lib64" ]]; then + ln -s /usr/lib/libatomic.so.1 /usr/lib/libatomic.so + fi + fi + - name: Upload wheels + uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist + + windows: + needs: [tests] + runs-on: windows-latest + strategy: + matrix: + target: [x64, x86] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + architecture: ${{ matrix.target }} + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.target }} + args: --release --out dist --find-interpreter --manifest-path ./sdk/Cargo.toml --features openssl/vendored + sccache: 'true' + - name: Upload wheels + uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist + + macos: + needs: [tests] + runs-on: macos-latest + strategy: + matrix: + target: [x86_64, aarch64] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.target }} + args: --release --out dist --find-interpreter --manifest-path ./sdk/Cargo.toml --features openssl/vendored + sccache: 'true' + - name: Upload wheels + uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist + + sdist: + needs: [tests] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build sdist + uses: PyO3/maturin-action@v1 + with: + command: sdist + args: --out dist --manifest-path ./sdk/Cargo.toml + - name: Upload sdist + uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist + + release: + name: Release + runs-on: ubuntu-latest + if: "startsWith(github.ref, 'refs/tags/')" + needs: [linux, windows, macos, sdist] + steps: + - uses: actions/download-artifact@v3 + with: + name: wheels + - name: Publish to PyPI + uses: PyO3/maturin-action@v1 + env: + MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} + with: + command: upload + args: --non-interactive --skip-existing * diff --git a/.github/workflows/sdk.yml b/.github/workflows/sdk.yml new file mode 100644 index 0000000..f677dab --- /dev/null +++ b/.github/workflows/sdk.yml @@ -0,0 +1,48 @@ +name: SDK + +on: + workflow_call: + +jobs: + sdk_check: + name: Check + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./sdk + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - name: fmt + run: cargo fmt --check + - name: clippy + run: cargo clippy -- -D warnings + - uses: jordemort/action-pyright@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + workdir: ./sdk + fail_on_error: true + sdk_test: + name: Build & Test + needs: [sdk_check] + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./sdk + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Build + uses: PyO3/maturin-action@v1 + with: + args: --release --features openssl/vendored + working-directory: ./sdk + - name: Test + run: | + python -m venv .env + source .env/bin/activate + maturin develop --release --features openssl/vendored + python test.py diff --git a/sdk/Cargo.lock b/sdk/Cargo.lock index fb9e85b..f59ff0d 100644 --- a/sdk/Cargo.lock +++ b/sdk/Cargo.lock @@ -43,6 +43,7 @@ name = "aleo" version = "0.2.0" dependencies = [ "anyhow", + "openssl", "pyo3", "rand", "serde", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 693e329..b9b447f 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -6,10 +6,14 @@ description = "A Python sdk for zero-knowledge cryptography based on Aleo" edition = "2021" license = "GPL-3.0-or-later" +[lib] +crate-type = ["cdylib"] + [dependencies] anyhow = "1" +openssl = "0.10" +pyo3 = { version = "0.20.0", features = ["extension-module", "abi3-py37", "anyhow"] } rand = { version = "^0.8" } -pyo3 = { version = "0.20.0", features = ["extension-module", "anyhow"] } serde = "1" serde_json = "1" diff --git a/sdk/pyproject.toml b/sdk/pyproject.toml index 7c67305..1de9300 100644 --- a/sdk/pyproject.toml +++ b/sdk/pyproject.toml @@ -8,4 +8,8 @@ version = "0.2.0" description = "A Python SDK for zero-knowledge cryptography based on Aleo" repository = "https://github.com/AleoHQ/python-sdk/tree/master/sdk" license = "GPL-3.0-or-later" -authors = ["Konstantin Pandl", "Mike Turner", "Roman Proskuryakov"] \ No newline at end of file +authors = ["Konstantin Pandl", "Mike Turner", "Roman Proskuryakov"] + +[tool.pyright] +reportMissingModuleSource = false # don't report missing aleo.so for CI purposes +strict = ['./'] diff --git a/sdk/test.py b/sdk/test.py index a71be26..3f6a757 100644 --- a/sdk/test.py +++ b/sdk/test.py @@ -78,10 +78,9 @@ def test_coinbase(self): self.assertEqual(str(challenge), challenge_json) self.assertEqual(str(solution), solution_json) - # Skip it because it takes too much time to load the puzzle - # puzzle = aleo.CoinbasePuzzle.load() - # verifying_key = puzzle.verifying_key() - # assert solution.verify(verifying_key, challenge, 100) + puzzle = aleo.CoinbasePuzzle.load() + verifying_key = puzzle.verifying_key() + assert solution.verify(verifying_key, challenge, 100) def test_transfer(self): private_key = aleo.PrivateKey.from_string(