Skip to content

Commit

Permalink
Remove old bash
Browse files Browse the repository at this point in the history
  • Loading branch information
posener committed Apr 27, 2020
1 parent 07fe9c5 commit c460fb3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 129 deletions.
107 changes: 0 additions & 107 deletions .github/entrypoint.sh

This file was deleted.

9 changes: 5 additions & 4 deletions .github/workflows/goreadme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ jobs:
- name: Update readme according to Go doc
uses: ./
with:
recursive: 'true'
badge-travisci: 'true'
badge-codecov: 'true'
badge-godoc: 'true'
recursive: true
badge-travisci: true
badge-codecov: true
badge-godoc: true
github-token: '${{ secrets.GITHUB_TOKEN }}'
debug: true
38 changes: 29 additions & 9 deletions cmd/action/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"log"
"net/http"
"os"
"path/filepath"

"github.com/golang/gddo/gosrc"
"github.com/posener/goaction"
"github.com/posener/goaction/actionutil"
"github.com/posener/goreadme"
Expand All @@ -27,6 +29,8 @@ var (
)

func init() {
log.SetFlags(log.Lshortfile)

flag.StringVar(&cfg.ImportPath, "import-path", "", "Override package import path.")
flag.BoolVar(&cfg.RecursiveSubPackages, "recursive", false, "Load docs recursively.")
flag.BoolVar(&cfg.Functions, "functions", false, "Write functions section.")
Expand All @@ -45,14 +49,26 @@ func init() {
if *debug {
os.Setenv("GOREADME_DEBUG", "1")
}

// Set import path if was not overridden.
if cfg.ImportPath == "" {
cfg.ImportPath = "github.com/" + goaction.Repository
}
}

func main() {
ctx := context.Background()

localPath, err := filepath.Abs("./")
if err != nil {
log.Fatal(err)
}
gosrc.SetLocalDevMode(localPath)

gr := func(w io.Writer) error {
return goreadme.New(http.DefaultClient).WithConfig(cfg).Create(ctx, ".", w)
}
err := script.Writer("goreadme", gr).ToFile(*path)
err = script.Writer("goreadme", gr).ToFile(*path)
if err != nil {
log.Fatalf("Failed: %s", err)
}
Expand All @@ -71,13 +87,14 @@ func main() {

diff := gitDiff()

if diff == "" {
log.Println("No changes were made. Aborting")
os.Exit(0)
}
log.Printf("Diff:\n\n%s\n", diff)

switch {
case goaction.IsPush():
if diff == "" {
log.Println("No changes were made. Skipping push.")
break
}
push()
case goaction.IsPR():
pr(diff)
Expand Down Expand Up @@ -113,10 +130,13 @@ func pr(diff string) {
return
}

body := fmt.Sprintf(
"[goreadme](https://github.com/posener/goreadme) diff for %s file for this PR:\n\n%s",
*path,
diff)
body := "[goreadme](https://github.com/posener/goreadme) will not make any changes in this PR"
if diff != "" {
body = fmt.Sprintf(
"[goreadme](https://github.com/posener/goreadme) diff for %s file for this PR:\n\n%s",
*path,
diff)
}

ctx := context.Background()
err := actionutil.PRComment(ctx, githubToken, "goreadme", body)
Expand Down
11 changes: 2 additions & 9 deletions internal/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ func Execute(w io.Writer, data interface{}) error {
return main.Execute(&multiNewLineEliminator{w: w}, data)
}

func importPath(p *doc.Package) string {
if len(p.References) > 0 {
return p.References[0]
}
return p.ImportPath
}

var base = template.New("base").Funcs(
template.FuncMap{
"gocode": func(s string) string {
Expand All @@ -37,10 +30,10 @@ var base = template.New("base").Funcs(
return "`" + s + "`"
},
"importPath": func(p *doc.Package) string {
return importPath(p)
return p.ImportPath
},
"fullName": func(p *doc.Package) string {
return strings.TrimPrefix(importPath(p), "github.com/")
return strings.TrimPrefix(p.ImportPath, "github.com/")
},
"urlOrName": func(f *doc.File) string {
if f.URL != "" {
Expand Down

0 comments on commit c460fb3

Please sign in to comment.