1
0
mirror of synced 2026-02-06 19:05:55 +00:00

Add flux version to bootstrap commit messages

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
Stefan Prodan
2021-02-12 10:42:20 +02:00
parent 60a1e78869
commit bc9cbc387c
5 changed files with 117 additions and 12 deletions

View File

@@ -18,11 +18,14 @@ package install
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
"strings"
"time"
securejoin "github.com/cyphar/filepath-securejoin"
@@ -75,3 +78,29 @@ func Generate(options Options) (*manifestgen.Manifest, error) {
Content: string(content),
}, nil
}
// GetLatestVersion calls the GitHub API and returns the latest released version.
func GetLatestVersion() (string, error) {
ghURL := "https://api.github.com/repos/fluxcd/flux2/releases/latest"
c := http.DefaultClient
c.Timeout = 15 * time.Second
res, err := c.Get(ghURL)
if err != nil {
return "", fmt.Errorf("calling GitHub API failed: %w", err)
}
if res.Body != nil {
defer res.Body.Close()
}
type meta struct {
Tag string `json:"tag_name"`
}
var m meta
if err := json.NewDecoder(res.Body).Decode(&m); err != nil {
return "", fmt.Errorf("decoding GitHub API response failed: %w", err)
}
return m.Tag, err
}