feat: auto tag and git push

main
sudo pacman -Syu 2022-09-04 22:44:57 +07:00
parent c827c4d72c
commit 7840343cd4
No known key found for this signature in database
GPG Key ID: D6CB5C6C567C47B0
4 changed files with 79 additions and 44 deletions

View File

@ -9,7 +9,6 @@ run:
- ".*Mock.*"
- ".*_mock.*"
- ".*_generated.*"
go: "1.18"
output:
sort-results: true
@ -17,21 +16,18 @@ output:
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gosimple
- govet
- staticcheck
- typecheck
- unused
- varcheck
- errname
- errorlint
- execinquery
- goerr113
- gofumpt
- gosec
- ifshort
- importas
- makezero
- nilnil
@ -66,9 +62,4 @@ linters-settings:
- unreachable
- unusedresult
staticcheck:
go: "1.18"
checks: ["all", "-SA1019"]
issues:
new: true
fix: true

View File

@ -19,18 +19,20 @@ const (
type action struct {
flags struct {
scopes map[string]struct{}
output string
from string
to string
version string
repository string
filename string
filetype string
verbose bool
dryRun bool
interactive bool
autoCommit bool
scopes map[string]struct{}
output string
from string
to string
version string
repository string
filename string
filetype string
verbose bool
dryRun bool
interactive 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.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)
}

View File

@ -70,24 +70,8 @@ func (a *action) RunGenerate(c *cli.Context) error {
return err
}
if a.flags.autoCommit {
commitMsg := fmt.Sprintf(autoCommitMessageTemplate, version)
// 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)
if err := a.doGit(finalOutput, version); err != nil {
return err
}
return nil
@ -210,3 +194,53 @@ func (a *action) generateRSTChangelog(output, version string, commits []conventi
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
}

View File

@ -47,8 +47,14 @@ const (
flagInteractiveName = "interactive"
flagInteractiveUsage = "interactive mode"
flagAutoCommitName = "auto-commit"
flagAutoCommitUsage = "enable auto commit after generating changelog"
flagAutoGitCommitName = "auto-commit"
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 (
@ -120,8 +126,8 @@ func NewApp() *App {
Aliases: flagInteractiveAliases,
},
&cli.BoolFlag{
Name: flagAutoCommitName,
Usage: flagAutoCommitUsage,
Name: flagAutoGitCommitName,
Usage: flagAutoGitCommitUsage,
},
},
Action: a.RunGenerate,