Skip to content

Commit

Permalink
chore(ci): fix tool addlicense (#146)
Browse files Browse the repository at this point in the history
* chore: fix regexp for path .github and add licence for github/workflows
---------

Signed-off-by: Nikita Korolev <[email protected]>
  • Loading branch information
universal-itengineer authored Jun 20, 2024
1 parent 57eccea commit 0f70234
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 2 deletions.
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

0 comments on commit 0f70234

Please sign in to comment.