Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Andrej Orsula <[email protected]>
  • Loading branch information
AndrejOrsula committed Jan 20, 2024
0 parents commit 399262e
Show file tree
Hide file tree
Showing 32 changed files with 4,038 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .git_hooks/install.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -e

SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" &>/dev/null && pwd)"
REPOSITORY_DIR="$(dirname "${SCRIPT_DIR}")"

# Install pre-commit if not detected
if ! command -v pre-commit >/dev/null 2>&1; then
pip install --user pre-commit
fi

# Install local git hooks for this repository
cd "${REPOSITORY_DIR}"
pre-commit install --install-hooks --config "${REPOSITORY_DIR}/.pre-commit-config.yaml"
cd -
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "weekly"
32 changes: 32 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: pre-commit

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
cancel-in-progress: true

env:
PYTHON_VERSION: "3.10"
SKIP: cargo-fmt,cargo-update,cargo-clippy,cargo-check,cargo-test,cargo-test-doc,cargo-doc,cargo-miri-test,cargo-miri-run,cargo-deny-check

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

## Run pre-commit and try to apply fixes
- name: Run pre-commit
uses: pre-commit/[email protected]
- name: Apply fixes from pre-commit
uses: pre-commit-ci/[email protected]
if: always()
143 changes: 143 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: Rust

on:
push:
branches:
- main
pull_request:
release:
types: [published]
workflow_dispatch:

concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
cancel-in-progress: true

env:
PYTHON_VERSION: "3.10"
CARGO_TERM_COLOR: always
LIB_PACKAGE_NAME: pyo3_bindgen
CLI_PACKAGE_NAME: pyo3_bindgen_cli
ENGINE_PACKAGE_NAME: pyo3_bindgen_engine
MACROS_PROCEDURAL_PACKAGE_NAME: pyo3_bindgen_macros

jobs:
rustfmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

## cargo fmt
- name: cargo fmt
run: cargo fmt --all --check --verbose

cargo:
needs: rustfmt
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
toolchain:
- "1.70" # Minimal supported Rust version (MSRV)
- stable
- beta
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.event_name == 'push'}}
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
components: clippy
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

## cargo check
- name: cargo check
run: cargo check --workspace --all-targets --verbose
- name: cargo check --no-default-features
run: cargo check --workspace --all-targets --no-default-features --verbose
- name: cargo check --all-features
run: cargo check --workspace --all-targets --all-features --verbose

## cargo test
- name: cargo test
run: cargo test --workspace --all-targets --verbose
- name: cargo test --no-default-features
run: cargo test --workspace --all-targets --no-default-features --verbose
- name: cargo test --all-features
run: cargo test --workspace --all-targets --all-features --verbose

## cargo test --doc
- name: cargo test --doc
run: cargo test --workspace --doc --verbose
- name: cargo test --doc --no-default-features
run: cargo test --workspace --doc --no-default-features --verbose
- name: cargo test --doc --all-features
run: cargo test --workspace --doc --all-features --verbose

## [stable] cargo clippy
- name: stable | cargo clippy
if: ${{ matrix.toolchain == 'stable' }}
run: cargo clippy --workspace --all-targets --all-features --no-deps --verbose -- --deny warnings

## [stable] cargo doc
- name: stable | cargo doc --document-private-items
if: ${{ matrix.toolchain == 'stable' }}
run: cargo doc --workspace --all-features --no-deps --document-private-items --verbose

## [stable] Code coverage
- name: stable | Install cargo llvm-cov for code coverage
uses: taiki-e/install-action@cargo-llvm-cov
if: ${{ matrix.toolchain == 'stable' }}
## [stable] Generate coverage with cargo llvm-cov
- name: stable | Generate coverage
if: ${{ matrix.toolchain == 'stable' }}
run: cargo llvm-cov --workspace --all-features --lcov --output-path lcov.info
## [stable] Upload coverage to codecov.io
- name: stable | Upload coverage
if: ${{ matrix.toolchain == 'stable' }}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
fail_ci_if_error: true

deny:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v1
with:
command: check bans licenses sources

publish:
if: ${{ github.event_name == 'release' }}
needs:
- cargo
- deny
runs-on: ubuntu-latest
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable

## Publish to crates.io
- name: Publish crate (engine)
if: ${{ env.CARGO_REGISTRY_TOKEN != '' }}
run: cargo publish --no-verify --package ${{ env.ENGINE_PACKAGE_NAME }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Publish crate (procedural macros)
if: ${{ env.CARGO_REGISTRY_TOKEN != '' }}
run: cargo publish --no-verify --package ${{ env.MACROS_PROCEDURAL_PACKAGE_NAME }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Publish crate (public API)
if: ${{ env.CARGO_REGISTRY_TOKEN != '' }}
run: cargo publish --no-verify --package ${{ env.LIB_PACKAGE_NAME }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Publish crate (CLI tool)
if: ${{ env.CARGO_REGISTRY_TOKEN != '' }}
run: cargo publish --no-verify --package ${{ env.CLI_PACKAGE_NAME }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Rust & Cargo
target/
**/*.rs.bk
**/*.pdb
**/.cargo/config.toml
!.cargo/config.toml

## Python
**/__pycache__/
**/.pytest_cache/
**/*.pcd
**/*.py[cod]
**/*.pyc
**/*$py.class

## Shared Objects
**/*.so

## Virtual environments
.env/
.venv/

## VS Code
.vscode/*
!.vscode/extensions.json
!.vscode/launch.json
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/*.code-snippets
76 changes: 76 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

exclude: Cargo.lock
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
exclude: \.rs$
- id: check-symlinks
- id: check-toml
- id: check-vcs-permalinks
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: name-tests-test
- id: requirements-txt-fixer
- id: sort-simple-yaml
- id: trailing-whitespace

- repo: https://github.com/lovesegfault/beautysh
rev: v6.2.1
hooks:
- id: beautysh

- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
args: ["--ignore-words-list", "crate"]
exclude: Cargo.lock

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat

- repo: https://github.com/AndrejOrsula/pre-commit-cargo
rev: 0.3.0
hooks:
- id: cargo-fmt
- id: cargo-update
- id: cargo-clippy
args: ["--workspace", "--all-targets", "--", "--deny=warnings"]
- id: cargo-check
args: ["--workspace", "--all-targets"]
- id: cargo-test
args: ["--workspace", "--all-targets"]
- id: cargo-test-doc
args: ["--workspace"]
- id: cargo-doc
args: ["--workspace", "--no-deps", "--document-private-items"]
- id: cargo-deny-check
Loading

0 comments on commit 399262e

Please sign in to comment.