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

Allow for new Docker releases with no previously published releases #122

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
45 changes: 29 additions & 16 deletions .github/actions/latest-wrangler/main.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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)
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
with:
package_name: ${{ inputs.package }}
new_version: ${{ inputs.version_number }}
Expand Down