-
Notifications
You must be signed in to change notification settings - Fork 88
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
CLOUDP-114066: [MongoCLI] The json file of the download center doesn’t contain the release version #1008
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c2e60f7
Fix bug download archive json
andreaangiolillo f518c06
Refactoring release/main.go to use flags
andreaangiolillo 08a73f5
Update main.go
andreaangiolillo 7bd2ad8
Refactoring
andreaangiolillo bd3f348
Refactoring
andreaangiolillo 5d4e85b
Refactoring
andreaangiolillo aca4ee4
Refactoring
andreaangiolillo 75c6b4e
Addressed PR comments
andreaangiolillo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"` | ||
|
@@ -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{ | ||
|
@@ -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 { | ||
|
@@ -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{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.") | ||
andreaangiolillo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}, | ||
) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jira.mongodb.org/browse/CLOUDP-114080