Skip to content

Commit

Permalink
Fix license header CI checks (ava-labs#1492)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu committed May 12, 2023
1 parent a16d9fb commit f0a86cc
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 38 deletions.
2 changes: 0 additions & 2 deletions LICENSE.header

This file was deleted.

6 changes: 3 additions & 3 deletions ipcs/socket/socket_unix.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//go:build !windows && !plan9 && !js
// +build !windows,!plan9,!js

// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build !windows && !plan9 && !js
// +build !windows,!plan9,!js

package socket

import (
Expand Down
6 changes: 3 additions & 3 deletions ipcs/socket/socket_windows.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//go:build windows
// +build windows

// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build windows
// +build windows

package socket

import (
Expand Down
4 changes: 4 additions & 0 deletions license.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
header: |
// Copyright (C) 2019-{{YEAR}}, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
22 changes: 7 additions & 15 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,17 @@ function test_golangci_lint {
golangci-lint run --config .golangci.yml
}

# find_go_files [package]
# all go files except generated ones
function find_go_files {
local target="${1}"
go fmt -n "${target}" | grep -Eo "([^ ]*)$" | grep -vE "(\\.pb\\.go|\\.pb\\.gw.go)"
}

# automatically checks license headers
# to modify the file headers (if missing), remove "--check" flag
# TESTS='license_header' ADDLICENSE_FLAGS="-v" ./scripts/lint.sh
_addlicense_flags=${ADDLICENSE_FLAGS:-"--check -v"}
# to modify the file headers (if missing), remove "--verify" flag
# TESTS='license_header' ADDLICENSE_FLAGS="--debug" ./scripts/lint.sh
_addlicense_flags=${ADDLICENSE_FLAGS:-"--verify --debug"}
function test_license_header {
go install -v github.com/google/addlicense@latest
local target="${1}"
go install -v github.com/palantir/go-license@v1.25.0
local files=()
while IFS= read -r line; do files+=("$line"); done < <(find_go_files "${target}")
while IFS= read -r line; do files+=("$line"); done < <(find . -type f -name '*.go' ! -name '*.pb.go' ! -name 'mock_*.go')

addlicense \
-f ./LICENSE.header \
go-license \
--config=./license.yml \
${_addlicense_flags} \
"${files[@]}"
}
Expand Down
13 changes: 12 additions & 1 deletion scripts/mock.gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@ then
go install -v github.com/golang/mock/mockgen@v1.6.0
fi

if ! command -v go-license &> /dev/null
then
echo "go-license not found, installing..."
# https://github.com/palantir/go-license
go install -v github.com/palantir/go-license@v1.25.0
fi

# tuples of (source interface import path, comma-separated interface names, output file path)
input="scripts/mocks.mockgen.txt"
while IFS= read -r line
do
IFS='=' read src_import_path interface_name output_path <<< "${line}"
package_name=$(basename $(dirname $output_path))
echo "Generating ${output_path}..."
mockgen -copyright_file=./LICENSE.header -package=${package_name} -destination=${output_path} ${src_import_path} ${interface_name}
mockgen -package=${package_name} -destination=${output_path} ${src_import_path} ${interface_name}

go-license \
--config=./license.yml \
"${output_path}"
done < "$input"

echo "SUCCESS"
1 change: 1 addition & 0 deletions snow/engine/snowman/block/height_indexed_vm.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package block

import (
Expand Down
2 changes: 1 addition & 1 deletion utils/linkedhashmap/iterator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2023, Ava Labs, Inte. All rights reserved.
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package linkedhashmap
Expand Down
2 changes: 1 addition & 1 deletion utils/linkedhashmap/linkedhashmap.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2023, Ava Labs, Inte. All rights reserved.
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package linkedhashmap
Expand Down
6 changes: 3 additions & 3 deletions utils/storage/storage_unix.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//go:build !windows
// +build !windows

// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build !windows
// +build !windows

package storage

import "syscall"
Expand Down
6 changes: 3 additions & 3 deletions utils/storage/storage_windows.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//go:build windows
// +build windows

// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build windows
// +build windows

package storage

import (
Expand Down
6 changes: 3 additions & 3 deletions vms/rpcchainvm/runtime/subprocess/linux_stopper.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build linux
// +build linux

// ^ SIGTERM signal is not available on Windows
// ^ syscall.SysProcAttr only has field Pdeathsig on Linux

// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package subprocess

import (
Expand Down
6 changes: 3 additions & 3 deletions vms/rpcchainvm/runtime/subprocess/non_linux_stopper.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//go:build !linux
// +build !linux

// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build !linux
// +build !linux

package subprocess

import (
Expand Down

0 comments on commit f0a86cc

Please sign in to comment.