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 f7e9dd3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 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
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
set -e

if [ -z "$1" ]; then (echo "syntax: run.sh [workflow.py]"; exit -1); fi
command -v python3 >/dev/null 2>&1 || (echo "missing python3"; exit -1)
command -v python >/dev/null 2>&1 || (echo "missing python3"; exit -1)
command -v pip >/dev/null 2>&1 || (echo "missing python3-pip"; exit -1)
command -v pipenv >/dev/null 2>&1 || (echo "missing pipenv"; exit -1)

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")
12 changes: 9 additions & 3 deletions tests/tests_manifests_workflow/test_input_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,16 @@ 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"))
)

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"))
)

@patch("builtins.open", new_callable=mock_open)
Expand Down

0 comments on commit f7e9dd3

Please sign in to comment.