mirror of
https://github.com/jimeh/build-emacs-for-macos.git
synced 2026-02-19 11:56: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).
93 lines
2.2 KiB
Go
93 lines
2.2 KiB
Go
package plan
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/jimeh/build-emacs-for-macos/pkg/osinfo"
|
|
"github.com/jimeh/build-emacs-for-macos/pkg/release"
|
|
"github.com/jimeh/build-emacs-for-macos/pkg/source"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type Plan struct {
|
|
Build *Build `yaml:"build,omitempty" json:"build,omitempty"`
|
|
Source *source.Source `yaml:"source,omitempty" json:"source,omitempty"`
|
|
OS *osinfo.OSInfo `yaml:"os,omitempty" json:"os,omitempty"`
|
|
Release *Release `yaml:"release,omitempty" json:"release,omitempty"`
|
|
Output *Output `yaml:"output,omitempty" json:"output,omitempty"`
|
|
}
|
|
|
|
// Load attempts to loads a plan YAML from given filename.
|
|
func Load(filename string) (*Plan, error) {
|
|
b, err := os.ReadFile(filename)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
p := &Plan{}
|
|
err = yaml.Unmarshal(b, p)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return p, nil
|
|
}
|
|
|
|
// WriteYAML writes plan in YAML format to given io.Writer.
|
|
func (s *Plan) WriteYAML(w io.Writer) error {
|
|
enc := yaml.NewEncoder(w)
|
|
enc.SetIndent(2)
|
|
|
|
return enc.Encode(s)
|
|
}
|
|
|
|
// YAML returns plan in YAML format.
|
|
func (s *Plan) YAML() (string, error) {
|
|
var buf bytes.Buffer
|
|
err := s.WriteYAML(&buf)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return buf.String(), nil
|
|
}
|
|
|
|
// WriteJSON writes plan in JSON format to given io.Writer.
|
|
func (s *Plan) WriteJSON(w io.Writer) error {
|
|
enc := json.NewEncoder(w)
|
|
enc.SetIndent("", " ")
|
|
|
|
return enc.Encode(s)
|
|
}
|
|
|
|
// JSON returns plan in JSON format.
|
|
func (s *Plan) JSON() (string, error) {
|
|
var buf bytes.Buffer
|
|
err := s.WriteJSON(&buf)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return buf.String(), nil
|
|
}
|
|
|
|
type Build struct {
|
|
Name string `yaml:"name,omitempty" json:"name,omitempty"`
|
|
}
|
|
|
|
type Release struct {
|
|
Name string `yaml:"name" json:"name"`
|
|
Title string `yaml:"title,omitempty" json:"title,omitempty"`
|
|
Draft bool `yaml:"draft,omitempty" json:"draft,omitempty"`
|
|
Prerelease bool `yaml:"prerelease,omitempty" json:"prerelease,omitempty"`
|
|
Channel release.Channel `yaml:"channel,omitempty" json:"channel,omitempty"`
|
|
}
|
|
|
|
type Output struct {
|
|
Directory string `yaml:"directory,omitempty" json:"directory,omitempty"`
|
|
DiskImage string `yaml:"disk_image,omitempty" json:"disk_image,omitempty"`
|
|
}
|