You've already forked go-semantic-release
feat(hooks): pass environment variables to hooks
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
changelogCmd.Flags().Bool("checks", false, "Check for missing values and envs")
|
||||
changelogCmd.Flags().StringP("out", "o", "CHANGELOG.md", "Name of the file")
|
||||
rootCmd.AddCommand(changelogCmd)
|
||||
}
|
||||
@@ -35,12 +36,12 @@ var changelogCmd = &cobra.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
|
||||
configChecks, err := cmd.Flags().GetBool("checks")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks)
|
||||
s, err := semanticrelease.New(readConfig(config), repository, configChecks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
hooksCmd.Flags().Bool("checks", false, "Check for missing values and envs")
|
||||
rootCmd.AddCommand(hooksCmd)
|
||||
}
|
||||
|
||||
@@ -29,14 +30,14 @@ var hooksCmd = &cobra.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
|
||||
configChecks, err := cmd.Flags().GetBool("checks")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
releaseConfig := readConfig(config)
|
||||
|
||||
s, err := semanticrelease.New(releaseConfig, repository, !ignoreConfigChecks)
|
||||
s, err := semanticrelease.New(releaseConfig, repository, configChecks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
lastCmd.Flags().Bool("checks", false, "Check for missing values and envs")
|
||||
rootCmd.AddCommand(lastCmd)
|
||||
}
|
||||
|
||||
@@ -30,12 +31,12 @@ var lastCmd = &cobra.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
|
||||
configChecks, err := cmd.Flags().GetBool("checks")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks)
|
||||
s, err := semanticrelease.New(readConfig(config), repository, configChecks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
nextCmd.Flags().Bool("checks", false, "Check for missing values and envs")
|
||||
rootCmd.AddCommand(nextCmd)
|
||||
}
|
||||
|
||||
@@ -30,12 +31,12 @@ var nextCmd = &cobra.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
|
||||
configChecks, err := cmd.Flags().GetBool("checks")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks)
|
||||
s, err := semanticrelease.New(readConfig(config), repository, configChecks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
releaseCmd.Flags().Bool("no-checks", false, "Ignore missing values and envs")
|
||||
rootCmd.AddCommand(releaseCmd)
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ func init() {
|
||||
rootCmd.PersistentFlags().StringP("loglevel", "l", "error", "Set loglevel")
|
||||
rootCmd.PersistentFlags().StringP("config", "c", ".release.yml", "Path to config file")
|
||||
rootCmd.PersistentFlags().Bool("no-cache", false, "Ignore cache, don't use in ci build")
|
||||
rootCmd.PersistentFlags().Bool("no-checks", false, "Ignore missing values and envs")
|
||||
}
|
||||
|
||||
func readConfig(file string) *config.ReleaseConfig {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
setCmd.Flags().Bool("checks", false, "Check for missing values and envs")
|
||||
rootCmd.AddCommand(setCmd)
|
||||
}
|
||||
|
||||
@@ -26,12 +27,12 @@ var setCmd = &cobra.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
|
||||
configChecks, err := cmd.Flags().GetBool("checks")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks)
|
||||
s, err := semanticrelease.New(readConfig(config), repository, configChecks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
zipCmd.Flags().Bool("checks", false, "Check for missing values and envs")
|
||||
zipCmd.Flags().StringP("algorithm", "a", "sha256", "Algorithm for checksum (crc32,md5,sha1,sha224,sha384,sha256,sha512)")
|
||||
rootCmd.AddCommand(zipCmd)
|
||||
}
|
||||
@@ -24,12 +25,12 @@ var zipCmd = &cobra.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
|
||||
configChecks, err := cmd.Flags().GetBool("checks")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks)
|
||||
s, err := semanticrelease.New(readConfig(config), repository, configChecks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,13 +2,16 @@ package hooks
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
//Hooks struct
|
||||
@@ -61,17 +64,29 @@ func (h *Hooks) runCommand(command string) error {
|
||||
cmd = exec.Command("sh", "-c", cmdReplaced)
|
||||
}
|
||||
|
||||
cmd.Env = os.Environ()
|
||||
cmd.Env = append(cmd.Env, "RELEASE_VERSION="+h.version.Next.Version.String())
|
||||
cmdReader, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h.printOutput(cmdReader, strings.Fields(cmdReplaced)[0])
|
||||
|
||||
cmdErrReader, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h.printOutput(cmdErrReader, strings.Fields(cmdReplaced)[0])
|
||||
|
||||
scanner := bufio.NewScanner(cmdReader)
|
||||
go func() {
|
||||
for scanner.Scan() {
|
||||
log.WithField("cmd", strings.Fields(cmdReplaced)[0]).Infof("%s\n", scanner.Text())
|
||||
}
|
||||
}()
|
||||
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func (h *Hooks) printOutput(read io.ReadCloser, cmd string) {
|
||||
scanner := bufio.NewScanner(read)
|
||||
go func() {
|
||||
for scanner.Scan() {
|
||||
log.WithField("cmd", cmd).Infof("%s\n", scanner.Text())
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ func (g *Client) makeRelease(releaseVersion *shared.ReleaseVersion, generatedCha
|
||||
return fmt.Errorf("could not create release: %s", err.Error())
|
||||
}
|
||||
g.release = release
|
||||
g.log.Debugf("Release repsone: %+v", *release)
|
||||
g.log.Infof("Crated release")
|
||||
g.log.Debugf("Release response: %+v", *release)
|
||||
g.log.Infof("Created release")
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user