diff --git a/ci/azure-pipelines.yml b/ci/azure-pipelines.yml index 27f8d376..ea35f4c6 100644 --- a/ci/azure-pipelines.yml +++ b/ci/azure-pipelines.yml @@ -74,68 +74,6 @@ jobs: displayName: Lint pool: vmImage: ubuntu-18.04 - strategy: - matrix: - Basic-Application-Go: - DIRECTORY: asset-transfer-basic - LANGUAGE: go - TYPE: application - Basic-Application-Java: - DIRECTORY: asset-transfer-basic - LANGUAGE: java - TYPE: application - Basic-Application-Javascript: - DIRECTORY: asset-transfer-basic - LANGUAGE: javascript - TYPE: application - Basic-Chaincode-Go: - DIRECTORY: asset-transfer-basic - LANGUAGE: go - TYPE: chaincode - Basic-Chaincode-Java: - DIRECTORY: asset-transfer-basic - LANGUAGE: java - TYPE: chaincode - Basic-Chaincode-Javascript: - DIRECTORY: asset-transfer-basic - LANGUAGE: javascript - TYPE: chaincode - Basic-Chaincode-Typescript: - DIRECTORY: asset-transfer-basic - LANGUAGE: typescript - TYPE: chaincode - Ledger-Application-Java: - DIRECTORY: asset-transfer-ledger-queries - LANGUAGE: java - TYPE: application - Ledger-Chaincode-Go: - DIRECTORY: asset-transfer-ledger-queries - LANGUAGE: go - TYPE: chaincode - Ledger-Chaincode-Javascript: - DIRECTORY: asset-transfer-ledger-queries - LANGUAGE: javascript - TYPE: chaincode - PrivateData-Application-Javascript: - DIRECTORY: asset-transfer-private-data - LANGUAGE: javascript - TYPE: application - PrivateData-Chaincode-Go: - DIRECTORY: asset-transfer-private-data - LANGUAGE: go - TYPE: chaincode - SBE-Chaincode-Typescript: - DIRECTORY: asset-transfer-sbe - LANGUAGE: typescript - TYPE: chaincode - SBE-Chaincode-Java: - DIRECTORY: asset-transfer-sbe - LANGUAGE: java - TYPE: chaincode - Secured-Chaincode-Go: - DIRECTORY: asset-transfer-secured-agreement - LANGUAGE: go - TYPE: chaincode steps: - task: GoTool@0 inputs: @@ -146,6 +84,8 @@ jobs: inputs: versionSpec: $(NODE_VER) displayName: Install Node.js + - script: npm install -g typescript eslint tslint + displayName: Install Javascript Linting Deps - script: ./ci/scripts/lint.sh displayName: Lint Code diff --git a/ci/scripts/lint.sh b/ci/scripts/lint.sh index 275b4d62..55be08e4 100755 --- a/ci/scripts/lint.sh +++ b/ci/scripts/lint.sh @@ -7,45 +7,47 @@ function print() { echo -e "${GREEN}${1}${NC}" } -if [[ "${LANGUAGE}" == "go" ]]; then - go get golang.org/x/tools/cmd/goimports +dirs=("$(find . -name "*-go" -o -name "*-java" -o -name "*-javascript" -o -name "*-typescript")") +for dir in $dirs; do + if [[ -d $dir ]]; then + print "Linting $dir" + pushd $dir + if [[ "$dir" =~ "-go" ]]; then + go get golang.org/x/tools/cmd/goimports + print "Running go vet" + go vet ./... + print "Running gofmt" + output=$(gofmt -l -s $(go list -f '{{.Dir}}' ./...)) + if [[ "${output}" != "" ]]; then + print "The following files contain formatting errors, please run 'gofmt -l -w ' to fix these issues:" + echo "${output}" + fi - cd "${DIRECTORY}/${TYPE}-${LANGUAGE}" - print "Running go vet" - go vet ./... - - print "Running gofmt" - output=$(gofmt -l -s $(go list -f '{{.Dir}}' ./...)) - if [[ "${output}" != "" ]]; then - print "The following files contain formatting errors, please run 'gofmt -l -w ' to fix these issues:" - echo "${output}" + print "Running goimports" + output=$(goimports -l $(go list -f '{{.Dir}}' ./...)) + if [[ "${output}" != "" ]]; then + print "The following files contain import errors, please run 'goimports -l -w ' to fix these issues:" + echo "${output}" + fi + elif [[ "$dir" =~ "-javascript" ]]; then + print "Running ESLint" + if [[ "$dir" =~ "chaincode" ]]; then + eslint *.js */**.js + else + eslint *.js + fi + elif [[ "$dir" =~ "-java" ]]; then + if [[ -f "pom.xml" ]]; then + print "Running Maven Build" + mvn clean package + else + print "Running Gradle Build" + ./gradlew build + fi + elif [[ "$dir" =~ "-typescript" ]]; then + print "Running TSLint" + tslint --project . + fi + popd fi - - print "Running goimports" - output=$(goimports -l $(go list -f '{{.Dir}}' ./...)) - if [[ "${output}" != "" ]]; then - print "The following files contain import errors, please run 'goimports -l -w ' to fix these issues:" - echo "${output}" - fi -elif [[ "${LANGUAGE}" == "java" ]]; then - cd "${DIRECTORY}/${TYPE}-${LANGUAGE}" - print "Running Gradle Build" - ./gradlew build -elif [[ "${LANGUAGE}" == "javascript" ]]; then - npm install -g eslint - cd "${DIRECTORY}/${TYPE}-${LANGUAGE}" - print "Running ESLint" - if [[ "${TYPE}" == "chaincode" ]]; then - eslint *.js */**.js - else - eslint *.js - fi -elif [[ "${LANGUAGE}" == "typescript" ]]; then - npm install -g typescript tslint - cd "${DIRECTORY}/${TYPE}-${LANGUAGE}" - print "Running TSLint" - tslint --project . -else - echo "Language not supported" - exit 1 -fi +done