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
Sep 30, 2024
1 parent
b9df724
commit cb5a1ee
Showing
7 changed files
with
204 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# 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/>. | ||
from cfgnet.plugins.file_type.yaml_plugin import YAMLPlugin | ||
from cfgnet.config_types.config_types import ConfigType | ||
|
||
|
||
class CircleCiPlugin(YAMLPlugin): | ||
def __init__(self): | ||
super().__init__("circleci") | ||
|
||
def is_responsible(self, abs_file_path): | ||
return abs_file_path.endswith(".circleci/config.yml") | ||
|
||
# pylint: disable=too-many-return-statements | ||
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 ("command", "run", "shell", "entrypoint"): | ||
return ConfigType.COMMAND | ||
|
||
if option_name == "image": | ||
return ConfigType.IMAGE | ||
|
||
if option_name in ("parallelism"): | ||
return ConfigType.NUMBER | ||
|
||
if option_name in ( | ||
"at", | ||
"working_directory", | ||
"path", | ||
"paths", | ||
"destination", | ||
): | ||
return ConfigType.PATH | ||
|
||
if option_name in ("name", "resource_class"): | ||
return ConfigType.NAME | ||
|
||
if option_name == "user": | ||
return ConfigType.USERNAME | ||
|
||
if option_name == "environment": | ||
return ConfigType.ENVIRONMENT | ||
|
||
if option_name in ("xcode", "version"): | ||
return ConfigType.VERSION_NUMBER | ||
|
||
if option_name in ("docker_layer_caching", "background"): | ||
return ConfigType.BOOLEAN | ||
|
||
if option_name in ("no_output_timeout"): | ||
return ConfigType.TIME | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# 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.circleci_plugin import CircleCiPlugin | ||
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 = CircleCiPlugin() | ||
return plugin | ||
|
||
|
||
def test_is_responsible(get_plugin): | ||
plugin = get_plugin | ||
circle_file = os.path.abspath("tests/files/.circleci/config.yml") | ||
no_circle_file = os.path.abspath("tests/files/config.yml") | ||
|
||
circle_file = plugin.is_responsible(circle_file) | ||
no_circle_file = plugin.is_responsible(no_circle_file) | ||
|
||
assert circle_file | ||
assert not no_circle_file | ||
|
||
|
||
def test_parse_circle_file(get_plugin): | ||
plugin = get_plugin | ||
circle_file = os.path.abspath("tests/files/.circleci/config.yml") | ||
|
||
artifact = plugin.parse_file(circle_file, "config.yml") | ||
nodes = artifact.get_nodes() | ||
ids = {node.id for node in nodes} | ||
|
||
for id in ids: | ||
print(id) | ||
|
||
assert artifact is not None | ||
assert len(nodes) == 16 | ||
|
||
assert make_id("config.yml", "file", "config.yml") in ids | ||
assert make_id("config.yml", "jobs", "build", "docker", "offset:0", "image", "circleci/node:14") in ids | ||
assert make_id("config.yml", "jobs", "build", "steps", "checkout") in ids | ||
assert make_id("config.yml", "jobs", "build", "steps", "offset:0", "run", "name", "Install dependencies") in ids | ||
assert make_id("config.yml", "jobs", "build", "steps", "offset:0", "run", "command", "npm install") in ids | ||
assert make_id("config.yml", "jobs", "build", "steps", "offset:1", "persist_to_workspace", "root", ".") in ids | ||
assert make_id("config.yml", "jobs", "build", "steps", "offset:1", "persist_to_workspace", "paths", "dist") in ids | ||
assert make_id("config.yml", "jobs", "build", "steps", "offset:1", "persist_to_workspace", "paths", "src") in ids | ||
assert make_id("config.yml", "jobs", "deploy", "docker", "offset:0", "image", "circleci/node:14") in ids | ||
assert make_id("config.yml", "jobs", "deploy", "steps", "offset:0", "attach_workspace", "at", "/workspace") in ids | ||
assert make_id("config.yml", "jobs", "deploy", "steps", "offset:1", "run", "name", "Deploy application") in ids | ||
assert make_id("config.yml", "jobs", "deploy", "steps", "offset:1", "run", "command", 'echo "Deploying application..."') in ids | ||
assert make_id("config.yml", "workflows", "version", "2") in ids | ||
assert make_id("config.yml", "workflows", "build_and_deploy", "jobs", "build") in ids | ||
assert make_id("config.yml", "workflows", "build_and_deploy", "jobs", "offset:0", "deploy", "requires", "build") in ids | ||
|
||
|
||
def test_config_types(get_plugin): | ||
plugin = get_plugin | ||
file = os.path.abspath("tests/files/.circleci/config.yml") | ||
|
||
artifact = plugin.parse_file(file, "config.yml") | ||
nodes = artifact.get_nodes() | ||
|
||
version_node = next(filter(lambda x: x.id == make_id("config.yml", "workflows", "version", "2"), nodes)) | ||
command_node = next(filter(lambda x: x.id == make_id("config.yml", "jobs", "build", "steps", "offset:0", "run", "command", "npm install"), nodes)) | ||
path_node = next(filter(lambda x: x.id == make_id("config.yml", "jobs", "deploy", "steps", "offset:0", "attach_workspace", "at", "/workspace"), nodes)) | ||
image_node = next(filter(lambda x: x.id == make_id("config.yml", "jobs", "build", "docker", "offset:0", "image", "circleci/node:14"), nodes)) | ||
|
||
assert version_node.config_type == ConfigType.VERSION_NUMBER | ||
assert command_node.config_type == ConfigType.COMMAND | ||
assert path_node.config_type == ConfigType.PATH | ||
assert image_node.config_type == ConfigType.IMAGE |
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,37 @@ | ||
version: 2.1 | ||
|
||
jobs: | ||
build: | ||
docker: | ||
- image: circleci/node:14 | ||
steps: | ||
- checkout | ||
|
||
- run: | ||
name: Install dependencies | ||
command: npm install | ||
|
||
- persist_to_workspace: | ||
root: . | ||
paths: | ||
- dist | ||
- src | ||
|
||
deploy: | ||
docker: | ||
- image: circleci/node:14 | ||
steps: | ||
- attach_workspace: | ||
at: /workspace | ||
- run: | ||
name: Deploy application | ||
command: echo "Deploying application..." # Add your deployment commands here | ||
|
||
workflows: | ||
version: 2 | ||
build_and_deploy: | ||
jobs: | ||
- build | ||
- deploy: | ||
requires: | ||
- build |