-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add back in the rust spell check. Don't leave the binary.
- Loading branch information
Showing
11 changed files
with
1,080 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
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::" | ||
# Check if we can use the current spell checker | ||
# This is not added to the path by default. | ||
# I honestly do not know why | ||
export PATH="$GITHUB_ACTION_PATH:$PATH" | ||
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 | ||
if ! [ $exitCode -eq 0 ]; then | ||
echo "::endgroup::" | ||
echo -e " ${{ env.bashFail }} Don't have the ability to use the current spell checker, building it ${{ env.bashEnd }}" | ||
echo "::group::Compile Spell Checker" | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include <aspell.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/bin/bash | ||
bashPass="\033[32;1mPASSED -" | ||
bashInfo="\033[33;1mINFO -" | ||
bashFail="\033[31;1mFAILED -" | ||
bashEnd="\033[0m" | ||
|
||
output=$(getopt -V) | ||
if [[ *"getopt"* == "$output" ]] && [ $# != 0 ]; then | ||
echo -e "$bashInfo This script cannot parse options from Mac command line's default 'getopt' $bashEnd" | ||
echo -e "$bashInfo Run \"brew install gnu-getopt\" and then add it to your path using $bashEnd" | ||
echo -e "$bashInfo export PATH=\"/opt/homebrew/opt/gnu-getopt/bin:\$PATH\" $bashEnd" | ||
echo -e "$bashInfo At which point you can then use this script with options $bashEnd" | ||
exit 1; | ||
fi | ||
# Check number of arguments | ||
files="" | ||
file="" | ||
excludeDirs="" | ||
excludeFiles="" | ||
includeExtensions="" | ||
if [ $# != 0 ]; then | ||
VALID_ARGS=$(getopt -o h,ed:,ef:,if: --long help,exclude-dirs:,exclude-files:,include-extensions: -- "$@") | ||
eval set -- "$VALID_ARGS" | ||
while [ : ]; do | ||
case "$1" in | ||
ed | --exclude-dirs ) | ||
# $2 Holds the argument passed after --exclude-files or --ed | ||
# Use sed to replace the commas with the exclude flag | ||
if ! [ -z "$2" ]; then | ||
excludeDirs="-E $(echo "$2" | sed -r 's/,/ -E /g' )" | ||
fi | ||
shift 2 | ||
;; | ||
|
||
ef | --exclude-files ) | ||
# $2 Holds the argument passed after --exclude-files or --ed | ||
# Use sed to replace the commas with the exclude flag | ||
if ! [ -z "$2" ]; then | ||
excludeFiles="-E $( echo "$2" | sed -r 's/,/ -E /g' )" | ||
fi | ||
shift 2 | ||
;; | ||
|
||
if | --include-extensions ) | ||
# $2 Holds the argument passed after --exclude-files or --ed | ||
# Use sed to replace the commas with the exclude flag | ||
if ! [ -z "$2" ]; then | ||
includeExtensions="-e $( echo "$2" | sed -r 's/,/ -E /g' )" | ||
fi | ||
shift 2 | ||
;; | ||
|
||
h | --help ) | ||
echo -e "$bashInfo Find all .c and .h files with the Amazon copyright in them $bashEnd" | ||
echo -e "$bashInfo It exports this to a bash array variable called \"files\" $bashEnd" | ||
echo -e "$bashInfo This script can take in two optional arguments $bashEnd" | ||
echo -e "$bashInfo --exclude-files: A comma seperated list of files to exclude $bashEnd" | ||
echo -e "$bashInfo --exclude-dir: A comma seperated list of directories to exclude $bashEnd" | ||
echo -e "$bashInfo --include-extensions: Any additional exstensions to search for $bashEnd" | ||
exit 0 | ||
;; | ||
-- ) | ||
shift | ||
break | ||
;; | ||
esac | ||
done | ||
fi | ||
|
||
# We know we just want the .c and .h files | ||
# It's just way easier to do this then it is to write | ||
# A complicated thing to handle parsing the arguments | ||
#echo "Hello" | ||
#echo "fdfind -e c -e h "$excludeDirs" "$excludeFiles" "$includeExtensions" --exec grep -lriE \"copyright (.*) [0-9]{4} amazon.com\" " | ||
files=$(fdfind -e c -e h $excludeDirs $excludeFiles $includeExtensions --exec grep -liE "copyright (.*) [0-9]{4} amazon.com" ) | ||
|
||
finalFiles=("") | ||
for file in ${files[@]}; do | ||
if ! [ -z "$file" ]; then | ||
echo "$file" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(comment) @comment | ||
(string_literal) @string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(comment) @comment | ||
(string) @string |
Oops, something went wrong.