From 06e39997aad16e48f589ad32867e8726b739b723 Mon Sep 17 00:00:00 2001 From: Chirayu Kapoor Date: Fri, 17 May 2024 15:50:52 +0530 Subject: [PATCH 1/2] refactor: Add unbuffer option to print python logs * Fixed issues in workflow python script * Implemented the use of semver * Removed format_version and get_max_version function * Removed unused variable and import statments Signed-off-by: Chirayu Kapoor --- .github/workflows/add_new_versions.yml | 4 +- workflow_scripts/check-for-new-versions.py | 1 - workflow_scripts/gen-new-version-files.py | 55 +++++----------------- workflow_scripts/requirements.txt | 1 + 4 files changed, 16 insertions(+), 45 deletions(-) diff --git a/.github/workflows/add_new_versions.yml b/.github/workflows/add_new_versions.yml index bca712ea..8d3f8f03 100644 --- a/.github/workflows/add_new_versions.yml +++ b/.github/workflows/add_new_versions.yml @@ -31,7 +31,7 @@ jobs: - name: Check if new versions available id: check-versions run: | - python workflow_scripts/check-for-new-versions.py + python -u workflow_scripts/check-for-new-versions.py env: EXCLUDED_VERSIONS: "v20.10.x,v23.0.x" @@ -54,7 +54,7 @@ jobs: env: NEW_VERSIONS: ${{ env.NEW_VERSIONS }} run: | - python workflow_scripts/gen-new-version-files.py + python -u workflow_scripts/gen-new-version-files.py - name: Create branch, commit and push if: ${{ env.pr_exist == 'false' && env.PR_TITLE != '' }} diff --git a/workflow_scripts/check-for-new-versions.py b/workflow_scripts/check-for-new-versions.py index 6c14ed0d..97a531d1 100644 --- a/workflow_scripts/check-for-new-versions.py +++ b/workflow_scripts/check-for-new-versions.py @@ -1,5 +1,4 @@ import os -import subprocess import requests # Constants diff --git a/workflow_scripts/gen-new-version-files.py b/workflow_scripts/gen-new-version-files.py index 3861e681..c1aedae3 100644 --- a/workflow_scripts/gen-new-version-files.py +++ b/workflow_scripts/gen-new-version-files.py @@ -1,48 +1,29 @@ import os import subprocess -import requests +import semver # Constants DIST_FOLDER = './dist' NEW_VERSIONS = os.environ.get("NEW_VERSIONS","") +SCRIPT_EXTENSION=".sh" if NEW_VERSIONS == "": print("no new versions available, NEW_VERSIONS env variable is empty") exit(1) -def get_max_version(ver1, ver2): - if ver1.startswith('v'): - ver1 = ver1[1:] - if ver2.startswith('v'): - ver2 = ver2[1:] - - ver1_tuple = tuple(map(int, ver1.split('.'))) - ver2_tuple = tuple(map(int, ver2.split('.'))) - if ver1 > ver2: - return ver1 - return ver2 - -def format_version(v): - if v.startswith('v'): - return v[1:] - return v - def get_last_added_version(files_dir): max_modification_time = 0.0 - last_added_version = "" + last_added_version = "0.0.0" for file in os.listdir(files_dir): - if file.endswith('.sh') and file.count('.') == 3: + if file.endswith(SCRIPT_EXTENSION) and file.count('.') == 3: file_path = os.path.join(files_dir, file) modification_time = os.path.getmtime(file_path) - file_version = 'v' + file[:-3] + file_version = file.removesuffix(SCRIPT_EXTENSION) if modification_time > max_modification_time: max_modification_time = modification_time last_added_version = file_version elif modification_time == max_modification_time: - if last_added_version == "": - last_added_version = file_version - else: - last_added_version = get_max_version(last_added_version,file_version) + last_added_version = semver.max_ver(last_added_version,file_version) return last_added_version @@ -59,16 +40,9 @@ def get_version_dict(versions): version_dict = {} for version in versions: - version_parts = version.split('.') - major_minor = version_parts[0] + '.' + version_parts[1] - - if major_minor in version_dict: - current_version = tuple(map(int, version_parts[2])) - max_version = tuple(map(int, version_dict[major_minor].split('.')[2])) - if current_version > max_version: - version_dict[major_minor] = version - else: - version_dict[major_minor] = version + version_parts = semver.parse(version) + major_minor = f"{version_parts['major']}.{version_parts['minor']}" + version_dict[major_minor] = semver.max_ver(version_dict.setdefault(major_minor, version), version) return version_dict @@ -77,19 +51,16 @@ def main(): last_added_version = get_last_added_version(DIST_FOLDER) print("Last added version:",last_added_version) - new_versions = NEW_VERSIONS.split(',') - formatted_new_versions = list(map(format_version,new_versions)) - print("Formatted new versions: ", formatted_new_versions) + version_list = [version.removeprefix('v') for version in NEW_VERSIONS.split(',')] + print("Formatted new versions: ", version_list) - for version in formatted_new_versions: + for version in version_list: generate_diffs(last_added_version, version) - versions_string = ",".join(new_versions) - print("running generate script") subprocess.run(["bash", "./scripts/generate"], check=True) - version_dict = get_version_dict(formatted_new_versions) + version_dict = get_version_dict(version_list) print("version dictionary for symlink: ",version_dict) for major_minor,version in version_dict.items(): diff --git a/workflow_scripts/requirements.txt b/workflow_scripts/requirements.txt index 9688b8ec..f0a13749 100644 --- a/workflow_scripts/requirements.txt +++ b/workflow_scripts/requirements.txt @@ -1 +1,2 @@ Requests==2.31.0 +semver==3.0.2 From 4baa4164223d0cdd25de99f184419f169312a66d Mon Sep 17 00:00:00 2001 From: Chirayu Kapoor Date: Fri, 17 May 2024 16:01:53 +0530 Subject: [PATCH 2/2] chore: Update the workflow name and URL Signed-off-by: Chirayu Kapoor --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 469624a3..1aefb5bf 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ TEST_OS_IMAGE_TAG[2]="10" On each merge to master, scripts in `dist/` will be uploaded to `install-docker-dev` bucket and can be retrieved using https://releases.rancher.com/install-docker-dev/$VERSION.sh. The commit of the version that was uploaded can be found on https://releases.rancher.com/install-docker-dev/VERSION -When testing has been completed, a tag can be created to upload the scripts in `dist/` to `install-docker` (https://releases.rancher.com/install-docker/$VERSION.sh). A tag consists of the latest Docker version in the repository (for example, `20.10.12`) and epoch timestamp (in case we need to release same set of versions with changes). The tag can be generated using `scripts/generate-release-tag`, or you can use the GitHub Actions workflow [Create release tag](https://github.com/rancher/install-docker/actions/workflows/create-tag.yml) directly. The tag of the version that was uploaded can be found on https://releases.rancher.com/install-docker/VERSION +When testing has been completed, the release job needs to be run to upload the scripts in `dist/` to `install-docker` (https://releases.rancher.com/install-docker/$VERSION.sh). A tag consists of the latest Docker version in the repository (for example, `20.10.12`) and epoch timestamp (in case we need to release same set of versions with changes). The release job will automatically create a tag and release the artifacts to the specified upload bucket. To initiate the release process, use the GitHub Actions workflow [Creates a tag and upload release](https://github.com/rancher/install-docker/actions/workflows/create-release.yml). You can find the tag of the version that was uploaded at https://releases.rancher.com/install-docker/VERSION ## Previous manual instructions to add a new version