Skip to content

Commit

Permalink
Configure pre-commit hooks and GitHub Actions (#95)
Browse files Browse the repository at this point in the history
* Replace the linter/formatter black and isort with Ruff. Add mypy.

* Configure clang-format.

* Configurate markdown linter

* Create pre-commit configurations.

* Trigger pre-commit checks from GitHub Actions

* Refactor GitHub Actions configurations.

* Configure depndabot for updating GitHub Actions settings.

* Describe development steps and details about GitHub Adtions in CONTRIBUTING.md

* Update contributing guidelines in README.md

* Fix md link

* Rephrase section names
  • Loading branch information
azriel1rf authored May 5, 2024
1 parent 4bad2e6 commit 9b05125
Show file tree
Hide file tree
Showing 10 changed files with 541 additions and 87 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'weekly'
134 changes: 88 additions & 46 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: C++ Standard Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Run before script
timeout-minutes: 10
run: |
Expand All @@ -34,46 +34,47 @@ jobs:
./unit_tests_evaluator5_standalone
./unit_tests_evaluator6_standalone
./unit_tests_evaluator7_standalone
# - name: Setup Zig
# uses: goto-bus-stop/setup-zig@v1.3.0
# with:
# version: master
# - name: zig build -Drelease-fast
# run: |
# cd cpp
# zig build -Drelease-fast
# - name: zig build -Ddynamic -Drelease-fast
# run: |
# cd cpp
# zig build -Ddynamic -Drelease-fast
# - name: zig build -Dtarget=x86_64-windows -Drelease-fast
# run: |
# cd cpp
# zig build -Dtarget=x86_64-windows -Drelease-fast
# - name: zig build -Domaha -Drelease-fast
# run: |
# cd cpp
# zig build -Domaha -Drelease-fast
# - name: zig build -Domaha -Ddynamic -Drelease-fast
# run: |
# cd cpp
# zig build -Domaha -Ddynamic -Drelease-fast
# - name: zig build -Domaha -Ddynamic -Dtarget=x86_64-windows -Drelease-fast
# run: |
# cd cpp
# zig build -Domaha -Ddynamic -Dtarget=x86_64-windows -Drelease-fast
# - name: zig build and run examples
# run: |
# cd cpp
# zig build examples
# zig-out/bin/c_example
# zig-out/bin/cpp_example
# zig-out/bin/omaha_example
# - name: Setup Zig
# uses: goto-bus-stop/setup-zig@v1.3.0
# with:
# version: master
# - name: zig build -Drelease-fast
# run: |
# cd cpp
# zig build -Drelease-fast
# - name: zig build -Ddynamic -Drelease-fast
# run: |
# cd cpp
# zig build -Ddynamic -Drelease-fast
# - name: zig build -Dtarget=x86_64-windows -Drelease-fast
# run: |
# cd cpp
# zig build -Dtarget=x86_64-windows -Drelease-fast
# - name: zig build -Domaha -Drelease-fast
# run: |
# cd cpp
# zig build -Domaha -Drelease-fast
# - name: zig build -Domaha -Ddynamic -Drelease-fast
# run: |
# cd cpp
# zig build -Domaha -Ddynamic -Drelease-fast
# - name: zig build -Domaha -Ddynamic -Dtarget=x86_64-windows -Drelease-fast
# run: |
# cd cpp
# zig build -Domaha -Ddynamic -Dtarget=x86_64-windows -Drelease-fast
# - name: zig build and run examples
# run: |
# cd cpp
# zig build examples
# zig-out/bin/c_example
# zig-out/bin/cpp_example
# zig-out/bin/omaha_example

cpp_benchmark:
name: C++ Benchmark
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Run before script
timeout-minutes: 10
run: |
Expand All @@ -84,23 +85,64 @@ jobs:
run: |
cd cpp/build
./benchmark_phevaluator
python-test:
name: Python test
name: Python - Run unit tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.x
uses: actions/setup-python@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install package
- name: Run tests
run: |
cd python
pip install .
- name: Run script
python -m unittest discover -v
python-type-checking:
name: Python - Type checking with mypy
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.8"
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Run mypy
run: |
cd python
python -m unittest discover -v
pip install mypy
mypy .
python-check-install:
name: Python - Check package installation (without releasing)
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install package
run: |
cd python
pip install .
21 changes: 21 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: pre-commit

on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.8"
- uses: pre-commit/action@v3.0.1
10 changes: 10 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Default state for all rules
default: true

# MD033 - Inline HTML
MD033:
# We allow the <a> tag to create named anchors within the document.
# Example:
# [Go to section](#section)
# <a name="section"></a>
allowed_elements: [a]
114 changes: 114 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
repos:
# Display the arguments passed to the hook
- repo: meta
hooks:
- id: identity

# For all files
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-merge-conflict
fail_fast: true
- id: no-commit-to-branch
args: [--branch=master, --branch=develop]
fail_fast: true
- id: forbid-submodules
fail_fast: true
- id: detect-private-key
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: trailing-whitespace
- id: end-of-file-fixer
# Formatting for TOML
- id: check-toml
# Formatting for YAML
- id: check-yaml

# For all files
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
hooks:
- id: remove-crlf
- id: remove-tabs

# Formatting for Python configuration files
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
hooks:
- id: setup-cfg-fmt

# Linting and formatting for C++
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
args: [-i]
exclude: |
(?x)^(
cpp/src/hashtable.*|
cpp/src/tables.*
)$
# - id: clang-tidy
# - id: oclint
# - id: cppcheck
# - id: include-what-you-use
# args: [-Xiwyu, --no_comments]

# Formatting markdown files
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.40.0
hooks:
- id: markdownlint
args: [--fix]

- repo: local
hooks:
# Linting for Python
- id: ruff-check
name: Python - Linting with Ruff
entry: bash -c 'pip install ruff && cd python && ruff check'
language: system
types_or: [python]
pass_filenames: false

# Formatting for Python
- id: ruff-format
name: Python - Formatting with Ruff
entry: bash -c 'pip install ruff && cd python && ruff format'
language: system
types_or: [python]
pass_filenames: false

# Type checking for Python
- id: mypy
name: Python - Type checking with mypy
entry: bash -c 'pip install mypy && cd python && mypy .'
language: system
types_or: [python]
pass_filenames: false
stages:
- pre-commit
- pre-merge-commit
- pre-rebase
- manual

# Unit testing for Python
- id: unittest
name: Python - Run unit tests
entry: python -m unittest discover
language: system
pass_filenames: false
stages:
- pre-commit
- pre-merge-commit
- pre-rebase
- manual

# Display the differences between the original and formatted code
- id: git-diff
name: git diff
entry: git diff --color --exit-code
language: system
pass_filenames: false
always_run: true
Loading

0 comments on commit 9b05125

Please sign in to comment.