Add new fetching of git tags
This commit is contained in:
parent
279b57c4ef
commit
020d9f442e
@ -28,7 +28,7 @@ In practice, it means that for a project like [StyLua](https://github.com/Johnny
|
||||
--map-system Windows=win64 --map-system Darwin=macos --map-system=linux=Linux \
|
||||
"stylua-{version}-{system}.zip"
|
||||
|
||||
And `release-gitter` will get the release version from the `Cargo.toml`, get the URL from the `git remote`, call the Github API and look for a release matching the templated file name, extract the `stylua` file from the archive, and then make it executable.
|
||||
And `release-gitter` will get the release version from the `Cargo.toml`, get the URL from the `git remote`, call the Github API and look for a release matching the templated file name, extract the `stylua` file from the archive, and then make it executable. Alternatively, if you're project `--version-git-tag` can be used to pull the version from the latest tag. This will automatically do a shallow fetch (depth = 1), but this can be supressed with `--version-git-no-fetch`.
|
||||
|
||||
This allows a single command to be run from a checked out repo from pre-commit on any system to fetch the appropriate binary.
|
||||
|
||||
@ -38,6 +38,7 @@ Full usage is as follows:
|
||||
|
||||
usage: release-gitter [-h] [--hostname HOSTNAME] [--owner OWNER] [--repo REPO]
|
||||
[--git-url GIT_URL] [--version VERSION]
|
||||
[--version-git-tag] [--version-git-no-fetch]
|
||||
[--map-system MAP_SYSTEM] [--map-arch MAP_ARCH]
|
||||
[--exec EXEC] [--extract-files EXTRACT_FILES]
|
||||
[--extract-all] [--url-only]
|
||||
@ -59,6 +60,10 @@ Full usage is as follows:
|
||||
repo
|
||||
--version VERSION Release version to download. If not provied, it will
|
||||
look for project metadata
|
||||
--version-git-tag, -t
|
||||
Get the release version from a git tag
|
||||
--version-git-no-fetch
|
||||
Shallow fetch tags prior to checking versions
|
||||
--map-system MAP_SYSTEM, -s MAP_SYSTEM
|
||||
Map a platform.system() value to a custom value
|
||||
--map-arch MAP_ARCH, -a MAP_ARCH
|
||||
|
@ -104,7 +104,18 @@ def get_cargo_version(p: Path) -> str:
|
||||
raise ValueError(f"No version found in {p}")
|
||||
|
||||
|
||||
def read_version() -> Optional[str]:
|
||||
def get_git_tag(fetch: bool = True) -> Optional[str]:
|
||||
if fetch:
|
||||
check_call(["git", "fetch", "--tags", "--depth", "1"])
|
||||
|
||||
git_tag = check_output(["git", "describe", "--tags"]).decode("UTF-8").strip()
|
||||
return git_tag or None
|
||||
|
||||
|
||||
def read_version(from_tags: bool = False, fetch: bool = False) -> Optional[str]:
|
||||
if from_tags:
|
||||
return get_git_tag(fetch)
|
||||
|
||||
matchers = {
|
||||
"Cargo.toml": get_cargo_version,
|
||||
}
|
||||
@ -361,6 +372,17 @@ def parse_args(args: Optional[list[str]] = None) -> argparse.Namespace:
|
||||
"--version",
|
||||
help="Release version to download. If not provied, it will look for project metadata",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--version-git-tag",
|
||||
"-t",
|
||||
action="store_true",
|
||||
help="Get the release version from a git tag",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--version-git-no-fetch",
|
||||
action="store_true",
|
||||
help="Shallow fetch tags prior to checking versions",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--map-system",
|
||||
"-s",
|
||||
@ -409,7 +431,10 @@ def parse_args(args: Optional[list[str]] = None) -> argparse.Namespace:
|
||||
merge_field(parsed_args, remote_info, field)
|
||||
|
||||
if parsed_args.version is None:
|
||||
parsed_args.version = read_version()
|
||||
parsed_args.version = read_version(
|
||||
parsed_args.version_git_tag,
|
||||
not parsed_args.version_git_no_fetch,
|
||||
)
|
||||
|
||||
if parsed_args.extract_all:
|
||||
parsed_args.extract_files = []
|
||||
|
Loading…
Reference in New Issue
Block a user