Skip to content

Commit

Permalink
update: github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
KarolosLykos committed Feb 1, 2022
1 parent 892e267 commit 8f0b6f2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/init.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Initialize

on: [create]
on: [push]

jobs:
init:
Expand All @@ -19,8 +19,9 @@ jobs:
go get
go mod tidy
go run ./setup/main.go
rm -fr ./github/workflows/init.yml
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
commit-message: initial setup
run: |
git config --global user.name YOUR_NAME
git config --global user.email YOUR_EMAIL
git commit -am "Automated report"
git push
31 changes: 31 additions & 0 deletions setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func main() {
fmt.Println("CLI Template Setup")

originURL := detectOriginURL()
originalName, originalEmail := detectOriginUser()

projectParts := strings.Split(strings.TrimPrefix(originURL, "https://github.com/"), "/")
repoUser := projectParts[0]
Expand Down Expand Up @@ -42,6 +43,9 @@ func main() {
replaceAllInFile("./cmd/root.go", `Use: "cli-template",`, fmt.Sprintf(`Use: "%s",`, project.Reponame))
replaceAllInFile("./README.md", cliTemplatePath, project.ProjectName)

replaceAllInFile("./github/workflows/init.yml", "YOUR_NAME", originalName)
replaceAllInFile("./github/workflows/init.yml", "YOUR_EMAIL", originalEmail)

if err := os.RemoveAll(getPathTo("./setup")); err != nil {
panic(err)
}
Expand All @@ -58,6 +62,33 @@ func walkOverExt(exts string, f func(path string)) {
})
}

func detectOriginUser() (name, email string) {
out, err := exec.Command("git", "config", "--list").Output()
if err != nil {
panic(err)
}
fmt.Printf("Git output:\n%s", string(out))

output := string(out)

for _, s := range strings.Split(output, "\n") {
s = strings.TrimSpace(s)
if strings.HasPrefix(s, "user.name") {
name = strings.TrimSpace(strings.TrimPrefix(s, "user.name="))
}

if strings.HasPrefix(s, "user.email") {
email = strings.TrimSpace(strings.TrimPrefix(s, "user.email="))
}

if name != "" && email != "" {
return
}
}

return
}

func detectOriginURL() (url string) {
out, err := exec.Command("git", "remote", "-v").Output()
if err != nil {
Expand Down

0 comments on commit 8f0b6f2

Please sign in to comment.