Skip to content

Commit f5575af

Browse files
authored
Merge pull request #209 from nicholasSUSE/fix-icons
pull icons during release command
2 parents 9a52cff + ac1bba8 commit f5575af

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,10 @@ func release(c *cli.Context) {
900900
CurrentAsset = release.Chart + "/" + release.AssetTgz
901901
unzipAssets(c)
902902

903+
if err := release.PullIcon(ctx, rootFs); err != nil {
904+
logger.Fatal(ctx, fmt.Errorf("failed to pull icon: %w", err).Error())
905+
}
906+
903907
// update release.yaml
904908
if err := release.UpdateReleaseYaml(); err != nil {
905909
logger.Fatal(ctx, fmt.Errorf("failed to update release.yaml: %w", err).Error())

pkg/auto/release.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ import (
55
"errors"
66
"fmt"
77
"io"
8+
"log/slog"
89
"os"
10+
"strings"
911

12+
"github.com/go-git/go-billy/v5"
1013
"github.com/rancher/charts-build-scripts/pkg/filesystem"
1114
"github.com/rancher/charts-build-scripts/pkg/git"
1215
"github.com/rancher/charts-build-scripts/pkg/lifecycle"
16+
"github.com/rancher/charts-build-scripts/pkg/logger"
1317
"github.com/rancher/charts-build-scripts/pkg/path"
1418
"gopkg.in/yaml.v3"
19+
helmChartutil "helm.sh/helm/v3/pkg/chartutil"
1520
)
1621

1722
// Release holds necessary metadata to release a chart version
@@ -154,3 +159,55 @@ func (r *Release) UpdateReleaseYaml() error {
154159

155160
return nil
156161
}
162+
163+
// PullIcon will pull the icon from the chart and save it to the local assets/logos directory
164+
func (r *Release) PullIcon(ctx context.Context, rootFs billy.Filesystem) error {
165+
logger.Log(ctx, slog.LevelInfo, "starting to pull icon process")
166+
167+
// Get Chart.yaml path and load it
168+
chartYamlPath := path.RepositoryChartsDir + "/" + r.Chart + "/" + r.ChartVersion + "/Chart.yaml"
169+
absChartPath := filesystem.GetAbsPath(rootFs, chartYamlPath)
170+
171+
// Load Chart.yaml file
172+
chartMetadata, err := helmChartutil.LoadChartfile(absChartPath)
173+
if err != nil {
174+
return fmt.Errorf("could not load %s: %s", chartYamlPath, err)
175+
}
176+
177+
logger.Log(ctx, slog.LevelDebug, "checking if chart has downloaded icon")
178+
iconField := chartMetadata.Icon
179+
180+
// Check file prefix if it is a URL just skip this process
181+
if !strings.HasPrefix(iconField, "file://") {
182+
logger.Log(ctx, slog.LevelInfo, "icon path is not a file:// prefix")
183+
return nil
184+
}
185+
186+
relativeIconPath, _ := strings.CutPrefix(iconField, "file://")
187+
188+
// Check if icon is already present
189+
exists, err := filesystem.PathExists(ctx, rootFs, relativeIconPath)
190+
if err != nil {
191+
return err
192+
}
193+
194+
// Icon is already present, no need to pull it
195+
if exists {
196+
logger.Log(ctx, slog.LevelDebug, "icon already exists")
197+
return nil
198+
}
199+
200+
// Check if the icon exists in the dev branch
201+
if err := r.git.CheckFileExists(relativeIconPath, r.VR.DevBranch); err != nil {
202+
logger.Log(ctx, slog.LevelError, "icon file not found in dev branch but should", slog.String("icon", relativeIconPath), logger.Err(err))
203+
return fmt.Errorf("icon file not found in dev branch but should: %w", err)
204+
}
205+
206+
// checkout the icon file from the dev branch
207+
if err := r.git.CheckoutFile(r.VR.DevBranch, relativeIconPath); err != nil {
208+
return err
209+
}
210+
211+
// git reset return
212+
return r.git.ResetHEAD()
213+
}

0 commit comments

Comments
 (0)