Skip to content

Commit

Permalink
Version command can now track and bump Helm Chart.yaml values
Browse files Browse the repository at this point in the history
  • Loading branch information
aabmets committed Jan 11, 2024
1 parent 787a11b commit 3220113
Show file tree
Hide file tree
Showing 8 changed files with 538 additions and 411 deletions.
9 changes: 5 additions & 4 deletions .devtools
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
"file_name": "mit.json"
},
"version_cmd": {
"app_version": "0.12.1",
"app_version": "0.12.2",
"track_descriptor": true,
"track_chart": true,
"components": [
{
"name": "cli",
"target": ".",
"ignore": [],
"hash": "178d00633e782f0aa99cd165e26f7141"
"hash": "c294eca256b2d04c6c1893c57d9cd8e0"
}
],
"only_config": false
]
}
}
53 changes: 41 additions & 12 deletions .github/workflows/test-build-publish.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,53 @@
name: CI/CD Workflow
name: PyPI Publish Pipeline

on:
push:
branches:
- main

jobs:
test-and-publish:
build:
runs-on: ubuntu-latest
environment: release

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Run commands
run: |
pip install poetry
poetry install
poetry run pytest
poetry build
- name: Upload built package
uses: actions/upload-artifact@v4
with:
name: pypi-package
path: dist

publish:
needs: build
runs-on: ubuntu-latest

environment:
name: release
url: https://pypi.org/project/devtools-cli/

permissions:
id-token: write

steps:
- uses: actions/checkout@v3
- run: pip install poetry
- run: poetry install --with dev
- run: poetry run pytest
- run: poetry build
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Download package artifact
uses: actions/download-artifact@v4
with:
name: pypi-package
path: dist

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ cython_debug/
.idea/

# Non-versioned code
.no-vcs/
.exclude/
35 changes: 34 additions & 1 deletion devtools_cli/commands/version/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#
# SPDX-License-Identifier: MIT
#
import yaml
import hashlib
from pathlib import Path
from devtools_cli.utils import *
Expand All @@ -21,7 +22,9 @@
"digest_directory",
"count_descriptors",
"read_descriptor_file_version",
"write_descriptor_file_version"
"write_descriptor_file_version",
"read_chart_and_app_version",
"write_chart_and_app_version"
]

DIGEST_LENGTH = 32
Expand Down Expand Up @@ -97,3 +100,33 @@ def write_descriptor_file_version(new_version: str) -> None:
path = config_file.parent / file
if path.exists() and path.is_file():
func('write', path, new_version)


def read_chart_and_app_version() -> tuple:
config_file = find_local_config_file(init_cwd=True)
chart_path = config_file.parent / 'chart/Chart.yaml'
if chart_path.exists() and chart_path.is_file():
with open(chart_path, 'r') as file:
chart_yaml = yaml.safe_load(file)
chart_version = chart_yaml.get('version', '0.0.0')
app_version = chart_yaml.get('appVersion', '0.0.0')
return chart_version, app_version
return '0.0.0', '0.0.0'


def write_chart_and_app_version(new_version: str) -> None:
config_file = find_local_config_file(init_cwd=True)
chart_path = config_file.parent / 'chart/Chart.yaml'

if chart_path.exists() and chart_path.is_file():
with open(chart_path, 'r') as file:
lines = file.readlines()

with open(chart_path, 'w') as file:
for line in lines:
if line.strip().startswith('version:'):
file.write(f'version: {new_version}\n')
elif line.strip().startswith('appVersion:'):
file.write(f'appVersion: {new_version}\n')
else:
file.write(line)
Loading

0 comments on commit 3220113

Please sign in to comment.