Skip to content

pull icons during release command #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,10 @@ func release(c *cli.Context) {
CurrentAsset = release.Chart + "/" + release.AssetTgz
unzipAssets(c)

if err := release.PullIcon(ctx, rootFs); err != nil {
logger.Fatal(ctx, fmt.Errorf("failed to pull icon: %w", err).Error())
}

// update release.yaml
if err := release.UpdateReleaseYaml(); err != nil {
logger.Fatal(ctx, fmt.Errorf("failed to update release.yaml: %w", err).Error())
Expand Down
57 changes: 57 additions & 0 deletions pkg/auto/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"os"
"strings"

"github.com/go-git/go-billy/v5"
"github.com/rancher/charts-build-scripts/pkg/filesystem"
"github.com/rancher/charts-build-scripts/pkg/git"
"github.com/rancher/charts-build-scripts/pkg/lifecycle"
"github.com/rancher/charts-build-scripts/pkg/logger"
"github.com/rancher/charts-build-scripts/pkg/path"
"gopkg.in/yaml.v3"
helmChartutil "helm.sh/helm/v3/pkg/chartutil"
)

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

return nil
}

// PullIcon will pull the icon from the chart and save it to the local assets/logos directory
func (r *Release) PullIcon(ctx context.Context, rootFs billy.Filesystem) error {
logger.Log(ctx, slog.LevelInfo, "starting to pull icon process")

// Get Chart.yaml path and load it
chartYamlPath := path.RepositoryChartsDir + "/" + r.Chart + "/" + r.ChartVersion + "/Chart.yaml"
absChartPath := filesystem.GetAbsPath(rootFs, chartYamlPath)

// Load Chart.yaml file
chartMetadata, err := helmChartutil.LoadChartfile(absChartPath)
if err != nil {
return fmt.Errorf("could not load %s: %s", chartYamlPath, err)
}

logger.Log(ctx, slog.LevelDebug, "checking if chart has downloaded icon")
iconField := chartMetadata.Icon

// Check file prefix if it is a URL just skip this process
if !strings.HasPrefix(iconField, "file://") {
logger.Log(ctx, slog.LevelInfo, "icon path is not a file:// prefix")
return nil
}

relativeIconPath, _ := strings.CutPrefix(iconField, "file://")

// Check if icon is already present
exists, err := filesystem.PathExists(ctx, rootFs, relativeIconPath)
if err != nil {
return err
}

// Icon is already present, no need to pull it
if exists {
logger.Log(ctx, slog.LevelDebug, "icon already exists")
return nil
}

// Check if the icon exists in the dev branch
if err := r.git.CheckFileExists(relativeIconPath, r.VR.DevBranch); err != nil {
logger.Log(ctx, slog.LevelError, "icon file not found in dev branch but should", slog.String("icon", relativeIconPath), logger.Err(err))
return fmt.Errorf("icon file not found in dev branch but should: %w", err)
}

// checkout the icon file from the dev branch
if err := r.git.CheckoutFile(r.VR.DevBranch, relativeIconPath); err != nil {
return err
}

// git reset return
return r.git.ResetHEAD()
}
Loading