Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bkrukowski committed Feb 28, 2024
0 parents commit c41ca85
Show file tree
Hide file tree
Showing 14 changed files with 682 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/addlicense.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Addlicense
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
name: Addlicense
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go: [ '1.22' ]
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- run: go install github.com/google/addlicense@v1.1.1

- name: Addlicense
run: make addlicense-check
31 changes: 31 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go: [ '1.20', '1.21', '1.22' ]
steps:
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
cache: false
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.1
39 changes: 39 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
name: Tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go: [ '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20', '1.21', '1.22' ]
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Test
run: make tests

- name: Test coverage
run: make code-coverage

- name: Send coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
flag-name: Go-${{ matrix.go }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
/coverage.out
19 changes: 19 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
run:
timeout: 5m

linters:
enable-all: true
disable:
- funlen
- varnamelen
- interfacer
- golint
- structcheck
- maligned
- deadcode
- exhaustivestruct
- nosnakecase
- ifshort
- scopelint
- varcheck
- depguard
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2023–present Bartłomiej Krukowski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests:
go test -race -count=1 -coverprofile=coverage.out ./...

code-coverage:
go tool cover -func=coverage.out

lint:
golangci-lint run

addlicense:
addlicense -f LICENSE -ignore=vendor/\*\* -ignore=.\* -ignore=.\*/\*\*/\* .

addlicense-check:
addlicense -f LICENSE -ignore=vendor/\*\* -ignore=.\* -ignore=.\*/\*\*/\* -check .
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[![Go Reference](https://pkg.go.dev/badge/github.com/gontainer/graph.svg)](https://pkg.go.dev/github.com/gontainer/graph)
[![Tests](https://github.com/gontainer/graph/actions/workflows/tests.yml/badge.svg)](https://github.com/gontainer/graph/actions/workflows/tests.yml)
[![Coverage Status](https://coveralls.io/repos/github/gontainer/graph/badge.svg?branch=main)](https://coveralls.io/github/gontainer/graph?branch=main)
[![Go Report Card](https://goreportcard.com/badge/github.com/gontainer/graph)](https://goreportcard.com/report/github.com/gontainer/graph)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=gontainer_graph&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=gontainer_graph)

# Graph

This package provides a tool to detect circular dependencies and find all dependant nodes in directed graphs.

```go
g := graph.New()
g.AddDep("company", "tech-team")
g.AddDep("tech-team", "cto")
g.AddDep("cto", "company")
g.AddDep("cto", "ceo")
g.AddDep("ceo", "company")

fmt.Println(g.CircularDeps())

// Output:
// [[company tech-team cto company] [company tech-team cto ceo company]]
```

See [examples](examples_test.go).
22 changes: 22 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2023–present Bartłomiej Krukowski
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// Package graph provides a tool to detect circular dependencies and find all dependant nodes in directed graphs.
package graph
52 changes: 52 additions & 0 deletions examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) 2023–present Bartłomiej Krukowski
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package graph_test

import (
"fmt"

"github.com/gontainer/graph"
)

func ExampleNew_circularDeps() {
g := graph.New()
g.AddDep("company", "tech-team")
g.AddDep("tech-team", "cto")
g.AddDep("cto", "company")
g.AddDep("cto", "ceo")
g.AddDep("ceo", "company")

fmt.Println(g.CircularDeps())

// Output:
// [[company tech-team cto company] [company tech-team cto ceo company]]
}

func ExampleNew_deps() {
g := graph.New()
g.AddDep("company", "tech-team")
g.AddDep("tech-team", "cto")

fmt.Println(g.Deps("company"))

// Output:
// [cto tech-team]
}
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/gontainer/graph

go 1.14

require (
github.com/stretchr/testify v1.8.2
gonum.org/v1/gonum v0.14.0
)

0 comments on commit c41ca85

Please sign in to comment.