Skip to content

Release

Release #205

Workflow file for this run

name: Release
on:
create:
tags:
- 'v*'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build:
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
env:
CARGO_TERM_COLOR: always
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
build:
- linux
- macos-arm
- macos-intel
- windows
include:
- build: linux
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- build: macos-intel
os: macos-latest
target: x86_64-apple-darwin
- build: macos-arm
os: macos-latest
target: aarch64-apple-darwin
- build: windows
os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- name: Checkout sources
uses: actions/checkout@v4
- 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
- run: rustup target add ${{ matrix.target }}
- name: Build
run: cargo build --bin yr --profile release-lto --target ${{ matrix.target }}
env:
RUSTFLAGS: "-C target-feature=+crt-static"
- name: Build C library
if: matrix.build == 'windows'
run: |
cargo install cargo-c
cargo cbuild --profile release-lto --target ${{ matrix.target }}
env:
RUSTFLAGS: "-C target-feature=+crt-static"
- name: Build archive
shell: bash
run: |
set -ex
pkgname=yara-x-${{ github.ref_name }}-${{ matrix.target }}
if [ "${{ matrix.build }}" = "windows" ]; then
7z a $pkgname.zip ./target/${{ matrix.target }}/release-lto/yr.exe
7z a yara-x-capi-${{ github.ref_name }}-${{ matrix.target }}.zip \
./target/${{ matrix.target }}/release-lto/yara_x.h \
./target/${{ matrix.target }}/release-lto/yara_x_capi.def \
./target/${{ matrix.target }}/release-lto/yara_x_capi.lib \
./target/${{ matrix.target }}/release-lto/yara_x_capi.dll.lib \
./target/${{ matrix.target }}/release-lto/yara_x_capi.dll
else
tar czf $pkgname.gzip -C target/${{ matrix.target }}/release-lto yr
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: yr-${{ matrix.target }}
path: yara-x-*
build-py:
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version:
- cp39
- 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@v4
- 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@v5
with:
python-version: '3.12'
- run: rustup target add aarch64-apple-darwin x86_64-apple-darwin
if: matrix.build == 'macos'
- name: Install Python dependencies
run: pip install -U setuptools wheel twine cibuildwheel platformdirs
- name: Build sdist
if: matrix.build == 'linux' && matrix.python-version == 'cp39'
run: |
pip install maturin==1.7.4
maturin sdist --manifest-path py/Cargo.toml -o wheelhouse
- name: Build ${{ matrix.platform || matrix.os }} binaries
run: cibuildwheel --output-dir wheelhouse py
env:
CIBW_ENABLE: 'pypy'
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
MACOSX_DEPLOYMENT_TARGET: '10.12'
- 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:
needs: [ build ]
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: yr-*
- name: ls
shell: bash
run: ls
- name: Release
uses: softprops/action-gh-release@v2
with:
draft: true
files: yr-*/yara-x-*
publish-crate:
needs: [ publish ]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Publish crate
env:
# Don't re-generate the files `modules.rs` and `add_modules.rs`, use
# the ones in the repository. These files can't be regenerated because
# `cargo publish` checks that the repository doesn't change during
# the build. See: https://github.com/rust-lang/cargo/pull/5584
YRX_REGENERATE_MODULES_RS: "no"
run: |
cargo login ${{ secrets.CRATES_IO_API_TOKEN }}
cargo publish -p yara-x-macros
cargo publish -p yara-x-proto
cargo publish -p yara-x-proto-yaml
cargo publish -p yara-x-parser
cargo publish -p 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.12
with:
#repository-url: https://test.pypi.org/legacy/
skip-existing: true