Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Update build output with versions #40

Merged
merged 2 commits into from
Oct 8, 2020
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
3 changes: 1 addition & 2 deletions .python-version
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
3.7.4
2.7.18
3.7.8
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ splunk-add-on-ucc-framework supports the following params:
|------------|----------------------------------------------------------------------------------------------------------|
| source | Folder containing the app.manifest and app source |
| config | Path to the configuration file, Defaults to GlobalConfig.json in the parent directory of source provided |
| ta-version | Current version of TA, Default version is version specified in globalConfig.json |
| ta-version | Optional override Current version of TA, Default version is version specified in globalConfig.json a Splunkbase compatible version of SEMVER will be used by default |
27 changes: 13 additions & 14 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ lxml = "^4.3"
future = "^0"
splunktaucclib = "^4.0"
wheel = "*"
dunamai = "*"

[tool.poetry.dev-dependencies]
pytest = "^5.4"
Expand Down
46 changes: 0 additions & 46 deletions script/packagingScript.sh

This file was deleted.

56 changes: 54 additions & 2 deletions splunk_add_on_ucc_framework/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__version__ = "0.0.0"

import logging
import os
import os, time
import glob
from os import system
import shutil
Expand All @@ -16,6 +16,8 @@
from .start_alert_build import alert_build

from jinja2 import Environment, FileSystemLoader
from dunamai import Version, Style
import configparser

outputdir = os.path.join(os.getcwd(), "output")
sourcedir = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -473,10 +475,20 @@ def main():
help="Path to configuration file, Defaults to GlobalConfig.json in parent directory of source provided",
default=None
)
version = Version.from_git()
if not version.stage:
stage = 'R'
else:
stage = version.stage[:1]

version_str = version.serialize(metadata=True)
version_splunk = f"{version.base}-{stage}{version.commit}"

parser.add_argument(
"--ta-version",
type=str,
help="Version of TA, Deafult version is version specified in globalConfig.json",
help="Version of TA, Deafult version is version specified in the package such as app.manifest, app.conf, and globalConfig.json",
default = version_splunk
)
args = parser.parse_args()

Expand Down Expand Up @@ -564,3 +576,43 @@ def main():
ignore_list = get_ignore_list(ta_name, os.path.abspath(os.path.join(args.source, PARENT_DIR, ".uccignore")))
remove_listed_files(ignore_list)
copy_package_source(args, ta_name)

#Update app.manifest
with open(os.path.join(outputdir, ta_name,'VERSION'), 'w') as version_file:
version_file.write(version_str)
version_file.write("\n")
version_file.write(version_splunk)


manifest= None
with open(os.path.abspath(os.path.join(outputdir, ta_name, "app.manifest")), "r") as manifest_file:
manifest = json.load(manifest_file)
manifest['info']['id']['version'] = version_splunk


with open(os.path.abspath(os.path.join(outputdir, ta_name, "app.manifest")), "w") as manifest_file:
manifest_file.write(json.dumps(manifest, indent=4, sort_keys=True))

app_config = configparser.ConfigParser()
app_config.read_file(open(os.path.join(outputdir, ta_name,'default', "app.conf")))
if not 'launcher' in app_config:
app_config.add_section('launcher')
if not 'id' in app_config:
app_config.add_section('id')
if not 'package' in app_config:
app_config.add_section('package')
if not 'ui' in app_config:
app_config.add_section('ui')

app_config['launcher']['version']=version_splunk
app_config['launcher']['description']=manifest['info']['description']

app_config['id']['version']=version_splunk

app_config['package']['build']=str(int(time.time()))
app_config['package']['id']=manifest['info']['id']['name']

app_config['ui']['label']=manifest['info']['title']

with open(os.path.join(outputdir, ta_name,'default', "app.conf"), 'w') as configfile:
app_config.write(configfile)