From 993e1fb29f9ccd735f6c7ae1221a0c30ae89faf5 Mon Sep 17 00:00:00 2001 From: zhouzaihang Date: Fri, 6 Oct 2023 09:20:42 +0000 Subject: [PATCH 1/6] feat: add headers to Makefiles also Ensure makefiles also get license headers. --- main.go | 2 ++ main_test.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index b4cdd69..f182023 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 diff --git a/main_test.go b/main_test.go index b2ed227..890ff5d 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", }, From ef1869cbc6923cbb34440f20a402a6d242636127 Mon Sep 17 00:00:00 2001 From: ZhouZaihang Date: Fri, 6 Oct 2023 17:37:52 +0800 Subject: [PATCH 2/6] ci: using GOPROXY for build image --- Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) 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 From 8efd1db35634399d845381e702191d9e7d708388 Mon Sep 17 00:00:00 2001 From: ZhouZaihang Date: Fri, 6 Oct 2023 17:38:20 +0800 Subject: [PATCH 3/6] fix: check "# copyright" --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index f182023..a9b8f96 100644 --- a/main.go +++ b/main.go @@ -315,7 +315,7 @@ 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 + } else if base == "Makefile" || base == "makefile" || strings.HasSuffix(base, ".mk") { // handle various make files lic, err = executeTemplate(tmpl, data, "", "# ", "") } } @@ -376,7 +376,7 @@ 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("mozilla public")) || bytes.Contains(bytes.ToLower(b[:n]), []byte("spdx-license-identifier")) } From c942ac3470c91c2af22193af68c1423fcb25af7d Mon Sep 17 00:00:00 2001 From: Zhou Zaihang Date: Sat, 7 Oct 2023 14:47:30 +0800 Subject: [PATCH 4/6] fix: the issue of check hasLicense --- main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.go b/main.go index a9b8f96..018adba 100644 --- a/main.go +++ b/main.go @@ -377,6 +377,8 @@ func hasLicense(b []byte) bool { n = len(b) } 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("mozilla public")) || bytes.Contains(bytes.ToLower(b[:n]), []byte("spdx-license-identifier")) } From a459904d176c920171eeec0b3b04ccecfad68f63 Mon Sep 17 00:00:00 2001 From: Zhou Zaihang Date: Sat, 7 Oct 2023 14:55:06 +0800 Subject: [PATCH 5/6] fix: the issue of hasLicense --- main.go | 1 + main_test.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/main.go b/main.go index 018adba..93e502e 100644 --- a/main.go +++ b/main.go @@ -377,6 +377,7 @@ func hasLicense(b []byte) bool { n = len(b) } 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("mozilla public")) || diff --git a/main_test.go b/main_test.go index 890ff5d..868be31 100644 --- a/main_test.go +++ b/main_test.go @@ -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}, From 21343c7252e3c4bd0acecdddd8886c62ab718067 Mon Sep 17 00:00:00 2001 From: Zhou Zaihang Date: Mon, 9 Oct 2023 14:41:43 +0800 Subject: [PATCH 6/6] fix: issue of "* Copyright" --- main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main.go b/main.go index 93e502e..5b7081f 100644 --- a/main.go +++ b/main.go @@ -380,6 +380,7 @@ func hasLicense(b []byte) bool { 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")) }