generated from NicolaiRuckel/python-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sebastian Simon
committed
Oct 9, 2024
1 parent
a405148
commit 7e1a83d
Showing
9 changed files
with
176 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# This file is part of the CfgNet module. | ||
# | ||
# This program is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the Free Software | ||
# Foundation, either version 3 of the License, or (at your option) any later | ||
# version. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program. If not, see <https://www.gnu.org/licenses/>. | ||
import re | ||
from cfgnet.plugins.file_type.yaml_plugin import YAMLPlugin | ||
from cfgnet.config_types.config_types import ConfigType | ||
|
||
|
||
class GitHubActionPlugin(YAMLPlugin): | ||
file_name = re.compile(r".*?\.github\/workflows\/[^\/]*\.yml$") | ||
|
||
def __init__(self): | ||
super().__init__("github-action") | ||
|
||
def is_responsible(self, abs_file_path): | ||
if self.file_name.search(abs_file_path): | ||
return True | ||
return False | ||
|
||
def get_config_type(self, option_name: str) -> ConfigType: | ||
""" | ||
Find config type based on option name. | ||
:param option_name: name of option | ||
:return: config type | ||
""" | ||
if option_name in ("run"): | ||
return ConfigType.COMMAND | ||
|
||
if option_name in ("name", "uses"): | ||
return ConfigType.NAME | ||
|
||
if option_name in ("python-version"): | ||
return ConfigType.VERSION_NUMBER | ||
|
||
return ConfigType.UNKNOWN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# This file is part of the CfgNet module. | ||
# | ||
# This program is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the Free Software | ||
# Foundation, either version 3 of the License, or (at your option) any later | ||
# version. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
import os | ||
import pytest | ||
|
||
from cfgnet.plugins.concept.github_actions_plugin import GitHubActionPlugin | ||
from cfgnet.config_types.config_types import ConfigType | ||
from tests.utility.id_creator import make_id | ||
|
||
|
||
@pytest.fixture(name="get_plugin") | ||
def get_plugin_(): | ||
plugin = GitHubActionPlugin() | ||
return plugin | ||
|
||
|
||
def test_is_responsible(get_plugin): | ||
plugin = get_plugin | ||
|
||
assert plugin.is_responsible("tests/files/.github/workflows/ci.yml") | ||
assert not plugin.is_responsible("tests/files/test.yml") | ||
|
||
|
||
def test_config_types(get_plugin): | ||
plugin = get_plugin | ||
file_name = os.path.abspath("tests/files/.github/workflows/ci.yml") | ||
artifact = plugin.parse_file(file_name, "ci.yml") | ||
nodes = artifact.get_nodes() | ||
|
||
name_node = next(filter(lambda x: x.id == make_id("ci.yml", "name", "Code Quality"), nodes)) | ||
version_node = next(filter(lambda x: x.id == make_id("ci.yml", "jobs", "code_style", "steps", "with", "python-version", "3.9"), nodes)) | ||
command_node = next(filter(lambda x: x.id == make_id("ci.yml", "jobs", "code_style", "steps", "run", "poetry install"), nodes)) | ||
boolean_node = next(filter(lambda x: x.id == make_id("ci.yml", "jobs", "code_style", "steps", "with", "virtualenvs-create", "true"), nodes)) | ||
|
||
assert name_node.config_type == ConfigType.NAME | ||
assert version_node.config_type == ConfigType.VERSION_NUMBER | ||
assert command_node.config_type == ConfigType.COMMAND | ||
assert boolean_node.config_type == ConfigType.BOOLEAN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Code Quality | ||
|
||
on: [push] | ||
|
||
jobs: | ||
|
||
code_style: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
with: | ||
version: latest | ||
virtualenvs-create: true | ||
virtualenvs-in-project: true | ||
|
||
- name: Install Dependencies | ||
run: poetry install | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
|
||
- name: Run linters | ||
run: make linter |