-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: asararatnakar <asara.ratnakar@gmail.com>
- Loading branch information
1 parent
e044966
commit 184d8b2
Showing
8 changed files
with
276 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# | ||
# Copyright contributors to the Hyperledger Fabric Operator project | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
name: basic-tests | ||
|
||
on: | ||
push: | ||
branches: [api] | ||
pull_request: | ||
branches: [api] | ||
|
||
env: | ||
GO_VER: 1.18 | ||
|
||
jobs: | ||
make-checks: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ env.GO_VER }} | ||
- name: license header checks | ||
run: scripts/check-license.sh | ||
- name: gosec | ||
run: make go-sec | ||
- name: Run vet and format checks | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# | ||
# Copyright contributors to the Hyperledger Fabric Operator project | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
## license checks | ||
check-license: | ||
@scripts/check-licenses.sh | ||
|
||
# Run go fmt against code | ||
fmt: | ||
go fmt ./... | ||
|
||
# Run go vet against code | ||
vet: | ||
@scripts/checks.sh | ||
|
||
checks: fmt vet | ||
|
||
# gosec checks | ||
gosec: | ||
@scripts/go-sec.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright contributors to the Hyperledger Fabric Operator project | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
cat << EOB > golang_copyright.txt | ||
/* | ||
* Copyright contributors to the Hyperledger Fabric Operator project | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
EOB | ||
|
||
cat << EOB > shell_copyright.txt | ||
# | ||
# Copyright contributors to the Hyperledger Fabric Operator project | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
EOB | ||
|
||
function filterGeneratedFiles { | ||
for f in $@; do | ||
head -n5 $f | grep -qE 'Code generated by.*DO NOT EDIT' || echo $f | ||
done | ||
} | ||
|
||
function filterExcludedFiles { | ||
CHECK=`echo "$CHECK" \ | ||
| grep -v "^\.git/" \ | ||
| grep -v "^\.gitignore" \ | ||
| grep -v "\.txt$" \ | ||
| grep -v "vendor/" \ | ||
| grep -v "go.mod" \ | ||
| grep -v "go.sum" \ | ||
| grep -v .deepcopy.go \ | ||
| sort -u` | ||
|
||
CHECK=$(filterGeneratedFiles "$CHECK") | ||
} | ||
|
||
CHECK=$(git diff --name-only --diff-filter=ACMRTUXB HEAD) | ||
filterExcludedFiles | ||
if [[ -z "$CHECK" ]]; then | ||
CHECK=$(git diff-tree --no-commit-id --name-only --diff-filter=ACMRTUXB -r "HEAD^..HEAD") | ||
filterExcludedFiles | ||
fi | ||
|
||
if [[ -z "$CHECK" ]]; then | ||
echo "All files are excluded from having license headers" | ||
exit 0 | ||
fi | ||
|
||
missing=`echo "$CHECK" | xargs ls -d 2>/dev/null | xargs grep -L "SPDX-License-Identifier: Apache-2.0"` | ||
if [[ -z "$missing" ]]; then | ||
echo "All files have SPDX-License-Identifier: Apache-2.0" | ||
exit 0 | ||
fi | ||
|
||
TMPFILE="./tmpfile" | ||
|
||
for FILE in ${missing}; do | ||
EXT="${FILE##*.}" | ||
echo "Adding copyright notice to $FILE" | ||
if [ "${EXT}" = "go" ]; then | ||
cat golang_copyright.txt ${FILE} > ${TMPFILE} | ||
cat ${TMPFILE} > ${FILE} | ||
rm -f ${TMPFILE} | ||
echo " ${FILE} copyright notice added" | ||
elif [ "${EXT}" = "yaml" ]; then | ||
cat shell_copyright.txt ${FILE} > ${TMPFILE} | ||
cat ${TMPFILE} > ${FILE} | ||
rm -f ${TMPFILE} | ||
echo " ${FILE} copyright notice added" | ||
elif [ "${EXT}" = "sh" ]; then | ||
cat shell_copyright.txt ${FILE} > ${TMPFILE} | ||
cat ${TMPFILE} > ${FILE} | ||
rm -f ${TMPFILE} | ||
echo " ${FILE} copyright notice added" | ||
else | ||
echo "invalid file extension" | ||
fi | ||
done | ||
|
||
rm golang_copyright.txt shell_copyright.txt | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright contributors to the Hyperledger Fabric Operator project | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# Need to run this before go vet | ||
go mod download | ||
|
||
echo "Running 'go vet'" | ||
OUTPUT=`go vet -all ./... 2>&1` | ||
if [ -n "$OUTPUT" ]; then | ||
echo "The following files contain go vet errors" | ||
echo $OUTPUT | ||
exit 1 | ||
fi | ||
echo "No 'go vet' issues found" | ||
|
||
cd /tmp | ||
go install golang.org/x/tools/cmd/goimports@ff88973b1e4e | ||
cd - | ||
echo "Checking imports ..." | ||
found=`goimports -l \`find . -path ./vendor -prune -o -name "*.go" -print\` 2>&1` | ||
found=$(echo "$found" | grep -v generated) | ||
if [ "$found" != "" ]; then | ||
echo "The following files have import problems:" | ||
echo "$found" | ||
echo "You may run 'goimports -w <file>' to fix each file." | ||
exit 1 | ||
fi | ||
echo "All files are properly formatted" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright contributors to the Hyperledger Fabric Operator project | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(go env GOPATH)/bin $RELEASE | ||
|
||
gosec ./... |