Import upstream version 2.0.3
Debian Janitor
2 years ago
0 | name: build | |
1 | ||
2 | on: [push, pull_request] | |
3 | ||
4 | jobs: | |
5 | build: | |
6 | runs-on: ubuntu-latest | |
7 | env: | |
8 | working-directory: ./src/github.com/awalterschulze/gographviz | |
9 | ||
10 | steps: | |
11 | - name: Set GOPATH | |
12 | run: | | |
13 | echo "##[set-env name=GOPATH;]$(dirname $GITHUB_WORKSPACE)/gographviz" | |
14 | echo "##[add-path]$(dirname $GITHUB_WORKSPACE)/gographviz/bin" | |
15 | shell: bash | |
16 | ||
17 | - name: Setup Go | |
18 | uses: actions/setup-go@v2 | |
19 | with: | |
20 | go-version: '1.14' | |
21 | ||
22 | - name: Checkout | |
23 | uses: actions/checkout@v2 | |
24 | with: | |
25 | fetch-depth: 1 | |
26 | path: src/github.com/awalterschulze/gographviz | |
27 | ||
28 | - name: Install dependencies | |
29 | run: make dependencies | |
30 | working-directory: ${{env.working-directory}} | |
31 | ||
32 | - name: Run regenerate | |
33 | run: make regenerate | |
34 | working-directory: ${{env.working-directory}} | |
35 | ||
36 | - name: Run build | |
37 | run: make build | |
38 | working-directory: ${{env.working-directory}} | |
39 | ||
40 | - name: Run checkers | |
41 | run: make checkers | |
42 | working-directory: ${{env.working-directory}} | |
43 | ||
44 | - name: Run testing | |
45 | run: make test | |
46 | working-directory: ${{env.working-directory}} |
0 | before_install: | |
1 | - ./install-godeps.sh | |
2 | ||
3 | script: | |
4 | - make travis | |
5 | ||
6 | language: go | |
7 | ||
8 | go: | |
9 | - 1.x |
0 | regenerate: | |
0 | .PHONY: help regenerate test dependencies build checkers action | |
1 | ||
2 | # Prefer tools that we've installed | |
3 | export PATH := $(HOME)/go/bin:$(PATH) | |
4 | ||
5 | help: | |
6 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | |
7 | ||
8 | regenerate: ## Re-generate lexers and parsers and pass through goimports | |
9 | go get github.com/goccmack/gocc | |
1 | 10 | go install github.com/goccmack/gocc |
2 | gocc -zip -o ./internal/ dot.bnf | |
11 | gocc -zip -o ./internal/ dot.bnf | |
3 | 12 | find . -type f -name '*.go' | xargs goimports -w |
4 | 13 | |
5 | test: | |
14 | test: ## Perform package tests | |
6 | 15 | go test ./... |
7 | 16 | |
8 | travis: | |
9 | make regenerate | |
10 | go build ./... | |
11 | go test ./... | |
17 | dependencies: ## Grab necessary dependencies for checkers | |
18 | go version | |
19 | go get golang.org/x/tools/cmd/goimports | |
20 | go get github.com/kisielk/errcheck | |
21 | go get -u golang.org/x/lint/golint | |
22 | ||
23 | build: ## Perform build process | |
24 | go build . | |
25 | ||
26 | checkers: ## Run all checkers (errcheck, gofmt and golint) | |
12 | 27 | errcheck -ignore 'fmt:[FS]?[Pp]rint*' ./... |
13 | 28 | gofmt -l -s -w . |
14 | 29 | golint -set_exit_status |
15 | 30 | git diff --exit-code |
31 | ||
32 | action: dependencies regenerate build test checkers ## Run steps of github action |
17 | 17 | |
18 | 18 | ### Documentation ### |
19 | 19 | |
20 | The [godoc](https://godoc.org/github.com/awalterschulze/gographviz) includes some more examples. | |
20 | - The [godoc](https://godoc.org/github.com/awalterschulze/gographviz) includes some more examples. | |
21 | - [How to implement an anonymous subgraph](https://github.com/awalterschulze/gographviz/issues/59) | |
21 | 22 | |
22 | 23 | ### Installation ### |
23 | 24 | go get github.com/awalterschulze/gographviz |
24 | 25 | |
25 | ### Tests ### | |
26 | ### Build and Tests ### | |
26 | 27 | |
27 | [![Build Status](https://travis-ci.org/awalterschulze/gographviz.svg?branch=master)](https://travis-ci.org/awalterschulze/gographviz) | |
28 | [![Build Status](https://github.com/awalterschulze/gographviz/workflows/build/badge.svg)](https://github.com/awalterschulze/gographviz/actions) | |
29 | ||
28 | 30 | |
29 | 31 | ### Users ### |
30 | 32 | |
33 | 35 | - [imagemonkey](https://imagemonkey.io/graph?editor=true) - Let's create our own image dataset |
34 | 36 | - [depviz](https://github.com/moul/depviz) - GitHub dependency visualizer (auto-roadmap) |
35 | 37 | - [kustomize-graph](https://github.com/jpreese/kustomize-graph) - A tool to visualize Kustomize dependencies |
38 | - [inframap](https://github.com/cycloidio/inframap) - Read your tfstate or HCL to generate a graph specific for each Terraform provider | |
39 | - [Antrea Traceflow](https://github.com/vmware-tanzu/antrea/blob/master/docs/traceflow-guide.md) supports using Traceflow for network diagnosis for Antrea, a Kubernetes networking solution intended to be Kubernetes native | |
36 | 40 | |
37 | 41 | ### Mentions ### |
38 | 42 |
103 | 103 | func TestString(t *testing.T) { |
104 | 104 | anal(t, |
105 | 105 | `digraph finite_state { rankdir = "LR" }`) |
106 | } | |
107 | ||
108 | func TestAttrImgPos(t *testing.T) { | |
109 | anal(t, | |
110 | "digraph finite_state { imagepos = tc }") | |
106 | 111 | } |
107 | 112 | |
108 | 113 | func TestAttrList(t *testing.T) { |
140 | 140 | Image Attr = "image" |
141 | 141 | // ImagePath http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:imagepath |
142 | 142 | ImagePath Attr = "imagepath" |
143 | // ImagePos https://graphviz.org/doc/info/attrs.html#d:imagepos | |
144 | ImagePos Attr = "imagepos" | |
143 | 145 | // ImageScale http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:imagescale |
144 | 146 | ImageScale Attr = "imagescale" |
145 | 147 | // InputScale http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:inputscale |
436 | 438 | string(ID): ID, |
437 | 439 | string(Image): Image, |
438 | 440 | string(ImagePath): ImagePath, |
441 | string(ImagePos): ImagePos, | |
439 | 442 | string(ImageScale): ImageScale, |
440 | 443 | string(InputScale): InputScale, |
441 | 444 | string(Label): Label, |
75 | 75 | return false |
76 | 76 | } |
77 | 77 | if c == '/' { |
78 | return false | |
79 | } | |
80 | if c == '.' { | |
78 | 81 | return false |
79 | 82 | } |
80 | 83 | i++ |
45 | 45 | if err := g.AddNode("asdf asdf", "a/b", nil); err != nil { |
46 | 46 | t.Fatal(err) |
47 | 47 | } |
48 | if err := g.AddNode("asdf asdf", "c.d", nil); err != nil { | |
49 | t.Fatal(err) | |
50 | } | |
51 | if err := g.AddNode("asdf asdf", "e-f", nil); err != nil { | |
52 | t.Fatal(err) | |
53 | } | |
54 | if err := g.AddNode("asdf asdf", "12_34", nil); err != nil { | |
55 | t.Fatal(err) | |
56 | } | |
48 | 57 | s := g.String() |
49 | 58 | if !strings.HasPrefix(s, `digraph "asdf adsf" { |
50 | 59 | "kasdf99 99"->7; |
60 | "12_34"; | |
51 | 61 | "a << b"; |
52 | 62 | "a/b"; |
63 | "c.d"; | |
64 | "e-f"; | |
53 | 65 | "kasdf99 99" [ URL="<a" ]; |
54 | 66 | 7 [ URL="<a" ]; |
55 | 67 |
0 | #!/usr/bin/env bash | |
1 | set -xe | |
2 | mkdir -p $GOPATH/src/githbub.com/goccmack | |
3 | git clone https://github.com/goccmack/gocc $GOPATH/src/github.com/goccmack/gocc | |
4 | go get golang.org/x/tools/cmd/goimports | |
5 | go get github.com/kisielk/errcheck | |
6 | go get -u golang.org/x/lint/golint⏎ |
3 | 3 | |
4 | 4 | import ( |
5 | 5 | "fmt" |
6 | "strconv" | |
7 | "unicode/utf8" | |
6 | 8 | ) |
7 | 9 | |
8 | 10 | type Token struct { |
56 | 58 | return fmt.Sprintf("%s(%d)", m.Id(typ), typ) |
57 | 59 | } |
58 | 60 | |
61 | // CharLiteralValue returns the string value of the char literal. | |
62 | func (t *Token) CharLiteralValue() string { | |
63 | return string(t.Lit[1 : len(t.Lit)-1]) | |
64 | } | |
65 | ||
66 | // Float32Value returns the float32 value of the token or an error if the token literal does not | |
67 | // denote a valid float32. | |
68 | func (t *Token) Float32Value() (float32, error) { | |
69 | if v, err := strconv.ParseFloat(string(t.Lit), 32); err != nil { | |
70 | return 0, err | |
71 | } else { | |
72 | return float32(v), nil | |
73 | } | |
74 | } | |
75 | ||
76 | // Float64Value returns the float64 value of the token or an error if the token literal does not | |
77 | // denote a valid float64. | |
78 | func (t *Token) Float64Value() (float64, error) { | |
79 | return strconv.ParseFloat(string(t.Lit), 64) | |
80 | } | |
81 | ||
82 | // IDValue returns the string representation of an identifier token. | |
83 | func (t *Token) IDValue() string { | |
84 | return string(t.Lit) | |
85 | } | |
86 | ||
87 | // Int32Value returns the int32 value of the token or an error if the token literal does not | |
88 | // denote a valid float64. | |
89 | func (t *Token) Int32Value() (int32, error) { | |
90 | if v, err := strconv.ParseInt(string(t.Lit), 10, 64); err != nil { | |
91 | return 0, err | |
92 | } else { | |
93 | return int32(v), nil | |
94 | } | |
95 | } | |
96 | ||
97 | // Int64Value returns the int64 value of the token or an error if the token literal does not | |
98 | // denote a valid float64. | |
99 | func (t *Token) Int64Value() (int64, error) { | |
100 | return strconv.ParseInt(string(t.Lit), 10, 64) | |
101 | } | |
102 | ||
103 | // UTF8Rune decodes the UTF8 rune in the token literal. It returns utf8.RuneError if | |
104 | // the token literal contains an invalid rune. | |
105 | func (t *Token) UTF8Rune() (rune, error) { | |
106 | r, _ := utf8.DecodeRune(t.Lit) | |
107 | if r == utf8.RuneError { | |
108 | err := fmt.Errorf("Invalid rune") | |
109 | return r, err | |
110 | } | |
111 | return r, nil | |
112 | } | |
113 | ||
114 | // StringValue returns the string value of the token literal. | |
115 | func (t *Token) StringValue() string { | |
116 | return string(t.Lit[1 : len(t.Lit)-1]) | |
117 | } | |
118 | ||
59 | 119 | var TokMap = TokenMap{ |
60 | 120 | typeMap: []string{ |
61 | 121 | "INVALID", |