Skip to content

Commit

Permalink
Refactor, CI: automatic license check, add missing licenses (bloomber…
Browse files Browse the repository at this point in the history
…g#330)

Signed-off-by: Evgeny Malygin <emalygin@bloomberg.net>
  • Loading branch information
678098 authored and alexander-e1off committed Oct 24, 2024
1 parent 4c957ab commit 8d2b9c7
Show file tree
Hide file tree
Showing 71 changed files with 1,147 additions and 7 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/ext/check_license.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

"""
Script for checking license header in C++/Python sources.
Usage:
python3 check_license.py [--path PATH]
optional arguments:
--path PATH to the directory containing sources to check
"""
import argparse
import glob
from pathlib import Path
import re


def load_license_template(path: str) -> list[re.Pattern]:
with open(path, "r") as f:
lines = f.readlines()

return [re.compile(line) for line in lines]


def check_license(fpath: str, expressions: list[re.Pattern]) -> bool:
with open(fpath, "r") as f:
ln = f.readline()
if ln.startswith("#!"): # skip possible shebang at the beginning of the file
ln = f.readline()

for expr in expressions:
if not expr.match(ln):
print(f"{fpath}:")
print(ln)
print("")
return False
ln = f.readline()
return True


def main() -> None:
parser = argparse.ArgumentParser(
prog=f"python3 -m {check_license.__name__}",
description="License checker",
)

parser.add_argument(
"--path",
default=".",
type=str,
action="store",
metavar="PATH",
help="PATH to the directory containing sources to check",
)

args = parser.parse_args()

checks = {
"*.cpp": "cxx_license_template.txt",
"*.h": "cxx_license_template.txt",
"*.c": "cxx_license_template.txt",
"*.hpp": "cxx_license_template.txt",
"*.py": "python_license_template.txt",
}

script_dir = Path(__file__).absolute().parent

for ext, template in checks.items():
fpaths = glob.glob(args.path + "/**/" + ext, recursive=True)
fpaths.sort()
if len(fpaths) == 0:
continue

expressions = load_license_template(script_dir.joinpath(template))
for fpath in fpaths:
check_license(fpath, expressions)


if __name__ == "__main__":
main()
14 changes: 14 additions & 0 deletions .github/workflows/ext/cxx_license_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright [\d-]+ Bloomberg Finance L.P.
// SPDX-License-Identifier: Apache-2.0
//
// 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.
14 changes: 14 additions & 0 deletions .github/workflows/ext/python_license_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright [\d-]+ Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.
23 changes: 23 additions & 0 deletions .github/workflows/license-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: License check

on:
pull_request:
types:
- "opened"
- "reopened"
- "synchronize"
- "labeled"
- "unlabeled"

jobs:
license_check:
runs-on: ubuntu-latest
name: License Check
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: license check
run: |
python3 ${{ github.workspace }}/.github/workflows/ext/check_license.py --path=${{ github.workspace }} | tee missing_licenses.txt
if [ -s missing_licenses.txt ]; then exit 1; fi
8 changes: 4 additions & 4 deletions src/groups/mqb/mqbc/mqbc_clusterdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// 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.
// 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.

// mqbc_clusterdata.cpp -*-C++-*-
#include <mqbc_clusterdata.h>
Expand Down
14 changes: 14 additions & 0 deletions src/integration-tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.
15 changes: 15 additions & 0 deletions src/integration-tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

import contextlib
import logging
import pytest
Expand Down
15 changes: 15 additions & 0 deletions src/integration-tests/test_admin_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

"""
This suite of test cases exercises admin session connection and some basic
commands.
Expand Down
15 changes: 15 additions & 0 deletions src/integration-tests/test_alarms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

"""
Testing broker ALARMS.
"""
Expand Down
15 changes: 15 additions & 0 deletions src/integration-tests/test_appids.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

import time
from typing import List

Expand Down
15 changes: 15 additions & 0 deletions src/integration-tests/test_auto_subscriptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

import blazingmq.dev.it.testconstants as tc
import pytest

Expand Down
15 changes: 15 additions & 0 deletions src/integration-tests/test_breathing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

"""
This test suite exercises basic routing functionality to in the presence of all
types of queues.
Expand Down
15 changes: 15 additions & 0 deletions src/integration-tests/test_broadcast.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

from itertools import islice

import blazingmq.dev.it.testconstants as tc
Expand Down
15 changes: 15 additions & 0 deletions src/integration-tests/test_cluster_node_shutdown.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

"""
Integration test that shuts down a cluster node and confirms that the system
recovers and keeps working as expected. For detailed documentation and diagrams
Expand Down
15 changes: 15 additions & 0 deletions src/integration-tests/test_compression.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

"""
Integration test that tests the successful sending and receiving of compressed
payload in various scenarios as listed below:
Expand Down
15 changes: 15 additions & 0 deletions src/integration-tests/test_confirm_after_killing_primary.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

"""
This test case verifies fix for the broker crash when virtual iterator goes
out of sync while processing CONFIRM after converting priority queue to
Expand Down
15 changes: 15 additions & 0 deletions src/integration-tests/test_confirms_buffering.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2024 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

import blazingmq.dev.it.testconstants as tc
from blazingmq.dev.it.fixtures import ( # pylint: disable=unused-import
Cluster,
Expand Down
Loading

0 comments on commit 8d2b9c7

Please sign in to comment.