Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/renovate-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
onboarding: false,
platform: 'github',
repositories: [
'logchange/valhalla'
],
//allowPostUpgradeCommandTemplating: true,
//postUpgradeTasks: {
// commands: ['curl -sSL https://raw.githubusercontent.com/logchange/logchange/main/add_entry.sh | bash -s -- -DfileName=renovate-{{{depNameSanitized}}}-{{{newVersion}}}.yml -Dtitle="Upgraded {{{depName}}} from {{{currentVersion}}} to {{{newVersion}}}" -Dauthor=marwin1991 -Dtype=dependency_update -Dlink.name=notes -Dlink.url={{{url}}}'],
// commands: [
// 'install-tool maven 3.9.3',
// 'mvn dev.logchange:logchange-maven-plugin:add --non-recursive -DbatchMode -DfileName=renovate-{{{depNameSanitized}}}-{{{newVersion}}}.yml -Dtitle="Upgraded {{{depName}}} from {{{currentVersion}}} to {{{newVersion}}}" -Dauthor="logchange-bot;logchange-bot;team@logchange.dev" -Dtype=dependency_update -Dlink.name=notes -Dlink.url={{{url}}} || true'],
// fileFilters: ['**/*.yml'],
// executionMode: 'update',
//}
};
10 changes: 10 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
],
"assignees": [
"marwin1991",
"witx98"
]
}
7 changes: 6 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ jobs:
run: pip install -r requirements.txt

- name: Run tests
run: python -m unittest discover -s test -t test -p '*_test.py'
run: pytest --cov --cov-branch --cov-report=xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
24 changes: 24 additions & 0 deletions .github/workflows/renovate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Renovate

on:
workflow_dispatch:
schedule:
- cron: "0 7 * * *"

jobs:
renovate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Self-hosted Renovate
uses: renovatebot/github-action@v43.0.14
with:
token: ${{ secrets.LOGCHANGE_PAT_TOKEN }}
configurationFile: .github/renovate-config.js
renovate-version: full
env:
RENOVATE_ALLOWED_POST_UPGRADE_COMMANDS: ".*"
LOG_LEVEL: debug


18 changes: 18 additions & 0 deletions .junie/guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,22 @@
To run tests in this project, use the following command:
```bash
python -m unittest discover -s test -t test -p '*_test.py'
```

# Test template

When creating a new test, please use the following template:
```python
import unittest

class SomeClassTest(unittest.TestCase):

def test_some_method(self, mock_run):
# given:
...
# when:
...
# then:
...

```
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN apk --update --no-cache add \
npm && \
npm install -g pnpm

RUN wget https://github.com/logchange/logchange/releases/download/1.15.0/logchange-linuxx64.zip \
RUN wget https://github.com/logchange/logchange/releases/download/1.19.10/logchange-linuxx64.zip \
&& unzip logchange-linuxx64.zip \
&& mv bins/logchange-linuxx64/logchange /usr/local/bin/logchange \
&& chmod +x /usr/local/bin/logchange \
Expand Down
77 changes: 7 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

