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

Rust Spell Check Action #69

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
535 changes: 535 additions & 0 deletions rust-spell-check/Cargo.lock

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions rust-spell-check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "spell-checker"
version = "0.1.0"
edition = "2021"

[dependencies]
tree-sitter = "0.20.4"
tree-sitter-c = "0.20.1"
tree-sitter-cpp = "0.20.0"
tree-sitter-python = "0.19.1"
libaspell-sys = { path = "crates/libaspell-sys" }
cstr = "0.2.10"
clap = { version = "3.1.2", features = ["derive"] }

[workspace]
members = ["crates/libaspell-sys"]

[profile.release]
lto = "thin"
panic = "abort"
148 changes: 148 additions & 0 deletions rust-spell-check/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: 'rust-spell-check'
description: 'Rust CI spellings check'
inputs:
path:
description: 'Path to repository folder to check spellings in.'
required: false
default: ./
lexicon:
description: 'Path to lexicon file to check spellings with'
required: false
default: lexicon.txt
exclude-dirs:
description: "Comma separated list of directories to not spell check"
required: false
exclude-files:
description: "Comma separated list of files to not spell check"
required: false
include-extensions:
description: "Comma separated list of files to match to regex"
required: false


runs:
using: "composite"
steps:
- env:
bashPass: \033[32;1mPASSED -
bashInfo: \033[33;1mINFO -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m
stepName: Set-Up The Spell Checker
name: ${{ env.stepName }}
id: spell-checker-setup
shell: bash
run: |
# ${{ env.stepName }}
echo "::group::Install Dependencies"

# Install the Dependencies we need to run the spell-checker
sudo apt-get install util-linux -y
sudo apt-get install fd-find -y
sudo apt-get install aspell -y
sudo apt-get install spell -y
echo "::endgroup::"

# Add the current directory to PATH
export PATH="$GITHUB_ACTION_PATH:$PATH"


# Due to feedback from @archigup we will not be storing the binary
# So will build it from scratch each time. A future improvement is to use
# GitHub Caches or a public S3 bucket to store a pre-built one and download it.
# When this is done this logic below needs to be changed to perform the download
# And then try to use the spell-checker. Leaving this here for future reference
# When this work is being done.
# echo -e " ${{ env.bashInfo }} Try Using the pre-built spell checker ${{ env.bashEnd }}"
# Wrap the check to use if in a set +e so we don't error out if it fails
# Save the exit code to check later, as "set -e" will overwrite it
# set +e
# spell-checker
# exitCode=$?
# set -e

echo "::group::Compile Spell Checker"
exitCode=1

if ! [ $exitCode -eq 0 ]; then
#echo -e " ${{ env.bashFail }} Don't have the ability to use the current spell checker, building it ${{ env.bashEnd }}"

# If we can't run the current one, install the tools we need to build it
# Run one a time for error checking
sudo apt-get install libaspell-dev -y
sudo apt-get install build-essential -y
sudo apt install rustc -y

echo -e "${{ env.bashInfo }} cargo --version = $(cargo --version) ${{ env.bashEnd }}"
echo -e "${{ env.bashInfo }} rustc --version = $(rustc --version) ${{ env.bashEnd }}"

pushd "$GITHUB_ACTION_PATH"
cargo build --release
echo -e "find = $(find . -name 'spell-checker') "
# It's possible that we have one in the directory, but just can't suse it
# set +e so we don't error when overriding it
set +e
mv $(find . -name "spell-checker") .
set -e
popd
spell-checker --help
echo "::endgroup::Compile Spell Checker"

# Only make it to here if nothing above fails
echo -e "${{ env.bashPass }} Compiled the Spell Checker ${{ env.bashEnd }}"
fi
echo "::endgroup::"

# Only get to here if nothing above fails
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"

- env:
bashPass: \033[32;1mPASSED -
bashInfo: \033[33;1mINFO -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m
stepName: Spell Checker
name: ${{ env.stepName }}
id: run-spell-checker
working-directory: ${{ inputs.path }}
shell: bash
run: |
# ${{ env.stepName }}
#echo "::group::${{ env.stepName }}"
export PATH="$GITHUB_ACTION_PATH:$PATH"

# So here's the deal. At time of writing this spell checker can check
# every word in every folder in FreeRTOS/FreeRTOS in like 10 seconds.
# So I just let it do that. If this changes in the future, feel free to use
# The various exclude dir/file options
# files=$(getFiles --exclude-dirs="${{ inputs.exclude-dirs}}" --exclude-files="${{ inputs.exclude-files }}" --include-extensions="${{ inputs.include-extensions }}")

# The use of exec will return the exit code from the grep command
# Grep returns an exit code if a file isn't found
# So wrap the search in a set +/- e so github doesn't stop the run on first failure
set +e
files=$(fdfind -e c -e h --exec grep -liE "copyright (.*) [0-9]{4} amazon.com")
set -e

# If you're onboarding a repo or need better debugging, uncomment this instead
# Of the one-line check
# for file in ${files[@]}; do
# echo -e "${{ env.bashInfo }} Checking spelling of "$file" ${{ env.bashEnd }}"
# set +e
# spell-checker -c -w .cSpellWords.txt $file
# exitStatus=$?
# set -e
# done

set +e
spell-checker -c -w .cSpellWords.txt $files
exitStatus=$?
set -e

#echo "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
9 changes: 9 additions & 0 deletions rust-spell-check/crates/libaspell-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "libaspell-sys"
version = "0.1.0"
edition = "2021"

[dependencies]

[build-dependencies]
bindgen = "0.59.2"
18 changes: 18 additions & 0 deletions rust-spell-check/crates/libaspell-sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::env;
use std::path::PathBuf;

fn main() {
println!("cargo:rustc-link-lib=aspell");
println!("cargo:rerun-if-changed=wrapper.h");

let bindings = bindgen::Builder::default()
.header("wrapper.h").clang_arg("-I/opt/homebrew/Cellar/aspell/0.60.8/include/")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
5 changes: 5 additions & 0 deletions rust-spell-check/crates/libaspell-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
1 change: 1 addition & 0 deletions rust-spell-check/crates/libaspell-sys/wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <aspell.h>
2 changes: 2 additions & 0 deletions rust-spell-check/queries/c.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(comment) @comment
(string_literal) @string
2 changes: 2 additions & 0 deletions rust-spell-check/queries/python.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(comment) @comment
(string) @string
Loading