CI: Call for Grafana version on demand - remove need for version.json (#54638)
* Remove need for version.json * Fix lint * log.Info -> fmt.Print * Add back tests * Remove non-used file * Fix lint * Update grabpl version to v3.0.6
This commit is contained in:
@@ -2,10 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@@ -57,40 +54,6 @@ func (md *Metadata) GetReleaseMode() (ReleaseMode, error) {
|
||||
// than the way it will be built in 'main'
|
||||
type VersionMap map[VersionMode]Version
|
||||
|
||||
// GetMetadata attempts to read the JSON file located at 'path' and decode it as a Metadata{} type.
|
||||
// If the provided path does not exist, then an error is not returned. Instead, an empty metadata is returned with no error.
|
||||
func GetMetadata(path string) (*Metadata, error) {
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return &Metadata{}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
// Ignore gosec G304 as this function is only used in the build process.
|
||||
//nolint:gosec
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if err := file.Close(); err != nil {
|
||||
log.Printf("error closing file at '%s': %s", path, err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
return DecodeMetadata(file)
|
||||
}
|
||||
|
||||
// DecodeMetadata decodes the data in the io.Reader 'r' as Metadata.
|
||||
func DecodeMetadata(r io.Reader) (*Metadata, error) {
|
||||
m := &Metadata{}
|
||||
if err := json.NewDecoder(r).Decode(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVersions reads the embedded config.json and decodes it.
|
||||
func GetVersion(mode VersionMode) (*Version, error) {
|
||||
if v, ok := Versions[mode]; ok {
|
||||
|
||||
Reference in New Issue
Block a user