Skip to content

Commit

Permalink
refactor(release): include goreleaser and remove packr
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-brito committed Oct 16, 2020
1 parent ab79107 commit 52f0e6a
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 167 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: goreleaser

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
# Project files
gocity
coverage.txt
/vendor
/vendor
/dist
27 changes: 27 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
before:
hooks:
- go mod download
- go generate ./...

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

archives:
- name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
replacements:
386: i386
amd64: x86_64

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ .Tag }}"

changelog:
sort: asc
5 changes: 2 additions & 3 deletions analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (

log "github.com/sirupsen/logrus"

"github.com/rodrigo-brito/gocity/lib"
"github.com/rodrigo-brito/gocity/lib/file"
"gocity/lib"
)

type Analyzer interface {
Expand Down Expand Up @@ -70,7 +69,7 @@ func (a *analyzer) Analyze() (map[string]*NodeInfo, error) {
}

fileSet := token.NewFileSet()
if f.IsDir() || !file.IsGoFile(f.Name()) || a.IsInvalidPath(path) {
if f.IsDir() || !lib.IsGoFile(f.Name()) || a.IsInvalidPath(path) {
return nil
}

Expand Down
9 changes: 5 additions & 4 deletions analyzer/visitor.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package analyzer

import (
"github.com/rodrigo-brito/gocity/lib/file"
"go/ast"
"go/token"

"gocity/lib"
)

type NodeInfo struct {
Expand Down Expand Up @@ -33,7 +34,7 @@ func (v *Visitor) Visit(node ast.Node) ast.Visitor {

switch definition := node.(type) {
case *ast.ValueSpec: // Atributes
identifier := file.GetIdentifier(v.Path, v.PackageName, "")
identifier := lib.GetIdentifier(v.Path, v.PackageName, "")

if _, ok := v.StructInfo[identifier]; !ok {
v.StructInfo[identifier] = new(NodeInfo)
Expand All @@ -44,7 +45,7 @@ func (v *Visitor) Visit(node ast.Node) ast.Visitor {

case *ast.TypeSpec: // Structs
if structObj, ok := definition.Type.(*ast.StructType); ok {
identifier := file.GetIdentifier(v.Path, v.PackageName, definition.Name.Name)
identifier := lib.GetIdentifier(v.Path, v.PackageName, definition.Name.Name)

if _, ok := v.StructInfo[identifier]; !ok {
v.StructInfo[identifier] = new(NodeInfo)
Expand All @@ -70,7 +71,7 @@ func (v *Visitor) Visit(node ast.Node) ast.Visitor {
}
}

identifier := file.GetIdentifier(v.Path, v.PackageName, structName)
identifier := lib.GetIdentifier(v.Path, v.PackageName, structName)

if _, ok := v.StructInfo[identifier]; !ok {
v.StructInfo[identifier] = new(NodeInfo)
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module github.com/rodrigo-brito/gocity
module gocity

go 1.15

require (
cloud.google.com/go v0.44.3
Expand All @@ -9,14 +11,16 @@ require (
github.com/gliderlabs/ssh v0.1.1 // indirect
github.com/go-chi/chi v4.0.1+incompatible
github.com/go-chi/cors v1.0.0
github.com/gobuffalo/packr/v2 v2.7.0
github.com/google/go-cmp v0.3.1 // indirect
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/karlseguin/ccache v2.0.2+incompatible
github.com/karlseguin/expect v1.0.1 // indirect
github.com/kevinburke/ssh_config v0.0.0-20180830205328-81db2a75821e // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/magiconair/properties v1.8.0
github.com/markbates/pkger v0.17.1
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pelletier/go-buffruneio v0.2.0 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/sergi/go-diff v1.0.0 // indirect
Expand All @@ -39,5 +43,3 @@ require (
gopkg.in/src-d/go-git.v4 v4.7.0
gopkg.in/warnings.v0 v0.1.2 // indirect
)

go 1.13
70 changes: 6 additions & 64 deletions go.sum

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions handle/analyzer.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
//go:generate go run github.com/markbates/pkger/cmd/pkger -o handle

package handle

import (
"encoding/json"
"fmt"
"github.com/rodrigo-brito/gocity/lib/file"
"net/http"
"time"

"github.com/gobuffalo/packr/v2"
"gocity/analyzer"
"gocity/handle/middlewares"
"gocity/lib"
"gocity/model"

"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/rodrigo-brito/gocity/analyzer"
"github.com/rodrigo-brito/gocity/handle/middlewares"
"github.com/rodrigo-brito/gocity/lib"
"github.com/rodrigo-brito/gocity/model"
"github.com/markbates/pkger"
log "github.com/sirupsen/logrus"
)

Expand All @@ -25,7 +26,7 @@ type AnalyzerHandle struct {
}

func (h *AnalyzerHandle) Handler(w http.ResponseWriter, r *http.Request) {
projectURL, ok := file.GetGithubBaseURL(r.URL.Query().Get("q"))
projectURL, ok := lib.GetGithubBaseURL(r.URL.Query().Get("q"))
if !ok {
w.WriteHeader(http.StatusBadRequest)
return
Expand Down Expand Up @@ -99,9 +100,12 @@ func (h *AnalyzerHandle) Serve(port int) error {
router.Use(middlewares.APIHeader(fmt.Sprintf("%s/api", baseURL)))
router.Use(middleware.DefaultLogger)

box := packr.New("assets", "./assets")
fs := http.FileServer(box)
assets, err := pkger.Open("/handle/assets")
if err != nil {
return err
}

fs := http.FileServer(assets)
router.Handle("/*", fs)
router.Get("/api", h.Handler)
router.Get("/health", func(w http.ResponseWriter, r *http.Request) {
Expand Down
21 changes: 0 additions & 21 deletions handle/fileserver.go

This file was deleted.

8 changes: 0 additions & 8 deletions handle/handle-packr.go

This file was deleted.

12 changes: 12 additions & 0 deletions handle/pkged.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/file/utils.go → lib/file.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package file
package lib

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion lib/file/utils_test.go → lib/file_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package file
package lib

import (
"fmt"
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
"fmt"
"github.com/rodrigo-brito/gocity/lib/file"
"os"

"github.com/rodrigo-brito/gocity/handle"
"github.com/rodrigo-brito/gocity/lib"
"gocity/handle"
"gocity/lib"

log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -50,7 +50,7 @@ func main() {
Description: "Open a given project in local server",
Action: func(c *cli.Context) error {
baseURL := c.Args().First()
url, ok := file.GetGithubBaseURL(c.Args().First())
url, ok := lib.GetGithubBaseURL(c.Args().First())
if !ok {
return fmt.Errorf("invalid project URL: %s", baseURL)
}
Expand Down
6 changes: 3 additions & 3 deletions model/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package model

import (
"fmt"
"github.com/rodrigo-brito/gocity/lib/file"
"sort"
"strings"

"github.com/rodrigo-brito/gocity/analyzer"
"gocity/analyzer"
"gocity/lib"
)

type NodeType string
Expand Down Expand Up @@ -103,7 +103,7 @@ func (n *Node) GenerateChildrenPosition() {
func getPathAndFile(fullPath string) (paths []string, fileName, structName string) {
pathlist := strings.Split(fullPath, "/")
paths = pathlist[:len(pathlist)-1]
fileName, structName = file.GetFileAndStruct(pathlist[len(pathlist)-1])
fileName, structName = lib.GetFileAndStruct(pathlist[len(pathlist)-1])
return
}

Expand Down
2 changes: 1 addition & 1 deletion model/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/magiconair/properties/assert"

"github.com/rodrigo-brito/gocity/analyzer"
"gocity/analyzer"
)

func TestNode_GenerateChildList(t *testing.T) {
Expand Down
42 changes: 0 additions & 42 deletions packrd/packed-packr.go

This file was deleted.

2 changes: 1 addition & 1 deletion testdata/mocks/Analyzer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 52f0e6a

Please sign in to comment.