diff --git a/.github/workflows/hadolint.yml b/.github/workflows/hadolint.yml new file mode 100644 index 000000000000..3ba99d5a069c --- /dev/null +++ b/.github/workflows/hadolint.yml @@ -0,0 +1,49 @@ +name: Linter +on: pull_request +jobs: + HadoLint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Run checks + env: + HADOLINT: "${{ github.workspace }}/hadolint" + HADOLINT_VER: "2.1.0" + VERIFICATION_LEVEL: "error" + run: | + URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" + PR_FILES=$(curl -s -X GET -G $URL | jq -r '.[] | select(.status != "removed") | .filename') + for file in $PR_FILES; do + if [[ ${file} =~ 'Dockerfile' ]]; then + changed_dockerfiles+=" ${file}" + fi + done + + if [[ ! -z ${changed_dockerfiles} ]]; then + curl -sL -o ${HADOLINT} "https://github.com/hadolint/hadolint/releases/download/v${HADOLINT_VER}/hadolint-Linux-x86_64" && chmod 700 ${HADOLINT} + echo "HadoLint version: "`${HADOLINT} --version` + echo "The files will be checked: "`echo ${changed_dockerfiles}` + mkdir -p hadolint_report + + ${HADOLINT} --no-fail --format json ${changed_dockerfiles} > ./hadolint_report/hadolint_report.json + get_verification_level=`cat ./hadolint_report/hadolint_report.json | jq -r '.[] | .level'` + for line in ${get_verification_level}; do + if [[ ${line} =~ ${VERIFICATION_LEVEL} ]]; then + pip install json2html + python ./tests/json_to_html.py ./hadolint_report/hadolint_report.json + exit 1 + else + exit 0 + fi + done + else + echo "No files with the \"Dockerfile*\" name found" + fi + + - name: Upload artifacts + if: failure() + uses: actions/upload-artifact@v2 + with: + name: hadolint_report + path: hadolint_report diff --git a/.github/workflows/remark.yml b/.github/workflows/remark.yml new file mode 100644 index 000000000000..3550e5227087 --- /dev/null +++ b/.github/workflows/remark.yml @@ -0,0 +1,46 @@ +name: Linter +on: pull_request +jobs: + Remark: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 12 + + - name: Run checks + run: | + URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" + PR_FILES=$(curl -s -X GET -G $URL | jq -r '.[] | select(.status != "removed") | .filename') + for files in $PR_FILES; do + extension="${files##*.}" + if [[ $extension == 'md' ]]; then + changed_files_remark+=" ${files}" + fi + done + + if [[ ! -z ${changed_files_remark} ]]; then + npm ci + npm install remark-cli vfile-reporter-json + mkdir -p remark_report + + echo "Remark version: "`npx remark --version` + echo "The files will be checked: "`echo ${changed_files_remark}` + npx remark --report json --no-stdout ${changed_files_remark} 2> ./remark_report/remark_report.json + get_report=`cat ./remark_report/remark_report.json | jq -r '.[]'` + if [[ ! -z ${get_report} ]]; then + pip install json2html + python ./tests/json_to_html.py ./remark_report/remark_report.json + exit 1 + fi + else + echo "No files with the \"md\" extension found" + fi + + - name: Upload artifacts + if: failure() + uses: actions/upload-artifact@v2 + with: + name: remark_report + path: remark_report diff --git a/.github/workflows/stylelint.yml b/.github/workflows/stylelint.yml new file mode 100644 index 000000000000..76634447c915 --- /dev/null +++ b/.github/workflows/stylelint.yml @@ -0,0 +1,42 @@ +name: Linter +on: pull_request +jobs: + StyleLint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 12 + + - name: Run checks + run: | + URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" + PR_FILES=$(curl -s -X GET -G $URL | jq -r '.[] | select(.status != "removed") | .filename') + for files in $PR_FILES; do + extension="${files##*.}" + if [[ $extension == 'css' || $extension == 'scss' ]]; then + changed_files_stylelint+=" ${files}" + fi + done + + if [[ ! -z ${changed_files_stylelint} ]]; then + npm ci + mkdir -p stylelint_report + + echo "StyleLint version: "`npx stylelint --version` + echo "The files will be checked: "`echo ${changed_files_stylelint}` + npx stylelint --formatter json --output-file ./stylelint_report/stylelint_report.json ${changed_files_stylelint} || exit_code=`echo $?` || true + pip install json2html + python ./tests/json_to_html.py ./stylelint_report/stylelint_report.json + exit ${exit_code} + else + echo "No files with the \"css|scss\" extension found" + fi + + - name: Upload artifacts + if: failure() + uses: actions/upload-artifact@v2 + with: + name: stylelint_report + path: stylelint_report diff --git a/tests/json_to_html.py b/tests/json_to_html.py new file mode 100644 index 000000000000..901179559c14 --- /dev/null +++ b/tests/json_to_html.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT + +from json2html import * +import sys +import os +import json + +def json_to_html(path_to_json): + with open(path_to_json) as json_file: + data = json.load(json_file) + hadolint_html_report = json2html.convert(json = data) + + with open(os.path.splitext(path_to_json)[0] + '.html', 'w') as html_file: + html_file.write(hadolint_html_report) + + +if __name__ == '__main__': + json_to_html(sys.argv[1])