- [dockerhub](https://hub.docker.com/repository/docker/logchange/valhalla/)

## [Documentation](https://logchange.dev/tools/valhalla/)

Visit **[logchange.dev/tools/valhalla](https://logchange.dev/tools/valhalla/)** to read the full documentation, explore
usage examples, and learn how to get the most out of Valhalla.


### 📐 background and basic concept

- **complex releasing process:** Creating a new software release involves a multitude of intricate steps. This
Expand All @@ -25,76 +31,7 @@ saving time, and promoting compliance with established regulations.

### ⚙️ configuration

- create `valhalla.yml` in your project (check
out [examples](https://github.com/logchange/valhalla/tree/master/examples))

```yml
# This file is used by valhalla tool to create release 🌌
# Visit https://github.com/logchange/valhalla and leave a star 🌟
# 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

# 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]

# 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
msg: Releasing version {VERSION} # commit message, you can use string predefined variables
before: # list of bash commands, you can use string predefined variables, custom variables or system environment variables!
- 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
from_command: "cat changelog/v{VERSION}/version_summary.md"
milestones:
- M {VERSION_MAJOR}.{VERSION_MINOR}
- Main
assets: # https://docs.gitlab.com/ee/api/releases/#create-a-release
links:
- name: Documentation # you can use string predefined variables
url: https://google.com/q?={VERSION} # you can use string predefined variables
link_type: other # The type of the link: other, runbook, image, package.
- 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.

# 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
msg: Preparation for next development cycle
before:
- echo "test" > prepare_next_iteration.md

# define merge request from release breach to your default
# branch with changes from commit_before_release and commit_after_release
merge_request:
enabled: True # if this is True merge request will be created
target_branch: hotfix-{VERSION} # optional property (default branch if empty) defining target branch for merge/pull request. Supports regexp
title: Releasing version {VERSION} and preparation for next development cycle # you can use string predefined variables
description: Hello world! I have just released {VERSION} # optional filed, you can use string predefined variables
reviewers:
- peter.zmilczak # usernames which will be reviews of created MR
- some_unknown_nick # if username cannot be found you can check logs
```

- Create `valhalla.yml` in your project (check out [examples](https://github.com/logchange/valhalla/tree/master/examples)) (check out [reference](https://logchange.dev/tools/valhalla/reference/#basic-structure))
- Create access token and pass it to CI as environment variable `VALHALLA_TOKEN`
- Update or CI/CD scripts to use valhalla (see below for examples)
- Update your `.gitignore` ! see [link](#-gitignore)
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ PyYAML==6.0.3
GitPython==3.1.45
python-gitlab==6.4.0
requests==2.32.5
pytest==8.4.2
pytest-cov==7.0.0
12 changes: 6 additions & 6 deletions test/ci_provider/gitlab/get_version_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from unittest.mock import patch

from valhalla.ci_provider.gitlab.get_version import get_version_to_release
from valhalla.ci_provider.gitlab.get_version import get_version_to_release_from_branch_name
from valhalla.version.version_to_release import ReleaseKind


Expand All @@ -14,7 +14,7 @@ def test_release_branch(self, mock_env_get):
release_kinds = [ReleaseKind("valhalla.yml", "", ".")]

# when:
result = get_version_to_release(release_kinds)
result = get_version_to_release_from_branch_name(release_kinds)

# then:
self.assertEqual(result.version_number_to_release, '1.0.0')
Expand All @@ -29,7 +29,7 @@ def test_non_release_branch(self, mock_exit, mock_env_get):
release_kinds = [ReleaseKind("valhalla.yml", "", ".")]

# when:
result = get_version_to_release(release_kinds)
result = get_version_to_release_from_branch_name(release_kinds)

# then:
self.assertIsNone(result)
Expand All @@ -43,7 +43,7 @@ def test_no_ci_commit_branch(self, mock_exit, mock_env_get):
release_kinds = [ReleaseKind("valhalla.yml", "", ".")]

# when:
result = get_version_to_release(release_kinds)
result = get_version_to_release_from_branch_name(release_kinds)

# then:
self.assertIsNone(result)
Expand All @@ -57,7 +57,7 @@ def test_release_hotfix_branch(self, mock_env_get):
ReleaseKind("valhalla-hotfix.yml", "-hotfix", ".")]

# when:
result = get_version_to_release(release_kinds)
result = get_version_to_release_from_branch_name(release_kinds)

# then:
self.assertEqual(result.version_number_to_release, '1.2.3')
Expand All @@ -72,7 +72,7 @@ def test_no_matching_valhalla_branch(self, mock_exit, mock_env_get):
release_kinds = [ReleaseKind("valhalla-hotfix.yml", "-hotfix", ".")]

# when:
result = get_version_to_release(release_kinds)
result = get_version_to_release_from_branch_name(release_kinds)

# then:
self.assertIsNone(result)
Expand Down
33 changes: 27 additions & 6 deletions test/common/get_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ def test_get_config(self, mock_open_file):

mock_open_file.assert_called_once_with(self.config_path)

@patch(
"builtins.open",
new_callable=mock_open,
read_data="""
version:
from_command: "cat version.txt"
git_host: gitlab
release:
name: "Test Release Name"
""",
)
def test_get_version_config(self, mock_open_file):
config = get_config(self.config_path)

mock_open_file.assert_called_once_with(self.config_path)

self.assertIsNotNone(config.version_config)
self.assertEqual(config.version_config.from_command, "cat version.txt")

mock_open_file.assert_called_once_with(self.config_path)

@patch(
"builtins.open",
new_callable=mock_open,
Expand All @@ -76,10 +97,10 @@ def test_get_config_no_mr_section(self, mock_open_file):
mock_open_file.assert_called_once_with(self.config_path)

self.assertEqual(config.merge_request.enabled, False)
self.assertEqual(config.merge_request.target_branch, None)
self.assertEqual(config.merge_request.title, None)
self.assertEqual(config.merge_request.description, None)
self.assertEqual(config.merge_request.reviewers, None)
self.assertEqual(config.merge_request.target_branch, "")
self.assertEqual(config.merge_request.title, "")
self.assertEqual(config.merge_request.description, "")
self.assertEqual(config.merge_request.reviewers, [])

mock_open_file.assert_called_once_with(self.config_path)

Expand Down Expand Up @@ -123,7 +144,6 @@ def test_get_config_file_not_found(self, mock_open_file):
mock_open_file.assert_called_once_with(self.config_path)
self.assertEqual(context.exception.code, -1)


@patch(
"builtins.open",
new_callable=mock_open,
Expand All @@ -145,7 +165,8 @@ def test_get_release_config(self, mock_open_file):
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")
self.assertEqual(config.release_config.description_config.from_command,
"cat changelog/v{VERSION}/version_summary.md")

mock_open_file.assert_called_once_with(self.config_path)

Expand Down
24 changes: 24 additions & 0 deletions test/common/get_from_dict_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import unittest
from unittest.mock import patch

from valhalla.common.get_config import get_from_dict


class GetFromDictTest(unittest.TestCase):

@patch('valhalla.common.get_config.error')
def test_required_missing_raises(self, mock_error):
with self.assertRaises(RuntimeError) as ctx:
get_from_dict({}, 'git_host', True)
self.assertIn('Missing required git_host in valhalla.yml!', str(ctx.exception))
mock_error.assert_called() # ensure error was logged

@patch('valhalla.common.get_config.info')
def test_optional_missing_returns_none_and_logs(self, mock_info):
value = get_from_dict({}, 'optional_key', False)
self.assertIsNone(value)
mock_info.assert_called() # ensure info was logged


if __name__ == '__main__':
unittest.main()
53 changes: 53 additions & 0 deletions test/common/release_assets_links_parsing_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import unittest
from unittest.mock import mock_open, patch

from valhalla.common.get_config import get_config


class ReleaseAssetsLinksParsingTest(unittest.TestCase):

@patch(
'builtins.open',
new_callable=mock_open,
read_data='''
git_host: gitlab
release:
name: "Rel"
assets:
links:
- name: "Documentation"
url: "https://example.com/docs"
link_type: "doc"
- name: "Image"
url: "https://example.com/diagram.png"
link_type: "image"
'''
)
def test_parse_assets_links(self, mock_open_file):
cfg = get_config('valhalla.yml')
self.assertIsNotNone(cfg.release_config)
self.assertIsNotNone(cfg.release_config.assets_config)
links = cfg.release_config.assets_config.links
self.assertEqual(2, len(links))
self.assertEqual(('Documentation', 'https://example.com/docs', 'doc'),
(links[0].name, links[0].url, links[0].link_type))
self.assertEqual(('Image', 'https://example.com/diagram.png', 'image'),
(links[1].name, links[1].url, links[1].link_type))

@patch(
'builtins.open',
new_callable=mock_open,
read_data='''
git_host: gitlab
release:
name: "Rel"
assets: {}
'''
)
def test_assets_links_none(self, mock_open_file):
cfg = get_config('valhalla.yml')
self.assertEqual([], cfg.release_config.assets_config.links)


if __name__ == '__main__':
unittest.main()
Loading