-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement new versioning methodology (#5060)
* change code stage * change revision number * add commit property * add test * add script tags * Update tag.py script to support multiple platforms * Add prebuild task to Makefile Co-authored-by: Alex Ruiz Becerra <[email protected]>
- Loading branch information
1 parent
5e7e61b
commit 128a487
Showing
4 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Generate tags for a release automatically. | ||
# Update the tag.py file before running this script. | ||
|
||
prebuild: | ||
@echo "- Updating project's versions ..." | ||
@node scripts/generate-build-version | ||
|
||
tags: prebuild | ||
@echo "- Generating Git tags ..." | ||
@python3 scripts/tag.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import packageValue from '../package.json'; | ||
|
||
const isNaN = (currentValue: string) => Number.isNaN(Number(currentValue)); | ||
|
||
describe('package.json version', () => { | ||
it('should have a version', () => { | ||
expect(packageValue.version).toBeDefined(); | ||
}); | ||
it("Wazuh's revision should be to follow the major.minor.patch.pattern.", () => { | ||
const versionSplit = packageValue.version.split('.'); | ||
|
||
const versionIsNaN = versionSplit.every(isNaN); | ||
|
||
expect(versionSplit.length).toBe(3); | ||
expect(versionIsNaN).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('package.json revison', () => { | ||
it('should have a revison', () => { | ||
expect(packageValue.revision).toBeDefined(); | ||
}); | ||
it('the revision should be a 2 digit number.', () => { | ||
const revision = packageValue.revision; | ||
|
||
const revisionIsNaN = isNaN(revision); | ||
|
||
expect(revision.length).toBe(2); | ||
expect(revisionIsNaN).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('package.json stage', () => { | ||
it('should have a stage', () => { | ||
expect(packageValue.stage).toBeDefined(); | ||
}); | ||
it('the state should be one of the defined.', () => { | ||
const stateDefined = [ | ||
'pre-alpha', | ||
'alpha', | ||
'beta', | ||
'release-candidate', | ||
'stable', | ||
]; | ||
|
||
const stage = packageValue.stage; | ||
|
||
expect(stateDefined).toContain(stage); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import json | ||
import logging | ||
import os | ||
import subprocess | ||
|
||
# ==================== CONFIGURATION ==================== # | ||
# Values to modify: | ||
# - version | ||
# - revision | ||
# - stage | ||
# - supported_versions & kbn_versions ONLY IF NEEDED (e.g. new Kibana version) | ||
# ======================================================= # | ||
|
||
# Wazuh version: major.minor.patch | ||
version = '4.4.0' | ||
# App's revision number (previous rev + 1) | ||
revision = '00' | ||
# One of 'pre-alpha', 'alpha', 'beta', 'release-candidate', 'stable' | ||
stage = 'alpha' | ||
|
||
# Global variable. Will be set later | ||
branch = None | ||
minor = ".".join(version.split('.')[:2]) | ||
|
||
# Supported versions of Kibana | ||
kbn_versions = [ | ||
[f'7.16.{x}' for x in range(0, 4)], | ||
[f'7.17.{x}' for x in range(0, 9)] | ||
] | ||
|
||
# Platforms versions | ||
supported_versions = { | ||
'OpenDistro': { | ||
'branch': f'{minor}-7.10', | ||
'versions': ['7.10.2'] | ||
}, | ||
'Kibana': { | ||
'branch': f'{minor}-7.16', | ||
# Flatten 2D list kbn_versions using lists comprehension | ||
'versions': [item for sublist in kbn_versions for item in sublist] | ||
}, | ||
'Wazuh Dashboard': { | ||
'branch': f'{minor}-2.4-wzd', | ||
'versions': ['2.4.1'] | ||
} | ||
} | ||
|
||
|
||
def get_git_revision_short_hash() -> str: | ||
return subprocess.check_output(['git', 'rev-parse', '--short', branch]).decode('ascii').strip() | ||
|
||
|
||
def update_package_json() -> tuple: | ||
logging.info(f'Updating package.json') | ||
data, success = {}, True | ||
|
||
# Read JSON and update keys. | ||
with open('package.json', 'r') as f: | ||
data, success = json.load(f), False | ||
|
||
# Update file | ||
data['commit'] = get_git_revision_short_hash() | ||
data['version'] = version | ||
data['revision'] = revision | ||
data['stage'] = stage | ||
|
||
with open('package.json', 'w') as f: | ||
json.dump(data, f, indent=2) | ||
|
||
return data, success | ||
|
||
|
||
def setup(): | ||
logging.info( | ||
f'Switching to branch "{branch}" and removing outdated tags...') | ||
os.system(f'git checkout {branch}') | ||
os.system('git fetch --prune --prune-tags') | ||
|
||
|
||
def main(platform: str, versions: list): | ||
for v in versions: | ||
tag = f'v{version}-{v}-{stage}' | ||
logging.info(f'Generating tag "{tag}"') | ||
update_package_json() | ||
os.system(f'git commit -am "Bump {tag}"') | ||
os.system( | ||
f'git tag -a {tag} -m "Wazuh {version} for {platform} {v}"') | ||
logging.info(f'Pushing tag "{tag}" to remote.') | ||
os.system(f'git push origin {tag}') | ||
# Undo latest commit | ||
os.system(f'git reset --hard origin/{branch}') | ||
# Save created tags to file | ||
os.system(f'git tag | grep -P -i "^v{version}-.*-{stage}" > tags.txt') | ||
|
||
|
||
if __name__ == '__main__': | ||
logging.basicConfig( | ||
filename='output.log', | ||
level=logging.INFO, | ||
format='%(asctime)s %(message)s' | ||
) | ||
logging.info( | ||
f'Wazuh version is "{version}". App revision is "{revision}". Stage is "{stage}"') | ||
|
||
for platform_name, platform_data in supported_versions.items(): | ||
branch, versions = platform_data['branch'], platform_data['versions'] | ||
setup() | ||
main(platform_name, versions) |