Skip to content

Commit

Permalink
Add script to get snapcraft releases
Browse files Browse the repository at this point in the history
  • Loading branch information
FirelightFlagboy committed Jul 15, 2024
1 parent 6d88c23 commit 1deb169
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions misc/snapcraft_releases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS
import logging
from argparse import ArgumentParser
from enum import StrEnum

from releaser import Version

log = logging.getLogger(__name__)


class Track(StrEnum):
Latest = "latest"
V2 = "v2"
V3 = "v3"
Nightly = "nightly"


class Channel(StrEnum):
Stable = "stable"
Candidate = "candidate"
Beta = "beta"
Edge = "edge"


CHANNELS = (Channel.Stable, Channel.Candidate, Channel.Beta, Channel.Edge)


def get_tracks_for_version(version: Version) -> list[Track]:
TRACKS_FOR_V2 = (Track.V2,)
# TODO: Add Latest track once we publicly release v3
TRACKS_FOR_V3 = (Track.V3,)

tracks: list[Track] = []
match version.major:
case 2:
tracks.extend(TRACKS_FOR_V2)
case 3:
tracks.extend(TRACKS_FOR_V3)
case _:
raise ValueError(f"Unsupported major version: {version.major}")
return tracks


assert get_tracks_for_version(Version.parse("2.0.0")) == [Track.V2]
assert get_tracks_for_version(Version.parse("3.0.0")) == [Track.V3]


def get_channel_for_version(version: Version) -> Channel:
PRERELEASE_TO_CHANNEL = {
"a": Channel.Edge,
"b": Channel.Beta,
"rc": Channel.Candidate,
}

if version.prerelease:
for pre, chan in PRERELEASE_TO_CHANNEL.items():
if version.prerelease.startswith(pre):
return chan
raise ValueError(f"Unsupported prerelease: {version.prerelease}")
elif version.dev is not None:
return Channel.Edge
else:
return Channel.Stable


assert get_channel_for_version(Version.parse("3.0.0")) == Channel.Stable
assert get_channel_for_version(Version.parse("3.0.0-a.1")) == Channel.Edge
assert get_channel_for_version(Version.parse("3.0.0-b.1")) == Channel.Beta
assert get_channel_for_version(Version.parse("3.0.0-rc.1")) == Channel.Candidate
assert get_channel_for_version(Version.parse("3.0.0-dev.1")) == Channel.Edge

if __name__ == "__main__":
parser = ArgumentParser(
"snapcraft_channel",
description="""
Determine the snapcraft channel based on the provided options and version.
""",
)

parser.add_argument(
"version", help="The version to determine the channel for.", type=Version.parse
)
parser.add_argument("--nightly", help="Use nightly channel", action="store_true")

args = parser.parse_args()

logging.basicConfig(level=logging.INFO)

version: Version = args.version
log.info(f"Parsed version: {version!r}")

tracks_for_version = get_tracks_for_version(version)
log.info(f"Tracks for version {version}: {', '.join(tracks_for_version)}")

if args.nightly:
print(
# Update the edge channel of the version's tracks
*(map(lambda track: f"--release={track}/{Channel.Edge}", tracks_for_version)),
# Update all nightly's channels
*(map(lambda chan: f"--release={Track.Nightly}/{chan}", CHANNELS)),
sep="\n",
)
else:
channel = get_channel_for_version(version)
log.info(f"Channel for version {version}: {channel}")

print(*(map(lambda track: f"--release={track}/{channel}", tracks_for_version)), sep="\n")

0 comments on commit 1deb169

Please sign in to comment.