mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
New commands & refectoring * fnctl: refactor code to improve reuse between commands build, bump and publish (formerly update) share a lot of code, this refactor ensure their logic are correctly reused. It renames update to publish, so it would be a strong diff between "update" and build. * fnctl: remove unnecessary dependency for build and bump * fnctl: improve code reuse between bump, build and publish Unify the use of walker function in all these three commands and drop dry-run support. * Code grooming - errcheck * fnctl: update README.md to be in sync with actual execution output * fnctl: move scan function to commoncmd structure * fnctl: change verbose flag handling does not use global variable anymore
74 lines
1.5 KiB
Go
74 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
bumper "github.com/giantswarm/semver-bump/bump"
|
|
"github.com/giantswarm/semver-bump/storage"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
var (
|
|
initialVersion = "0.0.1"
|
|
|
|
errVersionFileNotFound = errors.New("no VERSION file found for this function")
|
|
)
|
|
|
|
func bump() cli.Command {
|
|
cmd := bumpcmd{commoncmd: &commoncmd{}}
|
|
flags := append([]cli.Flag{}, cmd.flags()...)
|
|
return cli.Command{
|
|
Name: "bump",
|
|
Usage: "bump function version",
|
|
Flags: flags,
|
|
Action: cmd.scan,
|
|
}
|
|
}
|
|
|
|
type bumpcmd struct {
|
|
*commoncmd
|
|
}
|
|
|
|
func (b *bumpcmd) scan(c *cli.Context) error {
|
|
b.commoncmd.scan(b.walker)
|
|
return nil
|
|
}
|
|
|
|
func (b *bumpcmd) walker(path string, info os.FileInfo, err error, w io.Writer) error {
|
|
walker(path, info, err, w, b.bump)
|
|
return nil
|
|
}
|
|
|
|
// bump will take the found valid function and bump its version
|
|
func (b *bumpcmd) bump(path string) error {
|
|
fmt.Fprintln(b.verbwriter, "bumping version for", path)
|
|
|
|
dir := filepath.Dir(path)
|
|
versionfile := filepath.Join(dir, "VERSION")
|
|
if _, err := os.Stat(versionfile); os.IsNotExist(err) {
|
|
return errVersionFileNotFound
|
|
}
|
|
|
|
s, err := storage.NewVersionStorage("file", initialVersion)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
version := bumper.NewSemverBumper(s, versionfile)
|
|
newver, err := version.BumpPatchVersion("", "")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := ioutil.WriteFile(versionfile, []byte(newver.String()), 0666); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|