mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-02 09:36:19 +00:00
Split off cli into separate binaries (#37)
* 🎨 Split off cli into separate binaries This commit splits off the cli into 3 binaries: - agent - cli - provider The provider now is a separate component that can be tested by itself and have its own lifecycle. This paves the way to a ligher c3os variant, HA support and other features that can be provided on runtime. This is working, but still there are low hanging fruit to care about. Fixes #14 * 🤖 Add provider bin to releases * ⚙️ Handle signals * ⚙️ Reduce buildsize footprint * 🎨 Scan for providers also in /system/providers * 🤖 Run goreleaser * 🎨 Refactoring
This commit is contained in:
committed by
Itxaka
parent
74bfd373db
commit
63cd28d1cb
49
internal/github/releases.go
Normal file
49
internal/github/releases.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package github
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-github/v40/github"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
func newHTTPClient(ctx context.Context, token string) *http.Client {
|
||||
if token == "" {
|
||||
return http.DefaultClient
|
||||
}
|
||||
src := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
|
||||
return oauth2.NewClient(ctx, src)
|
||||
}
|
||||
|
||||
func FindReleases(ctx context.Context, token, slug string) ([]string, error) {
|
||||
hc := newHTTPClient(ctx, token)
|
||||
cli := github.NewClient(hc)
|
||||
|
||||
repo := strings.Split(slug, "/")
|
||||
if len(repo) != 2 || repo[0] == "" || repo[1] == "" {
|
||||
return nil, fmt.Errorf("Invalid slug format. It should be 'owner/name': %s", slug)
|
||||
}
|
||||
|
||||
rels, res, err := cli.Repositories.ListReleases(ctx, repo[0], repo[1], nil)
|
||||
if err != nil {
|
||||
log.Println("API returned an error response:", err)
|
||||
if res != nil && res.StatusCode == 404 {
|
||||
// 404 means repository not found or release not found. It's not an error here.
|
||||
err = nil
|
||||
log.Println("API returned 404. Repository or release not found")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
versions := []string{}
|
||||
for _, rel := range rels {
|
||||
if strings.HasPrefix(*rel.Name, "v") {
|
||||
versions = append(versions, *rel.Name)
|
||||
}
|
||||
}
|
||||
return versions, nil
|
||||
}
|
Reference in New Issue
Block a user