Move linters from Azure to GHA

Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>
This commit is contained in:
Josh Kneubuhl 2022-11-13 04:10:46 -05:00
parent 34734cfff2
commit 8b0dab01b0
8 changed files with 176 additions and 65 deletions

68
.github/workflows/lint.yaml vendored Normal file
View file

@ -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

View file

@ -86,25 +86,6 @@ jobs:
- template: templates/install-deps.yml - template: templates/install-deps.yml
- template: templates/fabcar/azure-pipelines-typescript.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 - job: TestNetworkBasic
displayName: Test Network displayName: Test Network
pool: pool:

34
ci/scripts/lint-go.sh Executable file
View file

@ -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 <path>' 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 <path>' to fix these issues:"
echo "${output}"
fi
popd
done

24
ci/scripts/lint-java.sh Executable file
View file

@ -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

22
ci/scripts/lint-javascript.sh Executable file
View file

@ -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

22
ci/scripts/lint-typescript.sh Executable file
View file

@ -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

View file

@ -1,50 +1,10 @@
#!/bin/bash #!/bin/bash
set -euo pipefail set -euo pipefail
function print() { cd "$(dirname "$0")/../.."
GREEN='\033[0;32m'
NC='\033[0m'
echo
echo -e "${GREEN}${1}${NC}"
}
go install golang.org/x/tools/cmd/goimports@latest ci/scripts/lint-go.sh
ci/scripts/lint-javascript.sh
dirs=("$(find . -name "*-go" -o -name "*-java" -o -name "*-javascript" -o -name "*-typescript" -not -path '*/.*')") ci/scripts/lint-typescript.sh
for dir in $dirs; do ci/scripts/lint-java.sh
if [[ -d $dir ]] && [[ ! $dir =~ node_modules ]]; then ci/scripts/lint-shell.sh
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 <path>' 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 <path>' 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