Skip to content

Commit

Permalink
Add gitWebBuild()
Browse files Browse the repository at this point in the history
  • Loading branch information
nomeguy committed Oct 5, 2023
1 parent 08bbace commit d4ce580
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
40 changes: 39 additions & 1 deletion run/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
)

func gitClone(repoUrl string, path string) {
Expand Down Expand Up @@ -66,12 +67,49 @@ func gitApply(path string, patch string) {
}
}

func gitPull(path string) {
func gitGetLatestCommitHash(path string) string {
cmd := exec.Command("git", "rev-parse", "HEAD")
cmd.Dir = path
out, err := cmd.Output()
if err != nil {
panic(err)
}
return string(out)
}

func gitPull(path string) bool {
oldHash := gitGetLatestCommitHash(path)

cmd := exec.Command("git", "pull")
cmd.Dir = path
out, err := cmd.CombinedOutput()
println(out)
if err != nil {
panic(err)
}

newHash := gitGetLatestCommitHash(path)
affected := oldHash != newHash
return affected
}

func runCmd(dir, name string, args ...string) error {
cmd := exec.Command(name, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = dir
return cmd.Run()
}

func gitWebBuild(path string) {
webDir := filepath.Join(path, "web")
err := runCmd(webDir, "yarn", "install")
if err != nil {
panic(err)
}

err = runCmd(webDir, "yarn", "build")
if err != nil {
panic(err)
}
}
5 changes: 4 additions & 1 deletion run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ func CreateRepo(siteName string, needStart bool, diff string) {
gitApply(path, diff)
}
} else {
gitPull(path)
affected := gitPull(path)
if affected {
gitWebBuild(path)
}
}

if needStart {
Expand Down

0 comments on commit d4ce580

Please sign in to comment.