From 2c5174f38e56cff651e398f73b382a36748ebcec Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Wed, 25 Oct 2023 21:56:30 -0400 Subject: [PATCH] fix: ensure release tags are cronological (#18) --- README.md | 4 ++-- action/main.py | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2704bec..6ac4e1d 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ The action does the following: | publish_release | Whether or not to publish a release | | publish_stable_release | Whether or not to publish a stable release. The opposite of `publish_pre_release`. | | release_body | The body for the release | -| release_build | The build number to identify this build (i.e. first 7 characters of commit hash) | +| release_build | The build number to identify this build (i.e. `hhmmss`) | | release_commit | The commit hash for the release | | release_generate_release_notes | Whether or not to generate release notes for the release | | release_tag | The tag for the release (i.e. `release_version`-`release_build`) | @@ -110,7 +110,7 @@ subgraph "Set GitHub Outputs" B4(changelog_url = '') B5(changelog_version = '') - C1(release_build = \commit 0-7\) + C1(release_build = \hhmmss\) C2(release_commit = \commit\ ) D1{GitHub Release Exists?} diff --git a/action/main.py b/action/main.py index 50afe09..932c5f0 100644 --- a/action/main.py +++ b/action/main.py @@ -189,18 +189,24 @@ def get_push_event_details() -> dict: else: return push_event_details - # use regex and convert created at to yyyy.m.d - match = re.search(r'(\d{4})-(\d{1,2})-(\d{1,2})', push_event["created_at"]) + # use regex and convert created at to yyyy.m.d-hhmmss + # created_at: "2023-1-25T10:43:35Z" + match = re.search(r'(\d{4})-(\d{1,2})-(\d{1,2})T(\d{1,2}):(\d{2}):(\d{2})Z', push_event["created_at"]) release_version = '' + release_build = '' if match: - year = match.group(1) - month = match.group(2).zfill(2) # Ensure month is zero-padded to two digits - day = match.group(3).zfill(2) # Ensure day is zero-padded to two digits + year = int(match.group(1)) + month = int(match.group(2)) + day = int(match.group(3)) + hour = match.group(4).zfill(2) + minute = match.group(5).zfill(2) + second = match.group(6).zfill(2) release_version = f"{year}.{month}.{day}" + release_build = f"{hour}{minute}{second}" push_event_details['release_version'] = release_version - push_event_details['release_build'] = push_event["payload"]["head"][0:7] + push_event_details['release_build'] = release_build return push_event_details