From 128dbacdbd323a5ec11df8da198a0b24626e9aa3 Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Tue, 14 May 2024 17:05:23 -0400 Subject: [PATCH 1/4] allow for new Docker releases with no previously published releases --- .github/actions/latest-wrangler/main.py | 45 ++++++++++++++++--------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/.github/actions/latest-wrangler/main.py b/.github/actions/latest-wrangler/main.py index e001abe..a369bda 100644 --- a/.github/actions/latest-wrangler/main.py +++ b/.github/actions/latest-wrangler/main.py @@ -1,8 +1,9 @@ import os +import sys +from typing import List, Optional + from packaging.version import Version, parse import requests -import sys -from typing import List def main(): @@ -21,7 +22,7 @@ def _package_metadata(package_name: str, github_token: str) -> requests.Response return requests.get(url, auth=("", github_token)) -def _published_versions(response: requests.Response) -> List[Version]: +def _published_versions(response: requests.Response) -> List[Optional[Version]]: package_metadata = response.json() return [ parse(tag) @@ -31,24 +32,36 @@ def _published_versions(response: requests.Response) -> List[Version]: ] -def _new_version_tags(new_version: Version, published_versions: List[Version]) -> List[str]: - # the package version is always a tag - tags = [str(new_version)] +def _new_version_tags(new_version: Version, published_versions: List[Optional[Version]]) -> List[str]: + latest = "latest" + latest_minor = f"{new_version.major}.{new_version.minor}.latest" + pinned = str(new_version) + + published_patches = [ + patch + for patch in published_versions + if patch.major == new_version.major and patch.minor == new_version.minor + ] # pre-releases don't get tagged with `latest` if new_version.is_prerelease: - return tags + tags = [pinned] - if new_version > max(published_versions): - tags.append("latest") + # first releases are automatically the latest + elif not published_versions: + tags = [pinned, latest_minor, latest] - published_patches = [ - version - for version in published_versions - if version.major == new_version.major and version.minor == new_version.minor - ] - if new_version > max(published_patches): - tags.append(f"{new_version.major}.{new_version.minor}.latest") + # the overall latest release is also the latest minor release + elif new_version > max(published_versions): + tags = [pinned, latest_minor, latest] + + # this is not the overall latest release, but is still the latest minor release + elif new_version > max(published_patches): + tags = [pinned, latest_minor] + + # this is a patch release that was released off-cycle + else: + tags = [pinned] return tags From 48617b31dd33b3e77c04da94707e33ceeee3a71f Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Tue, 14 May 2024 17:36:40 -0400 Subject: [PATCH 2/4] point docker release to latest-wrangler on this branch for now --- .github/workflows/release-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml index aec31d3..ff0bc02 100644 --- a/.github/workflows/release-docker.yml +++ b/.github/workflows/release-docker.yml @@ -47,7 +47,7 @@ jobs: - name: "Get the tags to publish" id: tags # this cannot be relative because this workflow is called from multiple repos - uses: dbt-labs/dbt-release/.github/actions/latest-wrangler@main + uses: dbt-labs/dbt-release/.github/actions/latest-wrangler@latest-wrangler-new-docker with: package_name: ${{ inputs.package }} new_version: ${{ inputs.version_number }} From 74f699fdca09170b60329380370f6f6bbb53b1ae Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Tue, 14 May 2024 18:20:06 -0400 Subject: [PATCH 3/4] account for first minor release --- .github/actions/latest-wrangler/main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/actions/latest-wrangler/main.py b/.github/actions/latest-wrangler/main.py index a369bda..41eb29e 100644 --- a/.github/actions/latest-wrangler/main.py +++ b/.github/actions/latest-wrangler/main.py @@ -43,7 +43,7 @@ def _new_version_tags(new_version: Version, published_versions: List[Optional[Ve if patch.major == new_version.major and patch.minor == new_version.minor ] - # pre-releases don't get tagged with `latest` + # pre-releases don't get tagged with `latest` tags if new_version.is_prerelease: tags = [pinned] @@ -55,7 +55,11 @@ def _new_version_tags(new_version: Version, published_versions: List[Optional[Ve elif new_version > max(published_versions): tags = [pinned, latest_minor, latest] - # this is not the overall latest release, but is still the latest minor release + # first minor releases are automatically the latest minor release + elif not published_patches: + tags = [pinned, latest_minor] + + # this is a patch release that was released chronologically elif new_version > max(published_patches): tags = [pinned, latest_minor] From 68df897cff24f0d87801805bb053329c18261bcb Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Wed, 15 May 2024 14:36:21 -0400 Subject: [PATCH 4/4] point back to main --- .github/workflows/release-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml index ff0bc02..aec31d3 100644 --- a/.github/workflows/release-docker.yml +++ b/.github/workflows/release-docker.yml @@ -47,7 +47,7 @@ jobs: - name: "Get the tags to publish" id: tags # this cannot be relative because this workflow is called from multiple repos - uses: dbt-labs/dbt-release/.github/actions/latest-wrangler@latest-wrangler-new-docker + uses: dbt-labs/dbt-release/.github/actions/latest-wrangler@main with: package_name: ${{ inputs.package }} new_version: ${{ inputs.version_number }}