Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tool): fix addlicense #143

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/dev_auto-pr-author-assign.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2024 Flant JSC
#
# 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.

# .github/workflows/auto-author-assign.yml
name: Auto Author Assign

Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/dev_build_precache.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2024 Flant JSC
#
# 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: Build main, pre-alpha every 8 hours for dev
env:
MODULES_REGISTRY: ${{ vars.DEV_REGISTRY }}
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/dev_module_build-and-registration.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2024 Flant JSC
#
# 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: Deploy Dev

env:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/dev_module_build-on-self-hosted-runner.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2024 Flant JSC
#
# 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: Build and push for dev (Self-hosted)

env:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/dev_module_build.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2024 Flant JSC
#
# 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: Build and push for dev

env:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/dev_registry-cleanup.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2024 Flant JSC
#
# 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: Cleanup dev registries

env:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/release_module_build-and-registration.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2024 Flant JSC
#
# 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: Build and push for prod

env:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/release_module_release-channels.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2024 Flant JSC
#
# 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: Deploy Prod

env:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/release_release-please.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2024 Flant JSC
#
# 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: Release please

on:
Expand Down
72 changes: 72 additions & 0 deletions tools/addlicense/addlicense_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,75 @@ print("Hello")
})
}
}

func Test_FilesPathWithExtensionRe(t *testing.T) {
filePathCases := []struct {
title string
filePath string
}{
{
title: "Path .github with yaml extension",
filePath: "./.github/workflows/build.yaml",
},
{
title: "Path with /some/folder/.github yaml extension",
filePath: "/some/folder/.github/workflows/build.yaml",
},
{
title: "Path with ./.github yml extension",
filePath: "./.github/workflows/build.yml",
},
{
title: "Path with sh extension",
filePath: "./run.sh",
},
{
title: "Path with py extension",
filePath: "./scripts/run.py",
},
{
title: "Path with go extension",
filePath: "./cmds/run.go",
},
}

for _, c := range filePathCases {
t.Run(c.title, func(t *testing.T) {
resFilePathMatch := fileToCheckRe.MatchString(c.filePath)
require.True(t, resFilePathMatch)

// Copyright is maintained for files with an extension
license := getLicenseForFile(c.filePath)
require.NotEmpty(t, license)
require.True(t, CELicenseRe.MatchString(license))
})
}
}

func Test_FilesPathNoExtensionRe(t *testing.T) {
filePathCases := []struct {
title string
filePath string
}{
{
title: "Path with no extension",
filePath: "./cmds/enable",
},
{
title: "Path with no extension root dir",
filePath: "/enable",
},
}

for _, c := range filePathCases {
t.Run(c.title, func(t *testing.T) {
resFilePathMatch := fileToCheckRe.MatchString(c.filePath)
require.True(t, resFilePathMatch)

// Copyright is not maintained for files without an extension
license := getLicenseForFile(c.filePath)
require.Empty(t, license)
require.False(t, CELicenseRe.MatchString(license))
})
}
}
2 changes: 1 addition & 1 deletion tools/addlicense/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func getLicenseForFile(filePath string) string {
switch filepath.Ext(filePath) {
case ".go":
return goLicense
case ".py", ".sh", ".bash", ".zsh":
case ".py", ".sh", ".bash", ".zsh", ".yaml", ".yml":
return bashPythonLicense
default:
return ""
Expand Down
2 changes: 1 addition & 1 deletion tools/addlicense/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
// - Ends with .go, .sh, .py
// - Is inside a .github directory: scripts, workflows, or workflow_templates subdirectories,
// and ends with .js, .yml, .yaml, or .sh
var fileToCheckRe = regexp.MustCompile(`\.go$|/[^/.]+$|\.sh$|\.py$|^\.github/(scripts|workflows|workflow_templates)/.+\.(js|yml|yaml|sh)$`)
var fileToCheckRe = regexp.MustCompile(`\.go$|/[^/.]+$|\.sh$|\.py$|\.github/(scripts|workflows|workflow_templates)/.+\.(js|yml|yaml|sh)$`)

// fileToSkipRe matches filenames that will be skipped for adding license, meet the following conditions:
// - Directories .github/CODEOWNERS, /docs/
Expand Down
Loading