Skip to content

Commit

Permalink
ci(github action): update branch of checking (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
nannan00 authored Nov 13, 2023
1 parent 9599701 commit 37aa03e
Show file tree
Hide file tree
Showing 11 changed files with 731 additions and 546 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/bk-login.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: bklogin_ci_check
on:
push:
branches: [ main, pre_*, ft_*, release/* ]
paths:
- "src/bk-login/**"
- "src/idp-plugins/**"
pull_request:
branches: [ main, pre_*, ft_*, release/* ]
paths:
- "src/bk-login/**"
- "src/idp-plugins/**"
jobs:
check:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: create idp plugin symbolic link
run: |
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-login/bklogin
- name: Format & Lint with ruff
run: |
pip install ruff==0.1.4
ruff format src/bk-login --config=src/bk-login/pyproject.toml
ruff src/bk-login --config=src/bk-login/pyproject.toml
- name: Lint with mypy
run: |
pip install mypy==1.6.1 types-requests==2.31.0.2 types-setuptools==57.4.18 types-dataclasses==0.1.7 types-redis==3.5.18 types-PyMySQL==1.1.0.1 types-six==0.1.9 types-toml==0.1.5 types-pytz==2023.3.0.0 types-urllib3==1.26.25.14
mypy src/bk-login --config-file=src/bk-login/pyproject.toml
test:
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Start MySQL Container
uses: samin/[email protected]
with:
mysql version: "8.0"
mysql database: bk-login
mysql user: root
mysql password: root_pwd
mysql root password: root_pwd
- name: Start Redis Container
uses: supercharge/[email protected]
with:
redis-version: "3.2.0"
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: create idp plugin symbolic link
run: |
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-login/bklogin
- name: Set up Poetry
uses: abatilo/[email protected]
with:
poetry-version: "1.6.1"
- name: Install dependencies
working-directory: src/bk-login
run: poetry install
- name: Run unittest
working-directory: src/bk-login
run: |
# random secret
export BK_APP_SECRET="fod6MKVTVi_3M5HgGoj-qI7b3l0dgCzTBwGypnDz4vg="
export BK_USER_APP_SECRET="Vi_3M5HgGogCzTBwGypnDz4vgfod6MKVTj-qI7b3l0d="
# random secret key
export BKKRILL_ENCRYPT_SECRET_KEY="tttHSBLiVdQPItrfy7n9dV7AxAUMZpYVkD6IHMbL0VE="
export BK_DOMAIN="example.com"
export BK_COMPONENT_API_URL=""
export MYSQL_PASSWORD=root_pwd
export MYSQL_HOST="127.0.0.1"
export DJANGO_SETTINGS_MODULE=bklogin.settings
poetry run pytest ./tests
14 changes: 4 additions & 10 deletions .github/workflows/bk-user.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: bkuser_ci_check
on:
push:
branches: [master, ft_tenant]
branches: [ main, pre_*, ft_*, release/* ]
paths:
- "src/bk-user/**"
- "src/idp-plugins/**"
pull_request:
branches: [master, ft_tenant]
branches: [ main, pre_*, ft_*, release/* ]
paths:
- "src/bk-user/**"
- "src/idp-plugins/**"
jobs:
check:
runs-on: ubuntu-latest
Expand All @@ -20,23 +22,16 @@ jobs:
python-version: "3.10"
- name: create idp plugin symbolic link
run: |
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-login/bklogin
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-user/bkuser
- name: Format & Lint with ruff
run: |
pip install ruff==0.1.4
ruff format src/bk-user --config=src/bk-user/pyproject.toml
ruff src/bk-user --config=src/bk-user/pyproject.toml
ruff format src/bk-login --config=src/bk-login/pyproject.toml
ruff src/bk-login --config=src/bk-login/pyproject.toml
ruff format src/idp-plugins --config=src/idp-plugins/pyproject.toml
ruff src/idp-plugins --config=src/idp-plugins/pyproject.toml
- name: Lint with mypy
run: |
pip install mypy==1.6.1 types-requests==2.31.0.2 types-setuptools==57.4.18 types-dataclasses==0.1.7 types-redis==3.5.18 types-PyMySQL==1.1.0.1 types-six==0.1.9 types-toml==0.1.5 types-pytz==2023.3.0.0 types-urllib3==1.26.25.14
mypy src/bk-user --config-file=src/bk-user/pyproject.toml
mypy src/bk-login --config-file=src/bk-login/pyproject.toml
mypy src/idp-plugins --config-file=src/idp-plugins/pyproject.toml
test:
strategy:
fail-fast: false
Expand All @@ -61,7 +56,6 @@ jobs:
python-version: "3.10"
- name: create idp plugin symbolic link
run: |
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-login/bklogin
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-user/bkuser
- name: Set up Poetry
uses: abatilo/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ name: "CodeQL"

on:
push:
branches: [ master, develop ]
branches: [ main, pre_*, ft_*, release/* ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master, develop ]
branches: [ main, pre_*, ft_*, release/* ]
schedule:
- cron: '22 11 * * 4'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: ESLint

on:
push:
branches: [ master, develop, pre_*, ft_* ]
branches: [ main, pre_*, ft_*, release/* ]
pull_request:
branches: [ master, develop, pre_*, ft_* ]
branches: [ main, pre_*, ft_*, release/* ]

jobs:
build:
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/idp-plugins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: idp_plugin_ci_check
on:
push:
branches: [ main, pre_*, ft_*, release/* ]
paths:
- "src/idp-plugins/**"
pull_request:
branches: [ main, pre_*, ft_*, release/* ]
paths:
- "src/idp-plugins/**"
jobs:
check:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Format & Lint with ruff
run: |
pip install ruff==0.1.4
ruff format src/idp-plugins --config=src/idp-plugins/pyproject.toml
ruff src/idp-plugins --config=src/idp-plugins/pyproject.toml
- name: Lint with mypy
run: |
pip install mypy==1.6.1 types-requests==2.31.0.2 types-setuptools==57.4.18 types-dataclasses==0.1.7 types-redis==3.5.18 types-PyMySQL==1.1.0.1 types-six==0.1.9 types-toml==0.1.5 types-pytz==2023.3.0.0 types-urllib3==1.26.25.14
mypy src/idp-plugins --config-file=src/idp-plugins/pyproject.toml
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ repos:
.*/poetry\.lock|
.*/pyproject\.toml|
\.github/workflows/bk-user.yml|
\.github/workflows/bk-login.yml|
\.github/workflows/idp-plugins.yml|
src/bk-user/logs|src/pages/node_modules/|
src/bk-login/pages/src/views/components/protocol.vue|
src/pages/static/bk_icon_font/iconcool.json|
Expand Down
2 changes: 1 addition & 1 deletion src/bk-login/bklogin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": env.str("MYSQL_NAME", "bk-user"),
"NAME": env.str("MYSQL_NAME", "bk-login"),
"USER": env.str("MYSQL_USER", "root"),
"PASSWORD": env.str("MYSQL_PASSWORD", ""),
"HOST": env.str("MYSQL_HOST", "localhost"),
Expand Down
10 changes: 10 additions & 0 deletions src/bk-login/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-用户管理(Bk-User) available.
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://opensource.org/licenses/MIT
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.
"""
76 changes: 76 additions & 0 deletions src/bk-login/tests/utils/test_std_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-用户管理(Bk-User) available.
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://opensource.org/licenses/MIT
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 pytest
from bklogin.utils.std_error import APIError, ErrorCode
from django.utils.translation import gettext_lazy


def _format_message(message, exc):
return f"{exc.code}-{message}"


class TestingErrorCodes:
foo_bar = ErrorCode("foo message", status_code=500)
foo_formatted = ErrorCode("foo message", extra_formatter=_format_message)


class TestErrorCode:
def test_integrated(self):
error_codes = TestingErrorCodes()
exc = error_codes.foo_bar

assert isinstance(exc, APIError)
assert exc.code == "foo_bar"
assert exc.status_code == 500 # noqa: PLR2004
assert exc.message == "foo message"

def test_formatted(self):
exc = TestingErrorCodes().foo_formatted
assert exc.message == "foo_formatted-foo message"

def test_exception_clone(self):
error_codes = TestingErrorCodes()
assert error_codes.foo_bar is not error_codes.foo_bar


class TestAPIError:
def test_simple_message(self):
exc = APIError("foo", "foo error", "INVALID_ARGUMENT")
assert exc.message == "foo error"
assert exc.code == "foo"

@pytest.mark.parametrize(
("message", "replace", "kwargs", "result"),
[
("", False, {}, "name={name}"),
("value", False, {}, "name={name}: value"),
("value", False, {"name": "foo"}, "name=foo: value"),
("value", True, {"name": "foo"}, "value"),
],
)
def test_message_format(self, message, replace, result, kwargs):
exc = APIError("foo", "name={name}")
exc = exc.format(message=message, replace=replace, **kwargs)
assert exc.message == result

def test_format_clone(self):
exc = APIError("foo", "message")
formatted_exc = exc.format()
assert formatted_exc is not exc

def test_data_property_in_chain(self):
exc = APIError("foo", "name={name}")
assert exc.set_data({"value": -1}).f(name="bar").data == {"value": -1}

def test_lazy_str(self):
exc = APIError("foo", gettext_lazy("message"))
formatted_exc = exc.format(gettext_lazy("new message"))
assert formatted_exc.message == "message: new message"
Loading

0 comments on commit 37aa03e

Please sign in to comment.