Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #17 from aaron-trout/recursive-dir
Browse files Browse the repository at this point in the history
Recursively search directory for yaml files
  • Loading branch information
stefanprodan authored Dec 2, 2019
2 parents 4847d55 + dbc7078 commit ab23715
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Validate all Helm Releases in the test dir
id: validate-dir
uses: ./
with:
helmRelease: test/
- name: Check tested file count
env:
NUM_FILES_TESTED: ${{ steps.validate-dir.outputs.numFilesTested }}
run: "(( NUM_FILES_TESTED==3 ))"
push-container:
runs-on: ubuntu-latest
needs: [test-action, test-dir]
if: github.repository == 'stefanprodan/hrval-action' && github.ref == 'master'
steps:
- uses: actions/checkout@v1
- name: Publish to Docker Hub
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ inputs:
helmVersion:
description: 'Version of Helm to validate against'
default: 'v2'
outputs:
numFilesTested:
description: The number of HelmRelease files which were tested

runs:
using: 'docker'
Expand Down
10 changes: 9 additions & 1 deletion src/hrval-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ if [[ ${HELM_VER} == "v2" ]]; then
helm init --client-only
fi

# If the path provided is actually a file, just run hrval against this one file
if test -f "${DIR}"; then
${HRVAL} ${DIR} ${IGNORE_VALUES} ${KUBE_VER} ${HELM_VER}
exit 0
fi

# If the path provided is not a directory, print error message and exit
if [ ! -d "$DIR" ]; then
echo "\"${DIR}\" directory not found!"
exit 1
Expand All @@ -31,11 +33,17 @@ function isHelmRelease {
fi
}

# Find yaml files in directory recursively
DIR_PATH=$(echo ${DIR} | sed "s/^\///;s/\/$//")
for f in ${DIR_PATH}/*.yaml; do
FILES_TESTED=0
for f in `find ${DIR} -type f -name '*.yaml'`; do
if [[ $(isHelmRelease ${f}) == "true" ]]; then
${HRVAL} ${f} ${IGNORE_VALUES} ${KUBE_VER} ${HELM_VER}
FILES_TESTED=$(( FILES_TESTED+1 ))
else
echo "Ignoring ${f} not a HelmRelease"
fi
done

# This will set the GitHub actions output 'numFilesTested'
echo "::set-output name=numFilesTested::${FILES_TESTED}"
File renamed without changes.
1 change: 1 addition & 0 deletions test/subdirectory/not-a-yaml-file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
7 changes: 7 additions & 0 deletions test/subdirectory/some-other-yaml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: foo
annotations:
description: a file which should not get tested by hrval
data: {}

0 comments on commit ab23715

Please sign in to comment.