Skip to content

Commit

Permalink
fixed tests, resolved predefined variables in release and tag name, u…
Browse files Browse the repository at this point in the history
…pdated README.md
  • Loading branch information
sl1 committed Nov 28, 2024
1 parent aac2a3a commit 42a4a04
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ saving time, and promoting compliance with established regulations.
# More info about configuration you can find https://github.com/logchange/valhalla#%EF%B8%8F-configuration ⬅️
extends: # You can extend any file from URL! This helps keep configuration in one place!
- https://raw.githubusercontent.com/logchange/valhalla/master/valhalla-extends.yml
variables: # Define custom variables which can be used in any string with {}

# Define custom variables which can be used in any string with {}
variables:
MY_VARIABLE: Some value
git_host: gitlab # your project ci provider, supported [gitlab]
commit_before_release: # define actions which have to happen before release and output should be committed

# define actions which have to happen before release and output should be committed
commit_before_release:
enabled: True # if this is True commands from before will be performed and committed to branch
username: Test1234 # git config username
email: test-valhalla@logchange.dev # git config email
Expand All @@ -46,8 +50,10 @@ commit_before_release: # define actions which have to happen before release and
- echo "test" > some_file4.md
- mkdir -p changelog/v{VERSION}
- echo "Super release description for tests generated at {CI_COMMIT_TIMESTAMP}" > changelog/v{VERSION}/version_summary.md

# definition of release which will be created
release:
name: "Release {VERSION}" # optional filed, you can use string predefined variables (default name is VERSION)
description:
# bash command with will be executed and output will be used as
# release description, you can use string predefined variables
Expand All @@ -63,7 +69,13 @@ release:
- name: Docker Image # you can use string predefined variables
url: https://dockerhub.com/q?={VERSION} # you can use string predefined variables
link_type: image # The type of the link: other, runbook, image, package.
commit_after_release: # define actions which have to happen after release and output should be committed

# definition of tag which will be created
tag:
name: "Tag {VERSION}" # optional filed, you can use string predefined variables (default name is VERSION)

# define actions which have to happen after release and output should be committed
commit_after_release:
enabled: True
username: Test1234
email: test-valhalla@logchange.dev
Expand Down
3 changes: 3 additions & 0 deletions examples/valhalla-gitlab-maven-logchange.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ commit_before_release:
- mvn dev.logchange:logchange-maven-plugin:release --non-recursive

release:
name: "Release name {VERSION}"
description:
from_command: "cat changelog/v{VERSION}/version-summary.md"
assets:
Expand All @@ -30,6 +31,8 @@ release:
url: https://registry.my/#browse/browse:docker:v2%2F{DOCKER_IMAGE_NAME}%2Ftags%2F{VERSION}
link_type: image

tag:
name: "Tag name {VERSION}"

commit_after_release:
enabled: True
Expand Down
20 changes: 11 additions & 9 deletions test/common/get_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def setUp(self):
- echo "test"
- echo "test2"
release:
name: "Test Release Name"
description:
from_command: "cat changelog/v{VERSION}/version_summary.md"
name: "Test Release Name
tag:
tag:
name: "Test Tag Name"
merge_request:
enabled: On
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_get_config_file_not_found(self, mock_open_file):
read_data="""
git_host: gitlab
release:
name: "Test Release Name"
name: "Test Release Name {VERSION}"
milestones:
- "Test Milestone"
description:
Expand All @@ -142,8 +142,8 @@ def test_get_release_config(self, mock_open_file):

mock_open_file.assert_called_once_with(self.config_path)

self.assertEqual(config.release_config, True)
self.assertEqual(config.release_config.name, "Test Release Name")
self.assertIsNotNone(config.release_config)
self.assertEqual(config.release_config.name, "Test Release Name {VERSION}")
self.assertEqual(config.release_config.milestones, ['Test Milestone'])
self.assertEqual(config.release_config.description_config.from_command, "cat changelog/v{VERSION}/version_summary.md")

Expand All @@ -155,18 +155,20 @@ def test_get_release_config(self, mock_open_file):
read_data="""
git_host: gitlab
release:
name: "Test Release Name"
name: "Test Release Name {VERSION}"
description:
from_command: "cat changelog/v{VERSION}/version_summary.md"
tag:
name: "Test Tag Name"
name: "Test Tag Name {VERSION}"
""",
)
def test_get_tag_config(self, mock_open_file):
config = get_config(self.config_path)

mock_open_file.assert_called_once_with(self.config_path)

self.assertEqual(config.tag_config, True)
self.assertEqual(config.tag_config.name, "Test Tag Name")
self.assertIsNotNone(config.tag_config)
self.assertEqual(config.tag_config.name, "Test Tag Name {VERSION}")

mock_open_file.assert_called_once_with(self.config_path)

Expand Down
6 changes: 4 additions & 2 deletions valhalla/common/get_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(self, name: str):
def __repr__(self):
return f"\n" \
f" TagConfig( \n" \
f" name={self.tag_name} \n" \
f" name={self.name} \n" \
f" )"


Expand Down Expand Up @@ -243,7 +243,9 @@ def get_release_assets_links_config_part(links_list_of_dicts: List[dict]) -> Lis

return result

def get_tag_config_part(tag_config_dict: dict) -> TagConfig:
def get_tag_config_part(tag_config_dict: dict) -> TagConfig | None:
if tag_config_dict is None:
return None
name = get_from_dict(tag_config_dict, 'name', False)

return TagConfig(name)
Expand Down
4 changes: 2 additions & 2 deletions valhalla/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ def create_release(config: Config, version_to_release: str):
milestones = []

if config.release_config.name is not None:
release_name = config.release_config.name
release_name = resolve(config.release_config.name)
else:
release_name = version_to_release

if config.tag_config.name is not None:
tag_name = config.tag_config.name
tag_name = resolve(config.tag_config.name)
else:
tag_name = version_to_release

Expand Down

0 comments on commit 42a4a04

Please sign in to comment.