Skip to content

Commit

Permalink
Configure author for Git commit step (#2712)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay-krishna authored Dec 5, 2023
1 parent f55f4d5 commit 727cbca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
15 changes: 15 additions & 0 deletions tools/version-tracker/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const (
BaseRepoOwnerEnvvar = "BASE_REPO_OWNER"
HeadRepoOwnerEnvvar = "HEAD_REPO_OWNER"
GitHubTokenEnvvar = "GITHUB_TOKEN"
CommitAuthorNameEnvvar = "COMMIT_AUTHOR_NAME"
CommitAuthorEmailEnvvar = "COMMIT_AUTHOR_EMAIL"
DefaultCommitAuthorName = "EKS Distro PR Bot"
DefaultCommitAuthorEmail = "[email protected]"
BuildToolingRepoName = "eks-anywhere-build-tooling"
BuildToolingRepoURL = "https://github.com/aws/eks-anywhere-build-tooling"
ReadmeFile = "README.md"
Expand Down Expand Up @@ -49,6 +53,12 @@ var (
BinaryName: "cmctl",
Extract: true,
},
"containerd/containerd": {
AssetName: "containerd-%s-linux-amd64.tar.gz",
BinaryName: "bin/containerd",
Extract: true,
TrimLeadingVersionPrefix: true,
},
"fluxcd/flux2": {
AssetName: "flux_%s_linux_amd64.tar.gz",
BinaryName: "flux",
Expand Down Expand Up @@ -76,6 +86,11 @@ var (
BinaryName: "kind-linux-amd64",
Extract: false,
},
"opencontainers/runc": {
AssetName: "runc.amd64",
BinaryName: "runc.amd64",
Extract: false,
},
"rancher/local-path-provisioner": {
AssetName: "local-path-provisioner-amd64",
BinaryName: "local-path-provisioner-amd64",
Expand Down
19 changes: 18 additions & 1 deletion tools/version-tracker/pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/transport/http"

"github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/constants"
Expand Down Expand Up @@ -54,6 +55,7 @@ func CloneRepo(cloneURL, destination, headRepoOwner string) (*git.Repository, st
}
}
}

return repo, repoHeadCommitHash, nil
}

Expand Down Expand Up @@ -101,7 +103,22 @@ func Add(worktree *git.Worktree, paths []string) error {
// Commit creates a new commit with the given commit message.
func Commit(worktree *git.Worktree, commitMessage string) error {
logger.V(6).Info("Committing file(s) in the index")
_, err := worktree.Commit(commitMessage, &git.CommitOptions{})
var commitAuthorName, commitAuthorEmail string
commitAuthorName, ok := os.LookupEnv(constants.CommitAuthorNameEnvvar)
if !ok {
commitAuthorName = constants.DefaultCommitAuthorName
}

commitAuthorEmail, ok = os.LookupEnv(constants.CommitAuthorEmailEnvvar)
if !ok {
commitAuthorEmail = constants.DefaultCommitAuthorEmail
}
_, err := worktree.Commit(commitMessage, &git.CommitOptions{
Author: &object.Signature{
Name: commitAuthorName,
Email: commitAuthorEmail,
},
})
if err != nil {
return fmt.Errorf("committing file(s) in the index: %v", err)
}
Expand Down

0 comments on commit 727cbca

Please sign in to comment.