Skip to content

Commit

Permalink
Add ignore version flag to generate artifacts-index (#420)
Browse files Browse the repository at this point in the history
* fix style and show itens by default

* add option to ignore version

* update artifacts style

* fix reference

* fix spacing

* fix identation

* stop using pointers for vars

* add size to ignore map
  • Loading branch information
tashima42 authored May 8, 2024
1 parent e6f58e1 commit 2a55782
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 28 deletions.
44 changes: 23 additions & 21 deletions cmd/release/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import (
)

var (
k3sPrevMilestone *string
k3sMilestone *string

rke2PrevMilestone *string
rke2Milestone *string
artifactsIndexWriteToPath *string
concurrencyLimit *int
rancherMissingImagesJSONOutput *bool
k3sPrevMilestone string
k3sMilestone string

concurrencyLimit int
rancherMissingImagesJSONOutput bool
rke2PrevMilestone string
rke2Milestone string
rancherArtifactsIndexWriteToPath string
rancherArtifactsIndexIgnoreVersions []string
)

// generateCmd represents the generate command
Expand All @@ -44,7 +45,7 @@ var k3sGenerateReleaseNotesSubCmd = &cobra.Command{
ctx := context.Background()
client := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

notes, err := release.GenReleaseNotes(ctx, "k3s-io", "k3s", *k3sMilestone, *k3sPrevMilestone, client)
notes, err := release.GenReleaseNotes(ctx, "k3s-io", "k3s", k3sMilestone, k3sPrevMilestone, client)
if err != nil {
return err
}
Expand Down Expand Up @@ -85,7 +86,7 @@ var rke2GenerateReleaseNotesSubCmd = &cobra.Command{
ctx := context.Background()
client := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

notes, err := release.GenReleaseNotes(ctx, "rancher", "rke2", *rke2Milestone, *rke2PrevMilestone, client)
notes, err := release.GenReleaseNotes(ctx, "rancher", "rke2", rke2Milestone, rke2PrevMilestone, client)
if err != nil {
return err
}
Expand All @@ -105,7 +106,7 @@ var rancherGenerateArtifactsIndexSubCmd = &cobra.Command{
Use: "artifacts-index",
Short: "Generate artifacts index page",
RunE: func(cmd *cobra.Command, args []string) error {
return rancher.GeneratePrimeArtifactsIndex(*artifactsIndexWriteToPath)
return rancher.GeneratePrimeArtifactsIndex(rancherArtifactsIndexWriteToPath, rancherArtifactsIndexIgnoreVersions)
},
}

Expand All @@ -121,15 +122,15 @@ var rancherGenerateMissingImagesListSubCmd = &cobra.Command{
if !found {
return errors.New("verify your config file, version not found: " + version)
}
missingImages, err := rancher.GenerateMissingImagesList(version, *concurrencyLimit, rancherRelease.CheckImages)
missingImages, err := rancher.GenerateMissingImagesList(version, concurrencyLimit, rancherRelease.CheckImages)
if err != nil {
return err
}
// if there are missing images, return it as an error so CI also fails
if len(missingImages) != 0 && !*rancherMissingImagesJSONOutput {
if len(missingImages) != 0 && !rancherMissingImagesJSONOutput {
return errors.New("found missing images: " + strings.Join(missingImages, ","))
}
if *rancherMissingImagesJSONOutput {
if rancherMissingImagesJSONOutput {
b, err := json.MarshalIndent(missingImages, "", " ")
if err != nil {
return err
Expand All @@ -154,8 +155,8 @@ func init() {
generateCmd.AddCommand(rancherGenerateSubCmd)

// k3s release notes
k3sPrevMilestone = k3sGenerateReleaseNotesSubCmd.Flags().StringP("prev-milestone", "p", "", "Previous Milestone")
k3sMilestone = k3sGenerateReleaseNotesSubCmd.Flags().StringP("milestone", "m", "", "Milestone")
k3sGenerateReleaseNotesSubCmd.Flags().StringVarP(&k3sPrevMilestone, "prev-milestone", "p", "", "Previous Milestone")
k3sGenerateReleaseNotesSubCmd.Flags().StringVarP(&k3sMilestone, "milestone", "m", "", "Milestone")
if err := k3sGenerateReleaseNotesSubCmd.MarkFlagRequired("prev-milestone"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
Expand All @@ -166,8 +167,8 @@ func init() {
}

// rke2 release notes
rke2PrevMilestone = rke2GenerateReleaseNotesSubCmd.Flags().StringP("prev-milestone", "p", "", "Previous Milestone")
rke2Milestone = rke2GenerateReleaseNotesSubCmd.Flags().StringP("milestone", "m", "", "Milestone")
rke2GenerateReleaseNotesSubCmd.Flags().StringVarP(&rke2PrevMilestone, "prev-milestone", "p", "", "Previous Milestone")
rke2GenerateReleaseNotesSubCmd.Flags().StringVarP(&rke2Milestone, "milestone", "m", "", "Milestone")
if err := rke2GenerateReleaseNotesSubCmd.MarkFlagRequired("prev-milestone"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
Expand All @@ -178,13 +179,14 @@ func init() {
}

// rancher artifacts-index
artifactsIndexWriteToPath = rancherGenerateArtifactsIndexSubCmd.Flags().StringP("write-path", "w", "", "Write To Path")
rancherGenerateArtifactsIndexSubCmd.Flags().StringSliceVarP(&rancherArtifactsIndexIgnoreVersions, "ignore-versions", "i", []string{}, "Versions to ignore on the index")
rancherGenerateArtifactsIndexSubCmd.Flags().StringVarP(&rancherArtifactsIndexWriteToPath, "write-path", "w", "", "Write To Path")
if err := rancherGenerateArtifactsIndexSubCmd.MarkFlagRequired("write-path"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}

// rancher generate-missing-images-list
concurrencyLimit = rancherGenerateMissingImagesListSubCmd.Flags().IntP("concurrency-limit", "c", 3, "Concurrency Limit")
rancherMissingImagesJSONOutput = rancherGenerateMissingImagesListSubCmd.Flags().BoolP("json", "j", false, "JSON Output")
rancherGenerateMissingImagesListSubCmd.Flags().IntVarP(&concurrencyLimit, "concurrency-limit", "c", 3, "Concurrency Limit")
rancherGenerateMissingImagesListSubCmd.Flags().BoolVarP(&rancherMissingImagesJSONOutput, "json", "j", false, "JSON Output")
}
29 changes: 22 additions & 7 deletions release/rancher/rancher.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type registryAuthToken struct {
Token string `json:"token"`
}

func GeneratePrimeArtifactsIndex(path string) error {
func GeneratePrimeArtifactsIndex(path string, ignoreVersions []string) error {
client := ecmHTTP.NewClient(time.Second * 15)
resp, err := client.Get(rancherArtifactsListURL)
if err != nil {
Expand All @@ -97,7 +97,13 @@ func GeneratePrimeArtifactsIndex(path string) error {
if err := contentDecoder.Decode(&listBucket); err != nil {
return err
}
content := generateArtifactsIndexContent(listBucket)

ignore := make(map[string]bool, len(ignoreVersions))
for _, v := range ignoreVersions {
ignore[v] = true
}

content := generateArtifactsIndexContent(listBucket, ignore)
gaIndex, err := generatePrimeArtifactsHTML(content.GA)
if err != nil {
return err
Expand All @@ -112,7 +118,7 @@ func GeneratePrimeArtifactsIndex(path string) error {
return os.WriteFile(filepath.Join(path, "index-prerelease.html"), preReleaseIndex, 0644)
}

func generateArtifactsIndexContent(listBucket ListBucketResult) ArtifactsIndexContent {
func generateArtifactsIndexContent(listBucket ListBucketResult, ignoreVersions map[string]bool) ArtifactsIndexContent {
indexContent := ArtifactsIndexContent{
GA: ArtifactsIndexContentGroup{
Versions: []string{},
Expand All @@ -139,6 +145,10 @@ func generateArtifactsIndexContent(listBucket ListBucketResult) ArtifactsIndexCo
version := keyFile[0]
file := keyFile[1]

if _, ok := ignoreVersions[version]; ok {
continue
}

if _, ok := versionsFiles[version]; !ok {
versions = append(versions, version)
}
Expand Down Expand Up @@ -550,15 +560,15 @@ const artifactsIndexTempalte = `{{ define "release-artifacts-index" }}
<title>Rancher Prime Artifacts</title>
<link rel="icon" type="image/png" href="https://prime.ribs.rancher.io/assets/img/favicon.png">
<style>
body { font-family: Verdana, Geneneva; }
body { font-family: 'Courier New', monospace, Verdana, Geneneva; }
header { display: flex; flex-direction: row; justify-items: center; }
#rancher-logo { width: 200px; }
.project { margin-left: 20px; }
.release { margin-left: 40px; margin-bottom: 20px; }
.release h3 { margin-bottom: 0px; }
.files { margin-left: 60px; display: flex; flex-direction: column; }
.release-title { display: flex; flex-direction: row; }
.release-title-tag { margin-right: 20px; }
.release-title-tag { margin-right: 20px; min-width: 70px; }
.release-title-expand { background-color: #2453ff; color: white; border-radius: 5px; border: none; }
.release-title-expand:hover, .expand-active{ background-color: white; color: #2453ff; border: 1px solid #2453ff; }
.hidden { display: none; overflow: hidden; }
Expand All @@ -567,7 +577,7 @@ const artifactsIndexTempalte = `{{ define "release-artifacts-index" }}
<body>
<header>
<img src="https://prime.ribs.rancher.io/assets/img/rancher-suse-logo-horizontal-color.svg" alt="rancher logo" id="rancher-logo" />
<h1>Prime Artifacts</h1>
<h1>PRIME ARTIFACTS</h1>
</header>
<main>
<div class="project-rancher project">
Expand All @@ -578,7 +588,7 @@ const artifactsIndexTempalte = `{{ define "release-artifacts-index" }}
<b class="release-title-tag">{{ $version }}</b>
<button onclick="expand('{{ $version }}')" id="release-{{ $version }}-expand" class="release-title-expand">expand</button>
</div>
<div class="files hidden" id="release-{{ $version }}-files">
<div class="files" id="release-{{ $version }}-files">
<ul>
{{ range index $.VersionsFiles $version }}
<li><a href="{{ $.BaseURL }}/rancher/{{ $version }}/{{ . }}">{{ $.BaseURL }}/rancher/{{ $version }}/{{ . }}</a></li>
Expand All @@ -590,12 +600,17 @@ const artifactsIndexTempalte = `{{ define "release-artifacts-index" }}
</div>
</main>
<script>
hideFiles()
function expand(tag) {
const filesId = "release-" + tag + "-files"
const expandButtonId = "release-" + tag + "-expand"
document.getElementById(filesId).classList.toggle("hidden")
document.getElementById(expandButtonId).classList.toggle("expand-active")
}
function hideFiles() {
const fileDivs = document.querySelectorAll(".files")
fileDivs.forEach(f => f.classList.add("hidden"))
}
</script>
</body>
</html>
Expand Down

0 comments on commit 2a55782

Please sign in to comment.