Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: update CI workflows #101

Merged
merged 45 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
af41f56
ci: try building Python extension.
plusvic Mar 26, 2024
a4a07df
ci: build on push
plusvic Mar 26, 2024
803f181
ci: comments.
plusvic Mar 26, 2024
f83a288
ci: fix
plusvic Mar 26, 2024
4403131
ci: fix
plusvic Mar 26, 2024
83ea59d
ci: fix
plusvic Mar 26, 2024
2894371
ci: fix
plusvic Mar 26, 2024
b7cff38
ci: fix
plusvic Mar 26, 2024
010a603
ci: fix
plusvic Mar 26, 2024
61be635
ci: fix
plusvic Mar 26, 2024
bc47a79
ci: fix
plusvic Mar 26, 2024
b59e0da
ci: fix
plusvic Mar 26, 2024
77211bf
ci: fix
plusvic Mar 26, 2024
3b35320
ci: try fixing wheels generation
plusvic Apr 5, 2024
502c8e9
ci: fix package name
plusvic Apr 5, 2024
53bb48c
ci: fix pytest command
plusvic Apr 5, 2024
2fb04b9
ci: add pytest requirement
plusvic Apr 5, 2024
84ce869
ci: use environment variable for getting vcpkg path
plusvic Apr 5, 2024
19b1a48
ci: fixes
plusvic Apr 5, 2024
503f30f
ci: try building openssl statically
plusvic Apr 5, 2024
672a863
ci: install openssl-static
plusvic Apr 5, 2024
e0b2778
ci: fix
plusvic Apr 5, 2024
b1b8986
ci: try fix
plusvic Apr 5, 2024
d7b6d72
ci: add AMD64 arch
plusvic Apr 5, 2024
8584eef
ci: don't build for win32
plusvic Apr 5, 2024
3889d3b
ci: debug issue
plusvic Apr 8, 2024
c600590
Merge branch 'main' into build-py
plusvic Apr 29, 2024
b3c049f
chore: Don't use `openssl-static` feature while building Python exten…
plusvic Apr 29, 2024
5272c79
ci: OpenSSL doesn't need to be installed in CI workflows anymore
plusvic Apr 29, 2024
58f9427
ci: remove debugging step.
plusvic Apr 29, 2024
4a691db
ci: test PyPI uploads
plusvic Apr 29, 2024
8d0eb7f
ci: fix issues
plusvic Apr 29, 2024
6c1ec14
ci: fix issues
plusvic Apr 29, 2024
c7c1348
ci: fix issues
plusvic Apr 29, 2024
4991b4b
ci: fix issues
plusvic Apr 29, 2024
476a38a
ci: build wheels for more Python versions
plusvic Apr 29, 2024
7e7166b
ci: fix issues
plusvic Apr 29, 2024
8ba96ee
ci: more platforms for Python wheels
plusvic Apr 29, 2024
3fe8e7e
ci: fix issues
plusvic Apr 29, 2024
e6b9cdf
ci: fix issues
plusvic Apr 29, 2024
7f04e4a
ci: temporarily disable version check
plusvic Apr 29, 2024
fb51ce2
ci: more metadata
plusvic Apr 29, 2024
ae3d906
chore: add simple README file for YARA-X Python.
plusvic Apr 29, 2024
252902e
ci: fix issues
plusvic Apr 29, 2024
ec19adb
ci: enable version check
plusvic Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .github/workflows/golang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,6 @@ jobs:
with:
toolchain: stable

# Install OpenSSL on Windows
- name: Install OpenSSL
if: runner.os == 'Windows'
id: vcpkg
uses: johnwason/vcpkg-action@v5
with:
pkgs: openssl
triplet: x64-windows-static
token: ${{ github.token }}

- name: Set OPENSSL_DIR environment variable
if: runner.os == 'Windows'
shell: bash
run: echo "OPENSSL_DIR=${{ github.workspace }}\\vcpkg\\installed\\x64-windows-static" >> $GITHUB_ENV

# Install OpenSSL on Linux
- name: Install dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev

- name: Install cargo-c
run: cargo install cargo-c

