mirror of
https://github.com/jimeh/build-emacs-for-macos.git
synced 2026-02-19 06:06:40 +00:00
Add support for naming release and builds accordingly when given a git
ref for a pretest (90 or above patch number) or release
candidate ("-rcX" at the end of the tag).
43 lines
871 B
Go
43 lines
871 B
Go
package release
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"regexp"
|
|
)
|
|
|
|
// Errors
|
|
var (
|
|
Err = errors.New("release")
|
|
ErrInvalidName = fmt.Errorf("%w: invalid name", Err)
|
|
ErrEmptyVersion = fmt.Errorf("%w: empty version", Err)
|
|
ErrNotStableRef = fmt.Errorf(
|
|
"%w: git ref is not stable tagged release", Err,
|
|
)
|
|
)
|
|
|
|
var (
|
|
stableVersion = regexp.MustCompile(`^\d+\.\d+(?:[a-z]+)?$`)
|
|
stableGitRef = regexp.MustCompile(`^emacs-(\d+\.\d+(?:[a-z]+)?)$`)
|
|
)
|
|
|
|
func VersionToName(version string) (string, error) {
|
|
if version == "" {
|
|
return "", ErrEmptyVersion
|
|
}
|
|
|
|
if stableVersion.MatchString(version) {
|
|
return "Emacs-" + version, nil
|
|
}
|
|
|
|
return "Emacs." + version, nil
|
|
}
|
|
|
|
func GitRefToStableVersion(ref string) (string, error) {
|
|
if m := stableGitRef.FindStringSubmatch(ref); len(m) > 1 {
|
|
return m[1], nil
|
|
}
|
|
|
|
return "", fmt.Errorf("%w: \"%s\"", ErrNotStableRef, ref)
|
|
}
|