diff --git a/Dockerfile b/Dockerfile index 39ef329..6ff1583 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,11 @@ FROM golang:1.16 AS build WORKDIR /app +# set env +RUN go env -w GO111MODULE=on +RUN go env -w GOPROXY=https://goproxy.cn,direct + +# cache dependencies COPY go.mod go.sum ./ RUN go mod download diff --git a/main.go b/main.go index b4cdd69..5b7081f 100644 --- a/main.go +++ b/main.go @@ -315,6 +315,8 @@ func licenseHeader(path string, tmpl *template.Template, data licenseData) ([]by // handle various cmake files if base == "cmakelists.txt" || strings.HasSuffix(base, ".cmake.in") || strings.HasSuffix(base, ".cmake") { lic, err = executeTemplate(tmpl, data, "", "# ", "") + } else if base == "Makefile" || base == "makefile" || strings.HasSuffix(base, ".mk") { // handle various make files + lic, err = executeTemplate(tmpl, data, "", "# ", "") } } return lic, err @@ -374,7 +376,11 @@ func hasLicense(b []byte) bool { if len(b) < 1000 { n = len(b) } - return bytes.Contains(bytes.ToLower(b[:n]), []byte("copyright")) || + return bytes.Contains(bytes.ToLower(b[:n]), []byte("# copyright")) || + bytes.Contains(bytes.ToLower(b[:n]), []byte("copyright ")) || + bytes.Contains(bytes.ToLower(b[:n]), []byte("// copyright")) || + bytes.Contains(bytes.ToLower(b[:n]), []byte("/* copyright")) || + bytes.Contains(bytes.ToLower(b[:n]), []byte("* copyright")) || bytes.Contains(bytes.ToLower(b[:n]), []byte("mozilla public")) || bytes.Contains(bytes.ToLower(b[:n]), []byte("spdx-license-identifier")) } diff --git a/main_test.go b/main_test.go index b2ed227..868be31 100644 --- a/main_test.go +++ b/main_test.go @@ -340,7 +340,7 @@ func TestLicenseHeader(t *testing.T) { "(**\n HYS\n*)\n\n", }, { - []string{"cmakelists.txt", "f.cmake", "f.cmake.in"}, + []string{"cmakelists.txt", "f.cmake", "f.cmake.in", "makefile", "Makefile", "f.mk"}, "# HYS\n\n", }, @@ -395,6 +395,10 @@ func TestHasLicense(t *testing.T) { {"Copyright 2000", true}, {"CoPyRiGhT 2000", true}, + {"// Copyright 2000", true}, + {"# CopyRight 2000", true}, + {"/*\n * CopyRight 2000", true}, + {"// SPDX-License-Identifier: MIT", true}, {"Subject to the terms of the Mozilla Public License", true}, {"SPDX-License-Identifier: MIT", true}, {"spdx-license-identifier: MIT", true},