Skip to content

Commit 413557a

Browse files
authored
Make GitHub Action friendlier for pull requests (#6) #patch
* accomodate pull request usecases #patch * accomodate for rename use case
1 parent 5b98341 commit 413557a

3 files changed

Lines changed: 58 additions & 6 deletions

File tree

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ This action uses an Open Knowledge Framework schema to validate your manifest su
1111

1212
*Optional* How many cores to use. Default `"4"`.
1313

14+
#### `file-restrictions`
15+
16+
*Optional* For a given path or directory, only process these (space separated) files. Useful for pull requests. Default `""`.
17+
1418
#### `ok`
1519

1620
*Optional* Which Open Knowledge Framework schema to use for validation. Default [`"okh"`](./okv/schemas/okh.yaml).
@@ -33,11 +37,11 @@ This action uses an Open Knowledge Framework schema to validate your manifest su
3337
### Example usage
3438

3539
```yaml
36-
uses: helpfulengineering/ok-validate@v0.0.1
40+
uses: helpfulengineering/ok-validate@v0.0.4
3741
```
3842
3943
```yaml
40-
uses: helpfulengineering/ok-validate@v0.0.1
44+
uses: helpfulengineering/ok-validate@v0.0.4
4145
with:
4246
path: './some/path/to/file.yaml'
4347
```

action.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ inputs:
99
description: 'How many cores to use'
1010
required: false
1111
default: '4'
12+
file-restrictions:
13+
description: 'For a given path or directory, only process these (space separated) files. Useful for pull requests.'
14+
required: false
15+
default: ''
1216
ok:
1317
description: 'Which preset Open Knowledge Framework schema to use for validation. Should be one of ("okh")'
1418
required: false
@@ -18,7 +22,7 @@ inputs:
1822
required: false
1923
default: 'pyyaml'
2024
path:
21-
description: 'The path to your mainfest or manifests relative to your workspace'
25+
description: 'The path to your manifest(s) relative to your workspace'
2226
required: true
2327
default: './'
2428
schema:

entrypoint.sh

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,62 @@
11
#!/bin/bash
2-
set -ex
2+
set -e
33

4+
if [ ! -z "${DEBUG}" ]; then set -x; fi
45
if [ -z "${GITHUB_ACTIONS}" ]; then
56
exec okv ${@}
67
else
78
strict_mode='--no-strict'
89
if [ "${INPUT_STRICT}" = "true" ]; then strict_mode=''; fi
910
INPUT_CPU_NUM="$(env | sed -n 's/^INPUT_CPU-NUM=\(.*\)/\1/p')"
11+
INPUT_FILE_RESTRICTIONS="$(env | sed -n 's/^INPUT_FILE-RESTRICTIONS=\(.*\)/\1/p')"
1012
schema_flag="--ok=${INPUT_OK}"
1113
if [ ! -z "${INPUT_SCHEMA}" ]; then
1214
schema_flag="--schema=${INPUT_SCHEMA}"
1315
fi
14-
output=$(okv ${schema_flag} --cpu-num=${INPUT_CPU_NUM} --parser=${INPUT_PARSER} ${strict_mode} -path=${INPUT_PATH})
15-
result=$?
16+
output=""
17+
result="0"
18+
set +e
19+
if [ -z "${INPUT_FILE_RESTRICTIONS}" ]; then
20+
output=$(okv ${schema_flag} --cpu-num=${INPUT_CPU_NUM} --parser=${INPUT_PARSER} ${strict_mode} -path=${INPUT_PATH})
21+
result=$?
22+
echo "${output}"
23+
else
24+
# INPUT_FILE_RESTRICTIONS is expected to be a space-separated array
25+
# of files
26+
file_arr=($INPUT_FILE_RESTRICTIONS)
27+
for file in ${file_arr[@]}; do
28+
# If an input path is also provided, it is expected to serve as an
29+
# enforced prefix for each of the file restrictions. In the case
30+
# of the pull request, this means that added and modified files
31+
# must exist within a particular directory or match a file
32+
if [[ ! -z "${INPUT_PATH}" ]] && [[ "${file}" != ${INPUT_PATH}*.y*ml ]]; then
33+
continue
34+
fi
35+
if [ ! -f "${file}" ]; then
36+
continue
37+
fi
38+
tmp_output=$(okv ${schema_flag} --cpu-num=${INPUT_CPU_NUM} --parser=${INPUT_PARSER} ${strict_mode} -path=${file})
39+
tmp_result=$?
40+
# Loop over all files before throwing non-zero exit below
41+
if [ "${tmp_result}" == "0" ]; then
42+
continue
43+
fi
44+
if [ "${result}" == "0" ]; then
45+
result="$tmp_result"
46+
fi
47+
if [ -z "${output}" ]; then
48+
output="${tmp_output}"
49+
echo "${output}"
50+
else
51+
echo "----
52+
${tmp_output}"
53+
output="${output}
54+
----
55+
${tmp_output}"
56+
fi
57+
done
58+
fi
59+
set -e
1660
echo "::set-output name=results::$(echo $output)"
1761
if [ "${result}" != "0" ]; then exit 1; fi
1862
fi

0 commit comments

Comments
 (0)