Skip to content

Commit

Permalink
Allow getting versions for any package. (#2935)
Browse files Browse the repository at this point in the history
## Summary

Add an option to support version checking for arbitrary packages. This would allow us to deploy indexer releases at `algorand-releases/<channel>/indexer-*`

## Test Plan

Ran the command and see the correct regex:
```
~$ updater ver check -c nightly -p indexer
Checking for files matching: 'channel/nightly/indexer_nightly_linux-amd64_' in bucket algorand-releases
no updates found for channel 'nightly'
```
  • Loading branch information
winder authored Oct 26, 2021
1 parent ca3e877 commit 9bb4154
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
14 changes: 10 additions & 4 deletions cmd/updater/versionCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,26 @@ import (
var (
destFile string
versionBucket string
packageName string
specificVersion uint64
semanticOutput bool
)

// DefaultPackageName is the package we'll use by default.
const DefaultPackageName = "node"

func init() {
versionCmd.AddCommand(checkCmd)
versionCmd.AddCommand(getCmd)

checkCmd.Flags().StringVarP(&versionBucket, "bucket", "b", "", "S3 bucket containing updates.")
checkCmd.Flags().BoolVarP(&semanticOutput, "semantic", "s", false, "Human readable semantic version output.")
checkCmd.Flags().StringVarP(&packageName, "package", "p", DefaultPackageName, "Get version of specific package.")
checkCmd.Flags().StringVarP(&versionBucket, "bucket", "b", "", "S3 bucket containing updates.")

getCmd.Flags().StringVarP(&destFile, "outputFile", "o", "", "Path for downloaded file (required).")
getCmd.Flags().StringVarP(&versionBucket, "bucket", "b", "", "S3 bucket containing updates.")
getCmd.Flags().Uint64VarP(&specificVersion, "version", "v", 0, "Specific version to download.")
getCmd.Flags().StringVarP(&packageName, "package", "p", DefaultPackageName, "Get version of specific package.")
getCmd.Flags().StringVarP(&versionBucket, "bucket", "b", "", "S3 bucket containing updates.")
getCmd.MarkFlagRequired("outputFile")
}

Expand All @@ -67,7 +73,7 @@ var checkCmd = &cobra.Command{
if err != nil {
exitErrorf("Error creating s3 session %s\n", err.Error())
} else {
version, _, err := s3Session.GetLatestUpdateVersion(channel)
version, _, err := s3Session.GetPackageVersion(channel, packageName, 0)
if err != nil {
exitErrorf("Error getting latest version from s3 %s\n", err.Error())
}
Expand Down Expand Up @@ -102,7 +108,7 @@ var getCmd = &cobra.Command{
if err != nil {
exitErrorf("Error creating s3 session %s\n", err.Error())
} else {
version, name, err := s3Session.GetUpdateVersion(channel, specificVersion)
version, name, err := s3Session.GetPackageVersion(channel, packageName, specificVersion)
if err != nil {
exitErrorf("Error getting latest version from s3 %s\n", err.Error())
}
Expand Down
11 changes: 0 additions & 11 deletions util/s3/s3Helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ func makeS3Session(credentials *credentials.Credentials, bucket string) (helper
return
}

// GetLatestUpdateVersion returns the latest version details for the 'node' package
func (helper *Helper) GetLatestUpdateVersion(channel string) (maxVersion uint64, maxVersionName string, err error) {
return helper.GetUpdateVersion(channel, 0)
}

// GetLatestPackageVersion returns the latest version details for a given package name (eg node, install, tools)
func (helper *Helper) GetLatestPackageVersion(channel string, packageName string) (maxVersion uint64, maxVersionName string, err error) {
return helper.GetPackageVersion(channel, packageName, 0)
Expand All @@ -214,12 +209,6 @@ func (helper *Helper) GetLatestPackageFilesVersion(channel string, packagePrefix
return helper.GetPackageFilesVersion(channel, packagePrefix, 0)
}

// GetUpdateVersion ensures the specified version is present and returns the name of the file, if found
// Or if specificVersion == 0, returns the name of the file with the max version
func (helper *Helper) GetUpdateVersion(channel string, specificVersion uint64) (maxVersion uint64, maxVersionName string, err error) {
return helper.GetPackageVersion(channel, "node", specificVersion)
}

// DownloadFile downloads the specified file to the provided Writer
func (helper *Helper) DownloadFile(name string, writer io.WriterAt) error {
downloader := s3manager.NewDownloader(helper.session)
Expand Down

0 comments on commit 9bb4154

Please sign in to comment.