mirror of
https://github.com/fluxcd/flux2.git
synced 2026-05-03 00:28:50 +00:00
Add flux version to bootstrap commit messages
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
parent
60a1e78869
commit
bc9cbc387c
5 changed files with 117 additions and 12 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue