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

Implement new versioning methodology #5060

Merged
merged 8 commits into from
Jan 5, 2023
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
11 changes: 11 additions & 0 deletions Makefile
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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "wazuh",
"version": "4.4.0",
"revision": "4400",
"code": "4400",
"revision": "00",
"stage": "alpha",
"commit": "f4f8345",
"pluginPlatform": {
"version": "2.4.0"
},
Expand Down
50 changes: 50 additions & 0 deletions public/package.test.ts
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);
});
});
108 changes: 108 additions & 0 deletions scripts/tag.py
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)