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

Fix to address issue 84; support for spaces in file paths requiring quoting #90

Merged
merged 7 commits into from
May 5, 2022
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
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