Expand Down
75 changes: 30 additions & 45 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: Python extension
on:
push:
paths:
- 'py/**'
- '.github/workflows/python.yaml'
- 'py/**'
- '.github/workflows/python.yaml'

permissions:
contents: read
Expand All @@ -14,50 +14,35 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, "3.10", "3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [ 3.8, 3.9, "3.10", "3.11" ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

# Windows
- name: Install OpenSSL
if: runner.os == 'Windows'
id: vcpkg
uses: johnwason/vcpkg-action@v5
with:
pkgs: openssl
triplet: x64-windows-static
token: ${{ github.token }}

- name: Set OPENSSL_DIR environment variable
if: runner.os == 'Windows'
shell: bash
run: echo "OPENSSL_DIR=${{ github.workspace }}\\vcpkg\\installed\\x64-windows-static" >> $GITHUB_ENV

- name: Test Python - Windows
if: runner.os == 'Windows'
run: |
pip install virtualenv
virtualenv venv; venv\Scripts\activate.ps1
pwd
python -m pip install --upgrade pip maturin
python -m pip install pytest
maturin develop --manifest-path py/Cargo.toml
pytest py

# Non-windows
- name: Test Python - Non-Windows
if: runner.os != 'Windows'
run: |
pip install virtualenv
virtualenv venv; source venv/bin/activate
python -m pip install --upgrade pip maturin
python -m pip install pytest
maturin develop --manifest-path py/Cargo.toml
pytest py
- name: Test Python - Windows
if: runner.os == 'Windows'
run: |
pip install virtualenv
virtualenv venv; venv\Scripts\activate.ps1
pwd
python -m pip install --upgrade pip maturin
python -m pip install pytest
maturin develop --manifest-path py/Cargo.toml
pytest py

# Non-windows
- name: Test Python - Non-Windows
if: runner.os != 'Windows'
run: |
pip install virtualenv
virtualenv venv; source venv/bin/activate
python -m pip install --upgrade pip maturin
python -m pip install pytest
maturin develop --manifest-path py/Cargo.toml
pytest py

153 changes: 132 additions & 21 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ on:
tags:
- 'v*'
jobs:
build:
build-cli:
env:
CARGO_TERM_COLOR: always
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
build:
- linux
Expand All @@ -17,30 +18,24 @@ jobs:
include:
- build: linux
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-gnu
vcpkg_openssl_triplet: x64-linux-release

- build: macos
os: macos-latest
rust: stable
target: x86_64-apple-darwin
vcpkg_openssl_triplet: x64-osx-release

- build: windows
os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
vcpkg_openssl_triplet: x64-windows-static

steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
toolchain: stable

- name: Check version number
shell: bash
Expand All @@ -51,19 +46,10 @@ jobs:
exit 1
fi

- name: Install dependencies
id: vcpkg
uses: johnwason/vcpkg-action@v6
with:
pkgs: openssl
triplet: ${{ matrix.vcpkg_openssl_triplet }}
token: ${{ github.token }}

- name: Build
run: cargo build --bin yr --profile release-lto --target ${{ matrix.target }}
env:
RUSTFLAGS: "-C target-feature=+crt-static"
OPENSSL_DIR: "${{ github.workspace }}/vcpkg/installed/${{ matrix.vcpkg_openssl_triplet }}"

- name: Build archive
shell: bash
Expand All @@ -82,8 +68,111 @@ jobs:
name: yr-${{ matrix.target }}
path: yara-x-*

publish:
needs: [ build ]
build-py:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version:
- cp39
- cp310
- cp311
- cp312
- pp38
- pp39
- pp310
build:
- linux
- macos
- windows
include:
- build: linux
os: ubuntu-latest

- build: macos
os: macos-latest
arch: 'arm64 x86_64'

- build: windows
os: windows-latest
arch: 'x86 AMD64'

steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable

- name: Check version number
shell: bash
run: |
set -ex
version=`cargo pkgid --manifest-path lib/Cargo.toml | cut -d "@" -f2`
if [ "${{ github.ref_name }}" != "v$version" ]; then
exit 1
fi

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- run: rustup target add aarch64-apple-darwin x86_64-apple-darwin
if: matrix.build == 'macos'

