Skip to content

Commit

Permalink
chore(verify): verifies region versions
Browse files Browse the repository at this point in the history
Verify will retrieve the latest regions version and if has the same
version.
  • Loading branch information
faabiosr committed May 5, 2024
1 parent 450136c commit b77d206
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func newCmd() *cli.App {
return nil
}

app.Commands = commands(bumpCmd)
app.Commands = commands(bumpCmd, verifyCmd)

return app
}
Expand Down
69 changes: 69 additions & 0 deletions cmd/verify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) Fabio da Silva Ribeiro <faabiosr@gmail.com>
* SPDX-License-Identifier: MIT
*/

package cmd

import (
"errors"
"fmt"
"slices"

"github.com/aws/aws-sdk-go-v2/config"
"github.com/urfave/cli/v2"

"github.com/faabiosr/lb/internal"
)

var verifyCmd = &cli.Command{
Name: "verify",
Description: "verifies layer latest versions across regions",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "regions",
Aliases: []string{"r"},
Usage: "list of regions separated by comma.",
Required: true,
},
},
ArgsUsage: "layer-name",
Action: func(cc *cli.Context) error {
name := cc.Args().First()
if name == "" {
return errors.New(`required argument "layer-name" not set`)
}

regions := cc.StringSlice("regions")
if len(regions) <= 1 {
return errors.New(`required flag "regions" must contain at least two regions`)
}

cfg, err := config.LoadDefaultConfig(cc.Context)
if err != nil {
return fmt.Errorf("failed to load aws config: %w", err)
}

l := internal.LoadLayer(cfg, name)

versions, err := l.LatestVersions(cc.Context, regions)
if err != nil {
return err
}

bumped := slices.CompactFunc(versions, func(c, v *internal.Version) bool {
return c.Number == v.Number
})

if len(bumped) == 1 && bumped[0].Number == 0 {
return errors.New("there are no published versions")
}

if len(bumped) > 1 {
return errors.New(`some regions are not bumped`)
}

fmt.Fprintln(cc.App.Writer, "all regions bumped")
return nil
},
}

0 comments on commit b77d206

Please sign in to comment.