Skip to content

Commit 1a4f05c

Browse files
committed
Added ability to use a file list
1 parent 69eb1fd commit 1a4f05c

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ GitHub action that runs `csvlint`.
44

55
The project is heavily based on salt-lint-action, which was created by Roald Nefs and the action from blackstar257 at [docker-csvlint](https://github.com/blackstar257/docker-csvlint).
66

7-
This action adds few additional parameters like file paths and patterns to `docker-csvlint`. Also added is a configurable exit status.
7+
This action adds few additional parameters like file paths and patterns to `docker-csvlint`.
8+
9+
Also added is the ability to use an external file list and a configurable exit status.
810

911

1012

@@ -25,14 +27,17 @@ jobs:
2527
- name: Run csv-lint
2628
uses: kcheriyath/csvlinter@main
2729
with:
30+
file_list: "space delmited list of files including path"
2831
find_pattern: "*.csv"
2932
find_path: "./data"
3033
fail_on_error: "false"
3134
extra_params: "--lazyquotes"
3235
```
3336

3437

35-
find_path: (optional) when defined, find command is used to search for csv files in the path, relative to project root. defaults to . (`dot`)
38+
file_list: "(optional) if set, linter will use this file list only and find* parameters are ignored. Use as a static list or with jitterbit/get-changed-files to check only new files."
39+
40+
find_path: (optional) if set, find command is used to search for csv files in the path, relative to project root. defaults to . (`dot`)
3641

3742
find_pattern: (optional) defaults to *.csv.
3843

@@ -53,10 +58,11 @@ NOTE: The default settings validate that a CSV conforms to [RFC 4180](https://to
5358

5459
### Todo
5560

56-
- [ ] Ability to use a file list for only new/changed files.
61+
5762

5863
### Done ✓
5964

6065
- [x] Configurable exit status with fail_on_error.
6166
- [x] File path
6267
- [x] File pattern
68+
- [x] Ability to use a file list for only new/changed files.

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: "csvlinter"
22
description: "CSV Linter action based on csvlint"
33
author: "K Cheriyath"
44
inputs:
5+
file_list: # id of input
6+
description: "(optional) when defined, linter will use this file list only and find* parameters are ignored. Use as a static list or with jitterbit/get-changed-files to check only new files."
7+
required: false
58
find_path: # id of input
69
description: "(optional) when defined, find command is used to search for csv files in the path, relative to project root. defaults to ."
710
required: false

entrypoint.sh

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/bin/bash
22

3-
set -u
4-
53
# Set variables
64
ACTIONSTATUS=0
75
EXITSTATUS=0
@@ -17,20 +15,27 @@ INPUT_FAIL_ON_ERROR="${INPUT_FAIL_ON_ERROR:-true}"
1715

1816
cd "${GITHUB_WORKSPACE}"
1917

20-
if [ ! -d "${INPUT_FIND_PATH}" ]; then
21-
2>&1 echo "==> Can't find ${INPUT_FIND_PATH}. Please ensure INPUT_FIND_PATH is a directory relative to the root of your project."
22-
exit 1
23-
fi
24-
25-
if [[ -n "${INPUT_FIND_PATTERN}" ]]; then
26-
2>&1 echo "==> Pattern ${INPUT_FIND_PATTERN} specified. Finding files matching this pattern."
18+
if [ -n "${INPUT_FILE_LIST}" ]; then
2719

28-
readarray -d '' FILELIST < <(find "${INPUT_FIND_PATH}" -name "${INPUT_FIND_PATTERN}" -print0)
20+
2>&1 echo "==> File List ${INPUT_FILE_LIST} specified. Linting files matching this pattern."
21+
IFS=', ' read -r -a FILELIST <<< "${INPUT_FILE_LIST}"
2922
else
30-
2>&1 echo "INPUT_FIND_PATTERN is not set. Using '*.csv'"
31-
readarray -d '' FILELIST < <(find "${INPUT_FIND_PATH}" -name "*.csv" -print0)
23+
24+
if [ ! -d "${INPUT_FIND_PATH}" ]; then
25+
2>&1 echo "==> Can't find ${INPUT_FIND_PATH}. Please ensure INPUT_FIND_PATH is a directory relative to the root of your project."
26+
exit 1
27+
fi
28+
if [[ -n "${INPUT_FIND_PATTERN}" ]]; then
29+
2>&1 echo "==> Pattern ${INPUT_FIND_PATTERN} specified. Finding files matching this pattern."
30+
31+
readarray -d '' FILELIST < <(find "${INPUT_FIND_PATH}" -name "${INPUT_FIND_PATTERN}" -print0)
32+
else
33+
2>&1 echo "INPUT_FIND_PATTERN is not set. Using '*.csv'"
34+
readarray -d '' FILELIST < <(find "${INPUT_FIND_PATH}" -name "*.csv" -print0)
35+
fi
3236
fi
3337

38+
3439
FILECOUNT=${#FILELIST[@]}
3540

3641

0 commit comments

Comments
 (0)