print commit logs back to remote git
This commit is contained in:
parent
2217f13972
commit
e02edb878f
1 changed files with 27 additions and 51 deletions
78
main.go
78
main.go
|
@ -57,8 +57,8 @@ func isPublished(gitRepoPath, gitIndexPath, prevcommit, lastcommit string) bool
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func hugoLogs(logLines string, lines []string, hugoInstance string) string {
|
func hugoLogs(logLines string, lines []string) string {
|
||||||
logLines = logLines + fmt.Sprintf("~~~~~~~~~~ Hugo's logs %s ~~~~~~~~~~\n", hugoInstance)
|
logLines = logLines + "~~~~~~~~~~ Hugo's logs ~~~~~~~~~~\n"
|
||||||
for _, d := range lines {
|
for _, d := range lines {
|
||||||
logLines = logLines + d + "\n"
|
logLines = logLines + d + "\n"
|
||||||
|
|
||||||
|
@ -92,7 +92,6 @@ func main() {
|
||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
logLines := startTime.Format(time.RFC822) + "\n"
|
logLines := startTime.Format(time.RFC822) + "\n"
|
||||||
logGiteaLines := ""
|
|
||||||
|
|
||||||
ex, err := os.Executable()
|
ex, err := os.Executable()
|
||||||
check(err)
|
check(err)
|
||||||
|
@ -157,77 +156,58 @@ func main() {
|
||||||
outSandpointsDir, sandpointsCatalogName, sandpointsCatalogPrefix := getOutdirAndConfigCatalog(tmpRepoPath, gitRepoPath)
|
outSandpointsDir, sandpointsCatalogName, sandpointsCatalogPrefix := getOutdirAndConfigCatalog(tmpRepoPath, gitRepoPath)
|
||||||
logLines = logLines + fmt.Sprintf("to be moved to: %s\n", filepath.Join(outDir, outSandpointsDir))
|
logLines = logLines + fmt.Sprintf("to be moved to: %s\n", filepath.Join(outDir, outSandpointsDir))
|
||||||
tmpHugoGiteaPath := filepath.Join(os.TempDir(), fmt.Sprintf("sandpoints_hugo_%06d", rand.Intn(100001)))
|
tmpHugoGiteaPath := filepath.Join(os.TempDir(), fmt.Sprintf("sandpoints_hugo_%06d", rand.Intn(100001)))
|
||||||
tmpHugoPreviewPath := filepath.Join(tmpHugoGiteaPath, "_preview")
|
|
||||||
|
|
||||||
err = os.RemoveAll(tmpHugoGiteaPath)
|
err = os.RemoveAll(tmpHugoGiteaPath)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
err = os.MkdirAll(tmpHugoPreviewPath, 0755)
|
|
||||||
check(err)
|
|
||||||
|
|
||||||
err = os.MkdirAll(filepath.Join(outDir, outSandpointsDir, "_preview"), 0755)
|
|
||||||
check(err)
|
|
||||||
|
|
||||||
published := isPublished(gitRepoPath, gitIndexPath, prevCommit, lastCommit)
|
published := isPublished(gitRepoPath, gitIndexPath, prevCommit, lastCommit)
|
||||||
|
|
||||||
defer func() {
|
|
||||||
lastPreviewCommitLog, err := os.Create(filepath.Join(outDir, outSandpointsDir, "_preview", "last-commit-log.txt"))
|
|
||||||
check(err)
|
|
||||||
defer lastPreviewCommitLog.Close()
|
|
||||||
fmt.Fprintln(lastPreviewCommitLog, logLines)
|
|
||||||
log.Printf(logLines)
|
|
||||||
}()
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if published {
|
if published {
|
||||||
lastGiteaCommitLog, err := os.Create(filepath.Join(outDir, outSandpointsDir, "last-commit-log.txt"))
|
lastGiteaCommitLog, err := os.Create(filepath.Join(outDir, outSandpointsDir, "last-commit-log.txt"))
|
||||||
check(err)
|
check(err)
|
||||||
defer lastGiteaCommitLog.Close()
|
defer lastGiteaCommitLog.Close()
|
||||||
fmt.Fprintln(lastGiteaCommitLog, logGiteaLines)
|
fmt.Fprintln(lastGiteaCommitLog, logLines)
|
||||||
|
} else {
|
||||||
|
lastPreviewCommitLog, err := os.Create(filepath.Join(outDir, outSandpointsDir, "_preview", "last-commit-log.txt"))
|
||||||
|
check(err)
|
||||||
|
defer lastPreviewCommitLog.Close()
|
||||||
|
fmt.Fprintln(lastPreviewCommitLog, logLines)
|
||||||
}
|
}
|
||||||
|
log.Printf(logLines)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if published {
|
hugoGiteaLogs := cage.Start()
|
||||||
hugoGiteaLogs := cage.Start()
|
respGitea := commands.Execute([]string{"-s", tmpRepoPath, "-d", tmpHugoGiteaPath, "-e", "gitea"})
|
||||||
respGitea := commands.Execute([]string{"-s", tmpRepoPath, "-d", tmpHugoGiteaPath, "-e", "gitea"})
|
cage.Stop(hugoGiteaLogs)
|
||||||
cage.Stop(hugoGiteaLogs)
|
|
||||||
|
|
||||||
if respGitea.Err != nil {
|
if respGitea.Err != nil {
|
||||||
logGiteaLines = fmt.Sprintf("Attempt to publish web site ended up with an Error! Check out the last commit to capture possible errors.\n\n%s\n~~~~~~~~~~\n\n%s", respGitea.Err, logLines)
|
logLines = fmt.Sprintf("Hugo's attempt to render the web site ended up with an Error! Check out the last commit to capture possible errors.\n\n%s\n~~~~~~~~~~\n\n%s", respGitea.Err, logLines)
|
||||||
logLines = fmt.Sprintf("Rendering _preview of the web site ended up with an ERROR! Check out the last commit to capture possible errors.\n\n%s\n~~~~~~~~~~\n\n%s", respGitea.Err, logLines)
|
|
||||||
runtime.Goexit()
|
|
||||||
}
|
|
||||||
|
|
||||||
logGiteaLines = hugoLogs(logLines, hugoGiteaLogs.Data, "for published instance")
|
|
||||||
}
|
|
||||||
|
|
||||||
hugoPreviewLogs := cage.Start()
|
|
||||||
respPreview := commands.Execute([]string{"-s", tmpRepoPath, "-d", tmpHugoPreviewPath, "-e", "preview", "--templateMetrics"})
|
|
||||||
cage.Stop(hugoPreviewLogs)
|
|
||||||
|
|
||||||
if respPreview.Err != nil {
|
|
||||||
logLines = fmt.Sprintf("Rendering _preview of the web site ended up with an ERROR! Check out the last commit to capture possible errors.\n\n%s\n~~~~~~~~~~\n\n%s", respPreview.Err, logLines)
|
|
||||||
runtime.Goexit()
|
runtime.Goexit()
|
||||||
|
} else {
|
||||||
|
logLines = hugoLogs(logLines, hugoGiteaLogs.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
logLines = hugoLogs(logLines, hugoPreviewLogs.Data, "for _preview instance")
|
|
||||||
|
|
||||||
if published {
|
if published {
|
||||||
if _, err := os.Stat(filepath.Join(outDir, outSandpointsDir)); err == nil {
|
if _, err := os.Stat(filepath.Join(outDir, outSandpointsDir)); err == nil {
|
||||||
err := os.RemoveAll(filepath.Join(outDir, outSandpointsDir))
|
err := os.RemoveAll(filepath.Join(outDir, outSandpointsDir))
|
||||||
check(err)
|
check(err)
|
||||||
|
err = os.MkdirAll(outDir, 0755)
|
||||||
|
check(err)
|
||||||
}
|
}
|
||||||
|
} else if _, err := os.Lstat(filepath.Join(outDir, outSandpointsDir, "_preview")); err == nil {
|
||||||
|
err := os.Remove(filepath.Join(outDir, outSandpointsDir, "_preview"))
|
||||||
|
check(err)
|
||||||
} else if _, err := os.Stat(filepath.Join(outDir, outSandpointsDir, "_preview")); err == nil {
|
} else if _, err := os.Stat(filepath.Join(outDir, outSandpointsDir, "_preview")); err == nil {
|
||||||
err := os.RemoveAll(filepath.Join(outDir, outSandpointsDir, "_preview"))
|
err := os.RemoveAll(filepath.Join(outDir, outSandpointsDir, "_preview"))
|
||||||
check(err)
|
check(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.MkdirAll(outDir, 0755)
|
|
||||||
check(err)
|
|
||||||
|
|
||||||
if published {
|
if published {
|
||||||
err = os.Rename(tmpHugoGiteaPath, filepath.Join(outDir, outSandpointsDir))
|
err = os.Rename(tmpHugoGiteaPath, filepath.Join(outDir, outSandpointsDir))
|
||||||
check(err)
|
check(err)
|
||||||
|
err = os.Symlink(filepath.Join(outDir, outSandpointsDir), filepath.Join(outDir, outSandpointsDir, "_preview"))
|
||||||
|
check(err)
|
||||||
if sandpointsCatalogPrefix != "" && sandpointsCatalogName != "" {
|
if sandpointsCatalogPrefix != "" && sandpointsCatalogName != "" {
|
||||||
err = os.Symlink(filepath.Join(outDir, "libraries", sandpointsCatalogName), filepath.Join(outDir, outSandpointsDir, sandpointsCatalogPrefix))
|
err = os.Symlink(filepath.Join(outDir, "libraries", sandpointsCatalogName), filepath.Join(outDir, outSandpointsDir, sandpointsCatalogPrefix))
|
||||||
check(err)
|
check(err)
|
||||||
|
@ -235,7 +215,9 @@ func main() {
|
||||||
check(err)
|
check(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = os.Rename(tmpHugoPreviewPath, filepath.Join(outDir, outSandpointsDir, "_preview"))
|
err = os.MkdirAll(filepath.Join(outDir, outSandpointsDir), 0755)
|
||||||
|
check(err)
|
||||||
|
err = os.Rename(tmpHugoGiteaPath, filepath.Join(outDir, outSandpointsDir, "_preview"))
|
||||||
check(err)
|
check(err)
|
||||||
if sandpointsCatalogPrefix != "" && sandpointsCatalogName != "" {
|
if sandpointsCatalogPrefix != "" && sandpointsCatalogName != "" {
|
||||||
err = os.Symlink(filepath.Join(outDir, "libraries", sandpointsCatalogName), filepath.Join(outDir, outSandpointsDir, "_preview", sandpointsCatalogPrefix))
|
err = os.Symlink(filepath.Join(outDir, "libraries", sandpointsCatalogName), filepath.Join(outDir, outSandpointsDir, "_preview", sandpointsCatalogPrefix))
|
||||||
|
@ -243,12 +225,6 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
publishedMessage := ""
|
|
||||||
if published {
|
|
||||||
publishedMessage = " + published instance"
|
|
||||||
}
|
|
||||||
|
|
||||||
durationMillseconds := int64(time.Since(startTime) / time.Millisecond)
|
durationMillseconds := int64(time.Since(startTime) / time.Millisecond)
|
||||||
logLines = logLines + fmt.Sprintf("Total processing time (_preview%s): %d ms", publishedMessage, durationMillseconds)
|
logLines = logLines + fmt.Sprintf("Total processing time: %d ms", durationMillseconds)
|
||||||
logGiteaLines = logGiteaLines + fmt.Sprintf("Total processing time (published + _preview instance): %d ms", durationMillseconds)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue