Skip to content

Commit

Permalink
Fix manifest workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi committed Jun 8, 2023
1 parent 35398b9 commit f2f77d1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/osd-increment-plugin-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
- warning
- debug
jobs:
osd-plugin-version-increment:
plugin-version-increment-sync:
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down
54 changes: 30 additions & 24 deletions src/manifests_workflow/input_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ def cron_jenkinsfile(self) -> str:
return os.path.join(self.jenkins_path(), "check-for-build.jenkinsfile")

@classmethod
def versionincrement_workflow(self) -> str:
return os.path.join(self.workflows_path(), "increment-plugin-versions.yml")
def os_versionincrement_workflow(self) -> str:
return os.path.join(self.workflows_path(), "os-increment-plugin-versions.yml")

@classmethod
def osd_versionincrement_workflow(self) -> str:
return os.path.join(self.workflows_path(), "osd-increment-plugin-versions.yml")

@classmethod
def files(self, name: str) -> List:
Expand Down Expand Up @@ -192,29 +196,31 @@ def add_to_cron(self, version: str) -> None:
logging.info(f"Wrote {jenkinsfile}")

def add_to_versionincrement_workflow(self, version: str) -> None:
versionincrement_workflow_file = self.versionincrement_workflow()
versionincrement_workflow_files = [self.os_versionincrement_workflow(), self.osd_versionincrement_workflow()]
yaml = ruamel.yaml.YAML()
yaml.explicit_start = True # type: ignore
yaml.preserve_quotes = True # type: ignore

with open(versionincrement_workflow_file) as f:
data = yaml.load(f)

version_entry = []
major_version_entry = version.split(".")[0] + ".x"
minor_version_entry = version.rsplit(".", 1)[0]
if minor_version_entry not in data["jobs"]["plugin-version-increment-sync"]["strategy"]["matrix"]["branch"]:
print(f"Adding {minor_version_entry} to {versionincrement_workflow_file}")
version_entry.append(minor_version_entry)
if major_version_entry not in data["jobs"]["plugin-version-increment-sync"]["strategy"]["matrix"]["branch"]:
print(f"Adding {major_version_entry} to {versionincrement_workflow_file}")
version_entry.append(major_version_entry)

if version_entry:
branch_list = list(data["jobs"]["plugin-version-increment-sync"]["strategy"]["matrix"]["branch"])
branch_list.extend(version_entry)
data["jobs"]["plugin-version-increment-sync"]["strategy"]["matrix"]["branch"] = branch_list
yaml.indent(mapping=2, sequence=4, offset=2)
with open(versionincrement_workflow_file, 'w') as f:
yaml.dump(data, f)
logging.info("Added new version to the version increment workflow")
for workflow_file in versionincrement_workflow_files:

with open(workflow_file) as f:
data = yaml.load(f)

version_entry = []
major_version_entry = version.split(".")[0] + ".x"
minor_version_entry = version.rsplit(".", 1)[0]
if minor_version_entry not in data["jobs"]["plugin-version-increment-sync"]["strategy"]["matrix"]["branch"]:
print(f"Adding {minor_version_entry} to {workflow_file}")
version_entry.append(minor_version_entry)
if major_version_entry not in data["jobs"]["plugin-version-increment-sync"]["strategy"]["matrix"]["branch"]:
print(f"Adding {major_version_entry} to {workflow_file}")
version_entry.append(major_version_entry)

if version_entry:
branch_list = list(data["jobs"]["plugin-version-increment-sync"]["strategy"]["matrix"]["branch"])
branch_list.extend(version_entry)
data["jobs"]["plugin-version-increment-sync"]["strategy"]["matrix"]["branch"] = branch_list
yaml.indent(mapping=2, sequence=4, offset=2)
with open(workflow_file, 'w') as f:
yaml.dump(data, f)
logging.info("Added new version to the version increment workflow")
21 changes: 14 additions & 7 deletions tests/tests_manifests_workflow/test_input_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import os
import unittest
from typing import Any
from unittest.mock import MagicMock, call, mock_open, patch

from manifests_workflow.input_manifests import InputManifests
Expand Down Expand Up @@ -129,17 +128,25 @@ def test_add_to_cron(self, mock_open: MagicMock) -> None:
f"TARGET_JOB_NAME=distribution-build-test;BUILD_PLATFORM=linux;BUILD_DISTRIBUTION=tar\n"
)

def test_versionincrement_workflow(self) -> None:
def test_os_versionincrement_workflow(self) -> None:
self.assertEqual(
InputManifests.versionincrement_workflow(),
os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", ".github", "workflows", "increment-plugin-versions.yml"))
InputManifests.os_versionincrement_workflow(),
os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", ".github", "workflows", "os-increment-plugin-versions.yml"))
)
self.assertTrue(os.path.exists(InputManifests.os_versionincrement_workflow()))

def test_osd_versionincrement_workflow(self) -> None:
self.assertEqual(
InputManifests.osd_versionincrement_workflow(),
os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", ".github", "workflows", "osd-increment-plugin-versions.yml"))
)
self.assertTrue(os.path.exists(InputManifests.osd_versionincrement_workflow()))

@patch("builtins.open", new_callable=mock_open)
@patch("manifests_workflow.input_manifests.InputManifests.add_to_versionincrement_workflow")
def test_add_to_versionincrement_workflow(self, *mocks: Any) -> None:
def test_add_to_versionincrement_workflow(self, mock_add_to_versionincrement_workflow: MagicMock) -> None:
input_manifests = InputManifests("test")
input_manifests.add_to_versionincrement_workflow('0.1.2')
input_manifests.add_to_versionincrement_workflow('1.0.0')
mock_add_to_versionincrement_workflow.assert_called_with("1.0.0")

def test_create_manifest_with_components(self) -> None:
pass

0 comments on commit f2f77d1

Please sign in to comment.