#- run: rustup toolchain install stable-i686-pc-windows-msvc
# if: matrix.build == 'windows'

#- run: rustup target add i686-pc-windows-msvc
# if: matrix.build == 'windows'

- name: Install Python dependencies
run: pip install -U setuptools wheel twine cibuildwheel platformdirs

- name: Build sdist
if: matrix.build == 'linux' && matrix.python-version == 'cp312'
run: |
pip install maturin build
python -m build --sdist -o wheelhouse py

- name: Build ${{ matrix.platform || matrix.os }} binaries
run: cibuildwheel --output-dir wheelhouse py
env:
CIBW_BUILD: '${{ matrix.python-version }}-*'
# wasmtime doesn't support i686
CIBW_SKIP: '*_i686 *-musllinux* *-win32'
# we build for "arch" if it exists, else 'auto'
CIBW_ARCHS: ${{ matrix.arch || 'auto' }}

CIBW_BEFORE_BUILD_LINUX: >
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=minimal -y &&
rustup show

CIBW_ENVIRONMENT_LINUX: 'PATH="$HOME/.cargo/bin:$PATH" '
CIBW_ENVIRONMENT_WINDOWS: 'PATH="$UserProfile\.cargo\bin;$PATH"'

CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: 'pytest {project}/py'
CIBW_TEST_SKIP: '*-macosx_arm64 *-macosx_universal2:arm64'
CIBW_BUILD_VERBOSITY: 1

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: pypi-${{ matrix.build }}-${{ matrix.python-version }}
path: ./wheelhouse/*.whl

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: pypi-source-${{ strategy.job-index }}
path: ./wheelhouse/*.tar.gz

publish-cli:
needs: [ build-cli ]
runs-on: ubuntu-latest

steps:
Expand All @@ -100,4 +189,26 @@ jobs:
uses: softprops/action-gh-release@v2
with:
draft: true
files: yr-*/yara-x-*
files: yr-*/yara-x-*

publish-py:
needs: [ build-py ]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/yara-x
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: pypi-*
merge-multiple: true
path: dist

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
#repository-url: https://test.pypi.org/legacy/
skip-existing: true
16 changes: 1 addition & 15 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,7 @@ jobs:
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev libmagic-dev

- name: Install dependencies
id: vcpkg
if: runner.os == 'Windows'
uses: johnwason/vcpkg-action@v5
with:
pkgs: openssl
triplet: x64-windows-release
token: ${{ github.token }}

- name: Set OPENSSL_DIR environment variable
if: runner.os == 'Windows'
shell: bash
run: echo "OPENSSL_DIR=${{ github.workspace }}\\vcpkg\\installed\\x64-windows-release" >> $GITHUB_ENV
sudo apt-get install -y libmagic-dev

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
Expand Down
21 changes: 21 additions & 0 deletions py/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
This Python package allows using [YARA-X](https://virustotal.github.com/yara-x)
from your Python programs.

```python
import yara_x

rules = yara_x.compile('''
rule test {
strings:
$a = "foobar"
condition:
$a
}''')

results = rules.scan(b"foobar")

assert results.matching_rules[0].identifier == "test"
assert results.matching_rules[0].patterns[0].identifier == "$a"
assert results.matching_rules[0].patterns[0].matches[0].offset == 0
assert results.matching_rules[0].patterns[0].matches[0].length == 6
```
10 changes: 8 additions & 2 deletions py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ requires = ["maturin>=1.0,<2.0"]
build-backend = "maturin"

[project]
name = "yara-x-py"
name = "yara-x"
description = "Python bindings for YARA-X"
requires-python = ">=3.8"
readme = "README.md"
keywords = ["pattern-matching", "cybersecurity", "forensics", "malware", "yara"]
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"License :: OSI Approved :: MIT License",
"License :: OSI Approved :: BSD License",
]

[project.urls]
homepage = "https://virustotal.github.io/yara-x"
repository = "https://github.com/VirusTotal/yara-x.git"

[tool.maturin]
features = ["pyo3/extension-module"]
Loading