From 8b0dab01b0b44491909bff67889c84b32dd2970a Mon Sep 17 00:00:00 2001 From: Josh Kneubuhl Date: Sun, 13 Nov 2022 04:10:46 -0500 Subject: [PATCH] Move linters from Azure to GHA Signed-off-by: Josh Kneubuhl --- .github/workflows/lint.yaml | 68 +++++++++++++++++++++ ci/azure-pipelines.yml | 19 ------ ci/scripts/lint-go.sh | 34 +++++++++++ ci/scripts/lint-java.sh | 24 ++++++++ ci/scripts/lint-javascript.sh | 22 +++++++ ci/scripts/{shellcheck.sh => lint-shell.sh} | 0 ci/scripts/lint-typescript.sh | 22 +++++++ ci/scripts/lint.sh | 52 ++-------------- 8 files changed, 176 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/lint.yaml create mode 100755 ci/scripts/lint-go.sh create mode 100755 ci/scripts/lint-java.sh create mode 100755 ci/scripts/lint-javascript.sh rename ci/scripts/{shellcheck.sh => lint-shell.sh} (100%) create mode 100755 ci/scripts/lint-typescript.sh diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 00000000..2003533d --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,68 @@ +# +# SPDX-License-Identifier: Apache-2.0 +# +name: Lint +run-name: ${{ github.actor }} is linting fabric-samples + +on: + workflow_dispatch: + push: + branches: + - main + - release-1.4 + - release-2.2 + pull_request: + branches: + - main + - release-1.4 + - release-2.2 + +env: + GO_VER: 1.18.3 + NODE_VER: 16.x + JAVA_VER: 11.x + +jobs: + go: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VER }} + - uses: actions/checkout@v3 + - run: go install golang.org/x/tools/cmd/goimports@latest + - run: ci/scripts/lint-go.sh + + typescript: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VER }} + - run: ci/scripts/lint-typescript.sh + + javascript: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VER }} + - run: ci/scripts/lint-javascript.sh + + java: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: ${{ env.JAVA_VER }} + - run: ci/scripts/lint-java.sh + + shell: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: ci/scripts/lint-shell.sh diff --git a/ci/azure-pipelines.yml b/ci/azure-pipelines.yml index 1fbb352c..0bf9bd8b 100644 --- a/ci/azure-pipelines.yml +++ b/ci/azure-pipelines.yml @@ -86,25 +86,6 @@ jobs: - template: templates/install-deps.yml - template: templates/fabcar/azure-pipelines-typescript.yml - - job: Lint - displayName: Lint - pool: - vmImage: ubuntu-20.04 - steps: - - task: GoTool@0 - inputs: - goBin: $(GO_BIN) - version: $(GO_VER) - displayName: Install GoLang - - task: NodeTool@0 - inputs: - versionSpec: $(NODE_VER) - displayName: Install Node.js - - script: ./ci/scripts/shellcheck.sh - displayName: Lint Shell Scripts - - script: ./ci/scripts/lint.sh - displayName: Lint Code - - job: TestNetworkBasic displayName: Test Network pool: diff --git a/ci/scripts/lint-go.sh b/ci/scripts/lint-go.sh new file mode 100755 index 00000000..e869ef1d --- /dev/null +++ b/ci/scripts/lint-go.sh @@ -0,0 +1,34 @@ +#!/bin/bash +set -euo pipefail + +function print() { + GREEN='\033[0;32m' + NC='\033[0m' + echo + echo -e "${GREEN}${1}${NC}" +} + +dirs=("$(find . -name "*-go" -type d -not -path '*/.*')") +for dir in $dirs; do + print "Linting $dir" + pushd $dir + + print "Running go vet" + go vet -tags pkcs11 ./... + + print "Running gofmt" + output=$(gofmt -l -s $(go list -tags pkcs11 -f '{{.Dir}}' ./...)) + if [[ "${output}" != "" ]]; then + print "The following files contain formatting errors, please run 'gofmt -l -w ' to fix these issues:" + echo "${output}" + fi + + print "Running goimports" + output=$(goimports -l $(go list -tags pkcs11 -f '{{.Dir}}' ./...)) + if [[ "${output}" != "" ]]; then + print "The following files contain import errors, please run 'goimports -l -w ' to fix these issues:" + echo "${output}" + fi + + popd +done \ No newline at end of file diff --git a/ci/scripts/lint-java.sh b/ci/scripts/lint-java.sh new file mode 100755 index 00000000..327a91e7 --- /dev/null +++ b/ci/scripts/lint-java.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -euo pipefail + +function print() { + GREEN='\033[0;32m' + NC='\033[0m' + echo + echo -e "${GREEN}${1}${NC}" +} + +dirs=("$(find . -name "*-java" -type d -not -path '*/.*')") +for dir in $dirs; do + print "Linting $dir" + pushd $dir + + if [[ -f "pom.xml" ]]; then + print "Running Maven Build" + mvn clean package + else + print "Running Gradle Build" + ./gradlew build + fi + popd +done \ No newline at end of file diff --git a/ci/scripts/lint-javascript.sh b/ci/scripts/lint-javascript.sh new file mode 100755 index 00000000..0279b125 --- /dev/null +++ b/ci/scripts/lint-javascript.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -euo pipefail + +function print() { + GREEN='\033[0;32m' + NC='\033[0m' + echo + echo -e "${GREEN}${1}${NC}" +} + +dirs=("$(find . -name "*-javascript" -type d -not -path '*/.*')") +for dir in $dirs; do + print "Linting $dir" + pushd $dir + + print "Installing node modules" + npm install + print "Running Lint" + npm run lint + + popd +done \ No newline at end of file diff --git a/ci/scripts/shellcheck.sh b/ci/scripts/lint-shell.sh similarity index 100% rename from ci/scripts/shellcheck.sh rename to ci/scripts/lint-shell.sh diff --git a/ci/scripts/lint-typescript.sh b/ci/scripts/lint-typescript.sh new file mode 100755 index 00000000..86bcc36b --- /dev/null +++ b/ci/scripts/lint-typescript.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -euo pipefail + +function print() { + GREEN='\033[0;32m' + NC='\033[0m' + echo + echo -e "${GREEN}${1}${NC}" +} + +dirs=("$(find . -name "*-typescript" -type d -not -path '*/.*')") +for dir in $dirs; do + print "Linting $dir" + pushd $dir + + print "Installing node modules" + npm install + print "Running Lint" + npm run lint + + popd +done \ No newline at end of file diff --git a/ci/scripts/lint.sh b/ci/scripts/lint.sh index 74b4f495..842be747 100755 --- a/ci/scripts/lint.sh +++ b/ci/scripts/lint.sh @@ -1,50 +1,10 @@ #!/bin/bash set -euo pipefail -function print() { - GREEN='\033[0;32m' - NC='\033[0m' - echo - echo -e "${GREEN}${1}${NC}" -} +cd "$(dirname "$0")/../.." -go install golang.org/x/tools/cmd/goimports@latest - -dirs=("$(find . -name "*-go" -o -name "*-java" -o -name "*-javascript" -o -name "*-typescript" -not -path '*/.*')") -for dir in $dirs; do - if [[ -d $dir ]] && [[ ! $dir =~ node_modules ]]; then - print "Linting $dir" - pushd $dir - if [[ "$dir" =~ "-go" ]]; then - print "Running go vet" - go vet -tags pkcs11 ./... - print "Running gofmt" - output=$(gofmt -l -s $(go list -tags pkcs11 -f '{{.Dir}}' ./...)) - if [[ "${output}" != "" ]]; then - print "The following files contain formatting errors, please run 'gofmt -l -w ' to fix these issues:" - echo "${output}" - fi - - print "Running goimports" - output=$(goimports -l $(go list -tags pkcs11 -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" || "$dir" =~ "-typescript" ]]; then - print "Installing node modules" - npm install - print "Running Lint" - npm run lint - elif [[ "$dir" =~ "-java" ]]; then - if [[ -f "pom.xml" ]]; then - print "Running Maven Build" - mvn clean package - else - print "Running Gradle Build" - ./gradlew build - fi - fi - popd - fi -done +ci/scripts/lint-go.sh +ci/scripts/lint-javascript.sh +ci/scripts/lint-typescript.sh +ci/scripts/lint-java.sh +ci/scripts/lint-shell.sh \ No newline at end of file