Merge pull request #276 from epage/action

fix(action): Be stricter/cleaner with entrypoint
This commit is contained in:
Ed Page 2021-06-05 14:34:50 -05:00 committed by GitHub
commit 78787b1768
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 54 deletions

View file

@ -10,16 +10,16 @@ jobs:
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Prepare file with mistakes. - name: Prepare file with mistakes.
run: echo "The quick brown foxx jumped over the slepy dog." > file.txt run: echo "Finallizes" > file.txt
- name: Test force pass with mistakes - name: Test force pass with mistakes
continue-on-error: true continue-on-error: true
uses: ./ uses: ./
with: with:
files: ./file.txt files: ./file.txt
- name: Prepare file with no mistakes. - name: Prepare file with no mistakes.
run: echo "The quick brown fox jumped over the sleepy dog." > file.txt run: echo "Finalizes" > file.txt
- name: Test force pass with no mistakes - name: Test pass with no mistakes
uses: ./ uses: ./
with: with:
files: ./file.txt files: ./file.txt

View file

@ -1,59 +1,34 @@
#!/bin/bash #!/bin/bash
set -e set -eu
printf "Found files in workspace:\n" log() {
ls echo -e "$1" >&2
}
printf "\nLooking for typos installed...\n" CMD_NAME="typos"
which typos TARGET=${INPUT_FILES:-"."}
COMMAND="typos" if [[ -z $(ls ${TARGET} 2>/dev/null) ]]; then
log "ERROR: Input files (${TARGET}) not found"
# Show the _typos.toml file exit 1
if [ -f "_typos.toml" ]; then
echo "_typos.toml:"
cat _typos.toml
echo
fi fi
if [[ -z $(which ${CMD_NAME} 2>/dev/null) ]]; then
log "ERROR: 'typos' not found"
exit 1
fi
COMMAND="${CMD_NAME} ${TARGET}"
# Ignore implicit configuration files # Ignore implicit configuration files
if [ "${INPUT_ISOLATED}" == "true" ]; then if [ "${INPUT_ISOLATED:-false}" == "true" ]; then
COMMAND="${COMMAND} --isolated" COMMAND+=" --isolated"
fi fi
# Use a custom configuration file # Use a custom configuration file
if [ ! -z "${INPUT_CONFIG}" ]; then if [[ -n "${INPUT_CONFIG:-}" ]]; then
COMMAND+=" --config ${INPUT_CONFIG}"
# It must exist
if [ ! -f "${INPUT_CONFIG}" ]; then
printf "${INPUT_CONFIG} does not exist.\n"
exit 1;
else
# Show the custom config to the user
printf "Custom config:\n"
cat "${INPUT_CONFIG}"
echo
fi
COMMAND="${COMMAND} --config ${INPUT_CONFIG}"
fi fi
# Files are technically optional log "$ ${COMMAND}"
if [ ! -z "${INPUT_FILES}" ]; then
COMMAND="${COMMAND} ${INPUT_FILES}"
fi
echo "Command: "
echo "${COMMAND}"
echo
${COMMAND} ${COMMAND}
retval=$?
if [[ "${retval}" -eq 0 ]]; then
printf "No spelling mistakes found! 🎉️\n"
else
printf "Spelling mistakes found! 😱️\n"
exit $retval;
fi

View file

@ -172,13 +172,14 @@ fn run_checks(
let mut errors_found = false; let mut errors_found = false;
for path in args.path.iter() { for path in args.path.iter() {
let cwd = if path == std::path::Path::new("-") { let cwd = if path == std::path::Path::new("-") {
global_cwd.as_path() global_cwd.clone()
} else if path.is_file() { } else if path.is_file() {
path.parent().unwrap() let mut cwd = path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
cwd.pop();
cwd
} else { } else {
path.as_path() path.clone()
}; };
let cwd = cwd.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
engine engine
.init_dir(&cwd) .init_dir(&cwd)

View file

@ -22,3 +22,10 @@ fn test_stdin_correct() {
.write_stdin("Apropriate world"); .write_stdin("Apropriate world");
cmd.assert().success().stdout("Appropriate world"); cmd.assert().success().stdout("Appropriate world");
} }
#[test]
fn test_file_failure() {
let mut cmd = Command::cargo_bin("typos").unwrap();
cmd.arg("README.md");
cmd.assert().code(2);
}