/semver-aliases

A simple Go package to create deduplicated version aliases based on valid SemVer release names.

Primary LanguageGoApache License 2.0Apache-2.0

Go SemVer Aliases devel codecov Go Report Card GoDoc

A simple Go package to create deduplicated version aliases based on valid SemVer release names.

The library takes care of optional prefixed releases (v) as well as all version names are deduplicated and sorted in lexicographic order.

For example this library can be used to create SemVer and custom aliases for tagging Docker images.

Usage

package main

import (
	"fmt"

	aliases "github.com/joseluisq/semver-aliases"
)

func main() {
	// 1. Create alias names based on a given release
	versionAliases := aliases.FromVersion("v1.0.0")
	fmt.Printf("%#v\n", versionAliases)
	//	[]string{"1", "1.0", "1.0.0"}

	extras := []string{"latest", "stable", "v1.0.0", "1.0"}
	composed := append(versionAliases, extras...)
	fmt.Printf("%#v\n", composed)
	//	[]string{"1", "1.0", "1.0.0", "latest", "stable", "v1.0.0", "1.0"}

	// 2. Or create alias names based on a list of names (deduplicated and sorted)
	tags := aliases.FromVersionNames(composed)
	fmt.Printf("%#v\n", tags)
	//	[]string{"1", "1.0", "1.0.0", "latest", "stable"}

	// 3. Or create version names with its items suffixed (sorted)
	suffixed := aliases.GetVersionNamesSuffixed(versionAliases, "linux-amd64")
	fmt.Printf("%#v\n", suffixed)
	//	[]string{"1-linux-amd64", "1.0-linux-amd64", "1.0.0-linux-amd64"}
}

Examples

Documentation

pkg.go.dev/github.com/joseluisq/semver-aliases

Contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in current work by you, as defined in the Apache-2.0 license, shall be dual licensed as described below, without any additional terms or conditions.

Feel free to send some Pull request or issue.

License

This work is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).

© 2020-present Jose Quintana