diff --git a/.github/workflows/spellcheck.yaml b/.github/workflows/ci.yaml similarity index 52% rename from .github/workflows/spellcheck.yaml rename to .github/workflows/ci.yaml index f6b3607..4813745 100644 --- a/.github/workflows/spellcheck.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,4 @@ -name: Continuos Integration +name: Continuous Integration on: # rebuild any PRs and main branch changes pull_request: @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: streetsidesoftware/cspell-action@v1.0.1 + - uses: streetsidesoftware/cspell-action@v1.6.2 lint-format: # run the action runs-on: ubuntu-latest steps: @@ -18,3 +18,16 @@ jobs: - name: Check Format run: | npm run check:format + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: | + npm ci + - name: Prep container + run: | + npm run build:test-container + - name: Test + run: | + npm run test diff --git a/README.md b/README.md index 57e205c..6f18d00 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Example: [cfn-lint]: https://github.com/aws-cloudformation/cfn-python-lint -![An example of the CLI output](https://github.com/Graham42/cfn-lint-to-codeframe/blob/main/error-ouput.jpg?raw=true) +![An example of the CLI output](https://github.com/Graham42/cfn-lint-to-codeframe/blob/main/error-output.jpg?raw=true) ## Installation diff --git a/cspell.json b/cspell.json index 720c61a..64fb2da 100644 --- a/cspell.json +++ b/cspell.json @@ -1,4 +1,8 @@ { - "version": "0.1", - "allowCompoundWords": true + "version": "0.2", + "allowCompoundWords": true, + "words": [ + // + "McGregor" + ] } diff --git a/error-ouput.jpg b/error-output.jpg similarity index 100% rename from error-ouput.jpg rename to error-output.jpg diff --git a/package.json b/package.json index 3061874..1f23875 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "prettier": "prettier --ignore-path .gitignore \"**/*.{js,jsx,ts,tsx,html,vue,css,less,scss,graphql,yaml,yml,json,json5,md,mdx}\"", "check:format": "npm run prettier -- --check", "fix:format": "npm run prettier -- --write", - "test": "echo \"Error: no test specified\" && exit 1" + "build:test-container": "docker build --progress=plain -f ./test/test.Dockerfile -t test-container .", + "test": "npm run build:test-container && docker run --rm -t -v $(pwd):/work -w /work test-container ./test/test.sh", + "test:debug": "npm run build:test-container && docker run --rm -t -v $(pwd):/work -w /work -e DEBUG=true test-container ./test/test.sh" }, "main": "src/index.js", "bin": "src/index.js", diff --git a/src/index.js b/src/index.js index 1e63e8b..d412636 100755 --- a/src/index.js +++ b/src/index.js @@ -36,11 +36,6 @@ async function main() { try { err = parse(line); } catch (err) { - if (process.env.DEBUG) { - errorLog( - `Caught ${err}, assuming that the line should be part of the previous error message`, - ); - } // if there's no previous error then this seems like a real error if (result.length < 1) { errorLog(`Error parsing line: ${line}`); @@ -63,7 +58,7 @@ async function main() { const result = codeFrameColumns(contents, location, { highlightCode: true, }); - console.log(chalk.bgGray(err.fileName)); + console.log(chalk.gray(err.fileName)); console.log(" " + chalk.red.bold(err.message)); if (err.fileName.endsWith(".json")) { let path = getJsonPathFromRawLocation(contents, err.start); diff --git a/test.sh b/test.sh deleted file mode 100755 index a5b4322..0000000 --- a/test.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -# By running -# -# git clone https://github.com/aws-cloudformation/cfn-python-lint.git -# find cfn-python-lint/test/fixtures/templates/ -name '*.yaml' -print0 | xargs -0 -P 8 -I{} ./test.sh {} -# find cfn-python-lint/test/fixtures/templates/ -name '*.json' -print0 | xargs -0 -P 8 -I{} ./test.sh {} -# -# we can find templates that would cause issues. - -template="$1" -input=$(cfn-lint -t "${template}" -f parseable) -echo "$input" | ./src/index.js >/dev/null -if [ $? -ne 0 ]; then - echo "Error with $template" -fi diff --git a/test/python-err.sh b/test/python-err.sh deleted file mode 100755 index db3da1a..0000000 --- a/test/python-err.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -./test/python-err.py 2>&1 | ./src/index.js diff --git a/test/test-python-err.sh b/test/test-python-err.sh new file mode 100755 index 0000000..03f1256 --- /dev/null +++ b/test/test-python-err.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -e + +./test/python-err.py 2>&1 | ./src/index.js > /dev/null +if [ $? -ne 0 ]; then + echo "Error with handling python error" >&2 + exit 1 +fi diff --git a/test/test-template.sh b/test/test-template.sh new file mode 100755 index 0000000..7fda0f0 --- /dev/null +++ b/test/test-template.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +template="$1" +if [ -z "$template" ]; then + echo "Missing template parameter" >&2 + exit 1 +fi + +parseable_output=$(cfn-lint -t "${template}" -f parseable) +if [ -n "$DEBUG" ]; then + echo "$parseable_output" | ./src/index.js +fi +echo "$parseable_output" | ./src/index.js >/dev/null +if [ $? -ne 0 ]; then + echo "Error with $template" + exit 1 +fi diff --git a/test/test.Dockerfile b/test/test.Dockerfile new file mode 100644 index 0000000..323df91 --- /dev/null +++ b/test/test.Dockerfile @@ -0,0 +1,14 @@ +FROM node:16-slim + +RUN apt-get update && \ + apt-get install -y \ + python3 \ + python3-pip \ + && \ + ln -s /usr/bin/python3 /usr/bin/python && \ + ln -s /usr/bin/pip3 /usr/bin/pip && \ + python --version + +RUN pip install cfn-lint + +ENTRYPOINT ["bash"] diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 0000000..b7a4b92 --- /dev/null +++ b/test/test.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e -o pipefail + +find test/ -name '*.yaml' -o -name '*.json' -print0 | xargs -0 -L1 -I{} ./test/test-template.sh {} + +if [ -n "$DEBUG" ]; then + ./test/test-python-err.sh +fi + +echo "Test complete!"