Skip to content

Commit

Permalink
Fix to address issue 84; support for spaces in file paths requiring q…
Browse files Browse the repository at this point in the history
…uoting (#90)

* This is first shot at a fix of the issue reported
in #86. I believe file paths without space has been
working as a conincidence since the splitting has
not been working at all, but treating the list of
file names as a single string also worked.

Now it should work for both file paths without spaces
and file paths with spaces, which however require
uniform quoting using either ' (single quotes) or
" (double quotes)

* amend!

This is first shot at a fix of the issue reported
in #84. I believe file paths without space has been
working as a conincidence since the splitting has
not been working at all, but treating the list of
file names as a single string also worked.

Now it should work for both file paths without spaces
and file paths with spaces, which however require
uniform quoting using either ' (single quotes) or
" (double quotes)

* Bumped version in examples for the upcoming bug fix release

* Updated the documentation to support the bug fix addressing issue #84

* Minor correction to Dockerfile, was executing as sh, but was using Bash script
  • Loading branch information
jonasbn committed May 5, 2022
1 parent 0b93548 commit 0d2f3ab
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ RUN apt-get update && apt-get install -y \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /tmp
ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
54 changes: 50 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
steps:
# The checkout step
- uses: actions/checkout@master
- uses: rojopolis/spellcheck-github-actions@0.23.0
- uses: rojopolis/spellcheck-github-actions@0.23.1
name: Spellcheck
```

Expand All @@ -60,6 +60,52 @@ By default, this action will use the `sources:` list under each task in your con

When this option is used, you must also specify the `task_name` to override the `sources:` list for.

Do note that file paths containing spaces need to be quoted using either `'` (single quotes) or `"` (double quotes). The quoting has to be uniform and the two quoting styles can not be intermixed.

### Examples

Parts are lifted from issue [#84](https://github.com/rojopolis/spellcheck-github-actions/issues/84)

#### No spaces, quotes not required

```yaml
source_files: README.md CHANGELOG.md notes/Notes.md
```

#### No spaces, quotes not required, double quotes used for complete parameter

```yaml
source_files: "README.md CHANGELOG.md notes/Notes.md"
```

This might actually work, but it is not recommended and might it might break, instead using proper quoting.

#### No spaces, quotes not required, double quotes used for single parameters

```yaml
source_files: "README.md" "CHANGELOG.md" "notes/Notes.md"
```

This would also work using single quotes

#### Spaces, quotes required, single quotes used

```yaml
source_files: 'Managed Services/Security Monitor/README.md' 'Terraform/Development Guide/README.md'
```

#### Spaces, quotes required, double quotes used

```yaml
source_files: "Managed Services/Security Monitor/README.md" "Terraform/Development Guide/README.md"
```

#### Spaces, quotes required, intermixed quotes, will not work

```yaml
source_files: README.md CHANGELOG.md notes/Notes.md
```

## Specify A Specific Task To Run

By default, all tasks in your config file will be run. By setting `task_name` you can override this and run only the task you require.
Expand All @@ -79,7 +125,7 @@ jobs:
steps:
# The checkout step
- uses: actions/checkout@master
- uses: rojopolis/spellcheck-github-actions@0.23.0
- uses: rojopolis/spellcheck-github-actions@0.23.1
name: Spellcheck
with:
source_files: README.md CHANGELOG.md notes/Notes.md
Expand Down Expand Up @@ -152,7 +198,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: rojopolis/spellcheck-github-actions@0.23.0
- uses: rojopolis/spellcheck-github-actions@0.23.1
name: Spellcheck
with:
config_path: config/.spellcheck.yml # put path to configuration file here
Expand Down Expand Up @@ -414,7 +460,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: rojopolis/spellcheck-github-actions@0.23.0
- uses: rojopolis/spellcheck-github-actions@0.23.1
name: Spellcheck
```

Expand Down
58 changes: 53 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh -l
#!/bin/bash

SPELLCHECK_CONFIG_FILE=''

Expand All @@ -19,17 +19,65 @@ fi
echo ""
echo "Using pyspelling on configuration outlined in >$SPELLCHECK_CONFIG_FILE<"

SINGLE="'"
DOUBLE='"'
SPLIT=false

if [ -n "$INPUT_SOURCE_FILES" ]; then

if grep -q $SINGLE <<< "$INPUT_SOURCE_FILES"; then
OIFS=$IFS
IFS=$SINGLE
SPLIT=true
echo "Detected separator: >$SINGLE< (single quote)"
fi

if grep -q $DOUBLE <<< "$INPUT_SOURCE_FILES"; then
OIFS=$IFS
IFS=$DOUBLE
SPLIT=true
echo "Detected separator: >$DOUBLE< (double quote)"
fi

if [ -z "$INPUT_TASK_NAME" ]; then
echo "task_name must be specified to use source_files option"
exit 1
else
echo "Running task >$INPUT_TASK_NAME<"
fi
for FILE in $INPUT_SOURCE_FILES; do
SOURCES_LIST="$SOURCES_LIST --source $FILE"
echo "Checking file >$FILE<"
done

if [ "$SPLIT" = true ]; then
echo "IFS = >$IFS<"
read -a arr <<< "$INPUT_SOURCE_FILES"

for FILE in "${arr[@]}"; do

# Skip null items
if [ -z "$FILE" ]; then
continue
fi

if [ "$FILE" = ' ' ]; then
continue
fi

SOURCES_LIST="$SOURCES_LIST --source $FILE"
echo "Checking quoted file >$FILE<"

done

IFS=$OIFS
unset OIFS

else
read -a arr <<< "$INPUT_SOURCE_FILES"

for FILE in "${arr[@]}"; do
SOURCES_LIST="$SOURCES_LIST --source $FILE"
echo "Checking file >$FILE<"
done
fi

else
echo "Checking files matching specified outlined in >$SPELLCHECK_CONFIG_FILE<"
fi
Expand Down

0 comments on commit 0d2f3ab

Please sign in to comment.