Skip to content

Commit

Permalink
output commit hash & message during to execute 'deploy' command
Browse files Browse the repository at this point in the history
  • Loading branch information
ShotaKitazawa committed Jul 22, 2022
1 parent 13b4a13 commit 07f03e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ func runDeploy(
}
}
}
// Print CommitHash & CommitMessage
hash, msg, err := repo.GetHeadInfo(ctx)
if err != nil {
return err
}
fmt.Printf("hash: %s\nmessage: %s\n\n", hash, msg)
// Set deployers
deployers, err := newDeployersFunc(logger, template.New(conf.GitRevision), conf.LocalRepoPath, isucontinuous.Hosts)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions pkg/localrepo/localrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type LocalRepoIface interface {
GetRevision(ctx context.Context) (string, error)
SetRevision(ctx context.Context, revision string) error
ClearRevision(ctx context.Context) error
GetHeadInfo(ctx context.Context) (string, string, error)
}

type LocalRepo struct {
Expand Down Expand Up @@ -229,3 +230,17 @@ func (l *LocalRepo) SetRevision(ctx context.Context, revision string) error {
func (l *LocalRepo) ClearRevision(ctx context.Context) error {
return os.Remove(filepath.Join(l.absPath, revisionStoreFilename))
}

func (l *LocalRepo) GetHeadInfo(ctx context.Context) (string, string, error) {
stdout, stderr, err := l.shell.Exec(ctx, l.absPath, "git rev-parse HEAD")
if err != nil {
return "", "", myerrors.NewErrorCommandExecutionFailed(stderr)
}
hash := stdout.String()
stdout, stderr, err = l.shell.Exec(ctx, l.absPath, "git log -1 --pretty=%B")
if err != nil {
return "", "", myerrors.NewErrorCommandExecutionFailed(stderr)
}
msg := stdout.String()
return hash, msg, nil
}

0 comments on commit 07f03e5

Please sign in to comment.