Skip to content

CLOUDP-114066: [MongoCLI] The json file of the download center doesn’t contain the release version #1008

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 8 commits into from
Mar 1, 2022
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: 1 addition & 3 deletions build/ci/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ functions:
export GOROOT="${go_root}"
export PATH="./bin:${go_bin}:$PATH"

VERSION=$(git describe | cut -d "v" -f 2)

go run ../internal/release/main.go "${VERSION}" "${FEED_FILE_NAME}"
go run ../internal/release/main.go --version "$(git describe | cut -d "v" -f 2)" --file "${FEED_FILE_NAME}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git describe may not work anymore with a mono repo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the JSON files generated by the package tasks it seems to work properly

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have also made some tests locally and on evergreen and I haven’t found any issue with git describe

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry what I mean is that git describe will get you the latest tag, for now it works since we only release one thing, this may become flaky later

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification!
I don't think this is an issue: you are right that the tag returned by git describe will be different when releasing atlascli v0.0.1 as the mongocli.json file will contain the version 0.0.1 when running the packaging tasks. However, this won't happen when running releasing tasks as the latest tag will always be the correct one. Let me know if I am missing something here. Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not missing much and why I say may become flaky, race conditions may happen if releasing both the same day

Also this leaves us in a position where master json files will always point to latest, ie, when we do 0.0.1 of atlas we'll have the mongocli json with 0.0.1 as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to create a ticket to see how to fix this issue. I will start working on it once I have pre-released atlascli

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"upload dist":
- command: s3.put
params:
Expand Down
1 change: 1 addition & 0 deletions internal/flag/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,5 @@ const (
WithoutDefaultAlertSettings = "withoutDefaultAlertSettings" // WithoutDefaultAlertSettings flag
CurrentIP = "currentIp" // CurrentIP flag
Gov = "gov" // Gov flag
Version = "version" // Version flag
)
49 changes: 38 additions & 11 deletions internal/release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ import (
"os"
"strings"
"time"

"github.com/mongodb/mongocli/internal/flag"
"github.com/spf13/cobra"
)

const mongocli = "mongocli"

type Opts struct {
fileName string
version string
}

type DownloadArchive struct {
PreviousReleasesLink string `json:"previous_releases_link"`
ReleaseDate time.Time `json:"release_date"`
Expand Down Expand Up @@ -51,21 +59,21 @@ type Link struct {
Name string `json:"name"`
}

func newPlatform(tool, version, arch, system, distro string, formats []string) *Platform {
func newPlatform(packageName, version, arch, system, distro string, formats []string) *Platform {
p := &Platform{}
p.Arch = arch
p.OS = distro

links := make([]Link, len(formats))
for i, f := range formats {
links[i] = Link{
DownloadLink: fmt.Sprintf("https://fastdl.mongodb.org/mongocli/%s_%s_%s_%s.%s", tool, version, system, arch, f),
DownloadLink: fmt.Sprintf("https://fastdl.mongodb.org/mongocli/%s_%s_%s_%s.%s", packageName, version, system, arch, f),
Name: f,
}
}

title := "MongoDB Atlas CLI"
if tool == mongocli {
if packageName == mongocli {
title = "MongoDB CLI"
}
p.Packages = Package{
Expand All @@ -76,17 +84,11 @@ func newPlatform(tool, version, arch, system, distro string, formats []string) *
}

func main() {
version := os.Args[1]
feedFilename := os.Args[2]
fmt.Printf("Generating JSON: %s\n", feedFilename)
err := generateFile(feedFilename, version)

if err != nil {
cmd := Builder()
if err := cmd.Execute(); err != nil {
fmt.Printf("error encoding file: %v\n", err)

os.Exit(1)
}
fmt.Printf("File %s has been generated\n", feedFilename)
}

func generateFile(name, version string) error {
Expand Down Expand Up @@ -119,3 +121,28 @@ func generateFile(name, version string) error {
jsonEncoder.SetIndent("", " ")
return jsonEncoder.Encode(downloadArchive)
}

func Builder() *cobra.Command {
opts := Opts{}
cmd := &cobra.Command{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[non-blocking] using cobra for this is an overkill if you ask me, you could've used pflags with no need to bring cobra as well

Use: "main",
Short: "Generate the download center json file",
Example: `
Generate the download center json file for mongocli
$ main --version 1.23.0 --file mongocli.json`,
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Printf("Generating JSON: %s\n", opts.fileName)
return generateFile(opts.fileName, opts.version)
},
PostRun: func(cmd *cobra.Command, args []string) {
fmt.Printf("File %s has been generated\n", opts.fileName)
},
}

cmd.Flags().StringVar(&opts.version, flag.Version, "", "release version.")
cmd.Flags().StringVar(&opts.fileName, flag.File, "mongocli.json", "file name of the download center json file.")

_ = cmd.MarkFlagFilename(flag.File)
_ = cmd.MarkFlagRequired(flag.Version)
return cmd
}
34 changes: 34 additions & 0 deletions internal/release/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2022 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build unit
// +build unit

package main

import (
"testing"

"github.com/mongodb/mongocli/internal/flag"
"github.com/mongodb/mongocli/internal/test"
)

func TestBuilder(t *testing.T) {
test.CmdValidator(
t,
Builder(),
0,
[]string{flag.Version, flag.File},
)
}