feat: auto tag and git push
parent
c827c4d72c
commit
7840343cd4
|
@ -9,7 +9,6 @@ run:
|
||||||
- ".*Mock.*"
|
- ".*Mock.*"
|
||||||
- ".*_mock.*"
|
- ".*_mock.*"
|
||||||
- ".*_generated.*"
|
- ".*_generated.*"
|
||||||
go: "1.18"
|
|
||||||
|
|
||||||
output:
|
output:
|
||||||
sort-results: true
|
sort-results: true
|
||||||
|
@ -17,21 +16,18 @@ output:
|
||||||
linters:
|
linters:
|
||||||
disable-all: true
|
disable-all: true
|
||||||
enable:
|
enable:
|
||||||
- deadcode
|
|
||||||
- errcheck
|
- errcheck
|
||||||
- gosimple
|
- gosimple
|
||||||
- govet
|
- govet
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- typecheck
|
- typecheck
|
||||||
- unused
|
- unused
|
||||||
- varcheck
|
|
||||||
- errname
|
- errname
|
||||||
- errorlint
|
- errorlint
|
||||||
- execinquery
|
- execinquery
|
||||||
- goerr113
|
- goerr113
|
||||||
- gofumpt
|
- gofumpt
|
||||||
- gosec
|
- gosec
|
||||||
- ifshort
|
|
||||||
- importas
|
- importas
|
||||||
- makezero
|
- makezero
|
||||||
- nilnil
|
- nilnil
|
||||||
|
@ -66,9 +62,4 @@ linters-settings:
|
||||||
- unreachable
|
- unreachable
|
||||||
- unusedresult
|
- unusedresult
|
||||||
staticcheck:
|
staticcheck:
|
||||||
go: "1.18"
|
|
||||||
checks: ["all", "-SA1019"]
|
checks: ["all", "-SA1019"]
|
||||||
|
|
||||||
issues:
|
|
||||||
new: true
|
|
||||||
fix: true
|
|
||||||
|
|
|
@ -19,18 +19,20 @@ const (
|
||||||
|
|
||||||
type action struct {
|
type action struct {
|
||||||
flags struct {
|
flags struct {
|
||||||
scopes map[string]struct{}
|
scopes map[string]struct{}
|
||||||
output string
|
output string
|
||||||
from string
|
from string
|
||||||
to string
|
to string
|
||||||
version string
|
version string
|
||||||
repository string
|
repository string
|
||||||
filename string
|
filename string
|
||||||
filetype string
|
filetype string
|
||||||
verbose bool
|
verbose bool
|
||||||
dryRun bool
|
dryRun bool
|
||||||
interactive bool
|
interactive bool
|
||||||
autoCommit bool
|
autoGitCommit bool
|
||||||
|
autoGitTag bool
|
||||||
|
autoGitPush bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +77,9 @@ func (a *action) getFlags(c *cli.Context) {
|
||||||
|
|
||||||
a.flags.dryRun = c.Bool(flagDryRunName)
|
a.flags.dryRun = c.Bool(flagDryRunName)
|
||||||
a.flags.interactive = c.Bool(flagInteractiveName)
|
a.flags.interactive = c.Bool(flagInteractiveName)
|
||||||
a.flags.autoCommit = c.Bool(flagAutoCommitName)
|
a.flags.autoGitCommit = c.Bool(flagAutoGitCommitName)
|
||||||
|
a.flags.autoGitTag = c.Bool(flagAutoGitTagName)
|
||||||
|
a.flags.autoGitPush = c.Bool(flagAutoGitPushName)
|
||||||
|
|
||||||
a.log("Flags %+v\n", a.flags)
|
a.log("Flags %+v\n", a.flags)
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,24 +70,8 @@ func (a *action) RunGenerate(c *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.flags.autoCommit {
|
if err := a.doGit(finalOutput, version); err != nil {
|
||||||
commitMsg := fmt.Sprintf(autoCommitMessageTemplate, version)
|
return err
|
||||||
|
|
||||||
// TODO: disable until https://github.com/go-git/go-git/issues/180 is fixed
|
|
||||||
// if err := repo.Commit(commitMsg, finalOutput); err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
cmdOutput, err := exec.CommandContext(c.Context, "git", "add", finalOutput).CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
a.log("Git add output:\n%s", cmdOutput)
|
|
||||||
|
|
||||||
cmdOutput, err = exec.CommandContext(c.Context, "git", "commit", "-m", commitMsg).CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
a.log("Git commit output:\n%s", cmdOutput)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -210,3 +194,53 @@ func (a *action) generateRSTChangelog(output, version string, commits []conventi
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *action) doGit(finalOutput, version string) error {
|
||||||
|
if !a.flags.autoGitCommit {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: disable until https://github.com/go-git/go-git/issues/180 is fixed
|
||||||
|
// if err := repo.Commit(commitMsg, finalOutput); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
cmdOutput, err := exec.Command("git", "add", finalOutput).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
a.log("Git add output:\n%s", cmdOutput)
|
||||||
|
|
||||||
|
commitMsg := fmt.Sprintf(autoCommitMessageTemplate, version)
|
||||||
|
|
||||||
|
cmdOutput, err = exec.Command("git", "commit", "-m", commitMsg).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
a.log("Git commit output:\n%s", cmdOutput)
|
||||||
|
|
||||||
|
if a.flags.autoGitTag {
|
||||||
|
cmdOutput, err = exec.Command("git", "tag", version).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
a.log("Git tag output:\n%s", cmdOutput)
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.flags.autoGitPush {
|
||||||
|
cmdOutput, err = exec.Command("git", "push").CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
a.log("Git push output:\n%s", cmdOutput)
|
||||||
|
|
||||||
|
if a.flags.autoGitTag {
|
||||||
|
cmdOutput, err = exec.Command("git", "push", "origin", version).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
a.log("Git push tag output:\n%s", cmdOutput)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -47,8 +47,14 @@ const (
|
||||||
flagInteractiveName = "interactive"
|
flagInteractiveName = "interactive"
|
||||||
flagInteractiveUsage = "interactive mode"
|
flagInteractiveUsage = "interactive mode"
|
||||||
|
|
||||||
flagAutoCommitName = "auto-commit"
|
flagAutoGitCommitName = "auto-commit"
|
||||||
flagAutoCommitUsage = "enable auto commit after generating changelog"
|
flagAutoGitCommitUsage = "enable auto git commit after generating changelog"
|
||||||
|
|
||||||
|
flagAutoGitTagName = "auto-tag"
|
||||||
|
flagAutoGitTagUsage = "enable auto git tag after generating changelog, only works if auto-commit is enabled"
|
||||||
|
|
||||||
|
flagAutoGitPushName = "auto-push"
|
||||||
|
flagAutoGitPushUsage = "enable auto git push after generating changelog, only works if auto-commit is enabled, if auto-tag is enabled will auto git push tag too"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -120,8 +126,8 @@ func NewApp() *App {
|
||||||
Aliases: flagInteractiveAliases,
|
Aliases: flagInteractiveAliases,
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: flagAutoCommitName,
|
Name: flagAutoGitCommitName,
|
||||||
Usage: flagAutoCommitUsage,
|
Usage: flagAutoGitCommitUsage,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: a.RunGenerate,
|
Action: a.RunGenerate,
|
||||||
|
|
Loading…
Reference in New Issue