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.
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/aliases.go
- Playground code example
- Tests examples at aliases_test.go
pkg.go.dev/github.com/joseluisq/semver-aliases
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.
This work is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).
© 2020-present Jose Quintana