From c7b0fc95bfe65571861b9a749b0cc32085b1e620 Mon Sep 17 00:00:00 2001 From: Graham McGregor Date: Wed, 25 May 2022 18:46:26 -0400 Subject: [PATCH 1/8] chore: rename workflow file This isn't just for spellcheck --- .github/workflows/{spellcheck.yaml => ci.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{spellcheck.yaml => ci.yaml} (100%) diff --git a/.github/workflows/spellcheck.yaml b/.github/workflows/ci.yaml similarity index 100% rename from .github/workflows/spellcheck.yaml rename to .github/workflows/ci.yaml From 8e0932de7f59f07f02a68a3db28ef59332fa9579 Mon Sep 17 00:00:00 2001 From: Graham McGregor Date: Wed, 25 May 2022 14:15:25 -0400 Subject: [PATCH 2/8] chore: fix typo and upgrade cspell config version --- .github/workflows/ci.yaml | 2 +- README.md | 2 +- cspell.json | 2 +- error-ouput.jpg => error-output.jpg | Bin 4 files changed, 3 insertions(+), 3 deletions(-) rename error-ouput.jpg => error-output.jpg (100%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f6b3607..ec72b0a 100644 --- a/.github/workflows/ci.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: 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..7d56802 100644 --- a/cspell.json +++ b/cspell.json @@ -1,4 +1,4 @@ { - "version": "0.1", + "version": "0.2", "allowCompoundWords": true } diff --git a/error-ouput.jpg b/error-output.jpg similarity index 100% rename from error-ouput.jpg rename to error-output.jpg From b519a090cf157fa2463afafdf5bb53694c2156f4 Mon Sep 17 00:00:00 2001 From: Graham McGregor Date: Wed, 25 May 2022 18:44:31 -0400 Subject: [PATCH 3/8] build: add basic tests --- .github/workflows/ci.yaml | 10 ++++++++++ package.json | 4 +++- src/index.js | 5 ----- test.sh | 16 ---------------- test/python-err.sh | 5 ----- test/test-python-err.sh | 9 +++++++++ test/test-template.sh | 17 +++++++++++++++++ test/test.Dockerfile | 14 ++++++++++++++ test/test.sh | 9 +++++++++ 9 files changed, 62 insertions(+), 27 deletions(-) delete mode 100755 test.sh delete mode 100755 test/python-err.sh create mode 100755 test/test-python-err.sh create mode 100755 test/test-template.sh create mode 100644 test/test.Dockerfile create mode 100755 test/test.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ec72b0a..afbd818 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,3 +18,13 @@ 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: Test + run: | + npm run test diff --git a/package.json b/package.json index 3061874..47c53b7 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 -it -v $(pwd):/work -w /work test-container ./test/test.sh", + "test:debug": "npm run build:test-container && docker run --rm -it -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..424e3f4 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}`); 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..0d98d47 --- /dev/null +++ b/test/test.sh @@ -0,0 +1,9 @@ +#!/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 From 11ea02066de07bf0d799abab92210ac92c747cab Mon Sep 17 00:00:00 2001 From: Graham McGregor Date: Wed, 25 May 2022 18:48:47 -0400 Subject: [PATCH 4/8] fix: update filename color for light terminal theme --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 424e3f4..d412636 100755 --- a/src/index.js +++ b/src/index.js @@ -58,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); From a3dc2cccdf3cfe2e365830f18c0c4ec7a603f5e0 Mon Sep 17 00:00:00 2001 From: Graham McGregor Date: Wed, 25 May 2022 18:52:20 -0400 Subject: [PATCH 5/8] add spelling exception --- cspell.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cspell.json b/cspell.json index 7d56802..64fb2da 100644 --- a/cspell.json +++ b/cspell.json @@ -1,4 +1,8 @@ { "version": "0.2", - "allowCompoundWords": true + "allowCompoundWords": true, + "words": [ + // + "McGregor" + ] } From 871bb9d5f9a1749558b6e00320fbfef24c91b934 Mon Sep 17 00:00:00 2001 From: Graham McGregor Date: Wed, 25 May 2022 18:53:52 -0400 Subject: [PATCH 6/8] update spellcheck action --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index afbd818..a16f8aa 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: From 5ef3f4385a128a6d6403ecc1335e62cc9f5c7861 Mon Sep 17 00:00:00 2001 From: Graham McGregor Date: Wed, 25 May 2022 18:54:37 -0400 Subject: [PATCH 7/8] fix for ci --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 47c53b7..1f23875 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "check:format": "npm run prettier -- --check", "fix:format": "npm run prettier -- --write", "build:test-container": "docker build --progress=plain -f ./test/test.Dockerfile -t test-container .", - "test": "npm run build:test-container && docker run --rm -it -v $(pwd):/work -w /work test-container ./test/test.sh", - "test:debug": "npm run build:test-container && docker run --rm -it -v $(pwd):/work -w /work -e DEBUG=true test-container ./test/test.sh" + "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", From 47ff81c32871f88626e1a3ff01b54c9aa065f285 Mon Sep 17 00:00:00 2001 From: Graham McGregor Date: Wed, 25 May 2022 18:58:12 -0400 Subject: [PATCH 8/8] Improve test output for ci --- .github/workflows/ci.yaml | 3 +++ test/test.sh | 2 ++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a16f8aa..4813745 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,6 +25,9 @@ jobs: - name: Install dependencies run: | npm ci + - name: Prep container + run: | + npm run build:test-container - name: Test run: | npm run test diff --git a/test/test.sh b/test/test.sh index 0d98d47..b7a4b92 100755 --- a/test/test.sh +++ b/test/test.sh @@ -7,3 +7,5 @@ find test/ -name '*.yaml' -o -name '*.json' -print0 | xargs -0 -L1 -I{} ./test/t if [ -n "$DEBUG" ]; then ./test/test-python-err.sh fi + +echo "Test complete!"