Skip to content

Commit 721012c

Browse files
authored
feat: Update go-licenses, add CI (#2)
1 parent 0ae8979 commit 721012c

9 files changed

Lines changed: 159 additions & 678 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Go
1818
uses: actions/setup-go@v5
1919
with:
20-
go-version: 1.23
20+
go-version-file: go.mod
2121
id: go
2222

2323
- name: Run GoReleaser

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Check out code into the Go module directory
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version-file: go.mod
27+
28+
- name: Run Test
29+
run: go install github.com/google/go-licenses/v2 && go test ./...

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
This script scans the licenses of all the dependencies of modules in a given directory, and reports if any of them forbidden, notice, reciprocal or restricted types.
1+
# License Scanner
2+
3+
This script scans the licenses of all the dependencies of modules in a given directory, and reports if any of them forbidden, notice, reciprocal or restricted types.
24

35
From this directory, can be run with:
46

7+
```bash
8+
go run . check .
9+
go run . report .
510
```
6-
go run main.go check .
7-
go run main.go report .
8-
```

__snapshots__/main_test.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
[TestReport - 1]
3+
/-/-/-/
4+
hub-title: Licenses
5+
/-/-/-/
6+
7+
The following tools / packages are used in this plugin:
8+
9+
| Name | License |
10+
|------|---------|
11+
| github.com/spf13/cobra | Apache-2.0 |
12+
| github.com/spf13/pflag | BSD-3-Clause |
13+
| golang.org/x/sync/errgroup | BSD-3-Clause |
14+
---

go.mod

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,39 @@ module github.com/cloudquery/licenser
33
go 1.23.0
44

55
require (
6-
github.com/google/go-licenses v1.6.0
7-
github.com/spf13/cobra v1.6.0
6+
github.com/gkampitakis/go-snaps v0.5.7
7+
github.com/google/go-licenses/v2 v2.0.0-alpha.1
8+
github.com/spf13/cobra v1.7.0
9+
github.com/stretchr/testify v1.8.1
810
golang.org/x/sync v0.10.0
911
)
1012

1113
require (
12-
github.com/emirpasic/gods v1.12.0 // indirect
14+
github.com/davecgh/go-spew v1.1.1 // indirect
15+
github.com/gkampitakis/ciinfo v0.3.0 // indirect
16+
github.com/gkampitakis/go-diff v1.3.2 // indirect
1317
github.com/go-logr/logr v1.2.0 // indirect
1418
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
15-
github.com/google/licenseclassifier v0.0.0-20210722185704-3043a050f148 // indirect
16-
github.com/inconshreveable/mousetrap v1.0.1 // indirect
17-
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
18-
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd // indirect
19-
github.com/mitchellh/go-homedir v1.1.0 // indirect
20-
github.com/otiai10/copy v1.6.0 // indirect
19+
github.com/google/licenseclassifier/v2 v2.0.0 // indirect
20+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
21+
github.com/kr/pretty v0.3.1 // indirect
22+
github.com/kr/text v0.2.0 // indirect
23+
github.com/maruel/natural v1.1.1 // indirect
24+
github.com/otiai10/copy v1.10.0 // indirect
25+
github.com/pmezard/go-difflib v1.0.0 // indirect
26+
github.com/rogpeppe/go-internal v1.12.0 // indirect
2127
github.com/sergi/go-diff v1.2.0 // indirect
2228
github.com/spf13/pflag v1.0.5 // indirect
23-
github.com/src-d/gcfg v1.4.0 // indirect
24-
github.com/xanzy/ssh-agent v0.2.1 // indirect
25-
go.opencensus.io v0.23.0 // indirect
26-
golang.org/x/crypto v0.30.0 // indirect
29+
github.com/tidwall/gjson v1.17.0 // indirect
30+
github.com/tidwall/match v1.1.1 // indirect
31+
github.com/tidwall/pretty v1.2.1 // indirect
32+
github.com/tidwall/sjson v1.2.5 // indirect
33+
go.opencensus.io v0.24.0 // indirect
2734
golang.org/x/mod v0.17.0 // indirect
2835
golang.org/x/net v0.25.0 // indirect
2936
golang.org/x/sys v0.28.0 // indirect
3037
golang.org/x/text v0.21.0 // indirect
3138
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
32-
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
33-
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
34-
gopkg.in/warnings.v0 v0.1.2 // indirect
35-
k8s.io/klog/v2 v2.80.1 // indirect
39+
gopkg.in/yaml.v3 v3.0.1 // indirect
40+
k8s.io/klog/v2 v2.90.1 // indirect
3641
)

go.sum

Lines changed: 47 additions & 653 deletions
Large diffs are not rendered by default.

main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ func generateLicensesReport(dir string) error {
6767
return err
6868
}
6969

70+
if err := os.MkdirAll("docs", 0755); err != nil {
71+
return err
72+
}
7073
file, err := os.Create("docs/_licenses.md")
7174
if err != nil {
7275
return err
@@ -95,7 +98,7 @@ func findGoModDirs(rootDir string) ([]string, error) {
9598
return dirs, nil
9699
}
97100

98-
func main() {
101+
func rootCmd() *cobra.Command {
99102
g := new(errgroup.Group)
100103
g.SetLimit(10)
101104

@@ -171,5 +174,12 @@ func main() {
171174
cmd.AddCommand(checkCmd)
172175
cmd.AddCommand(reportCmd)
173176

174-
cmd.Execute()
177+
return &cmd
178+
}
179+
180+
func main() {
181+
cmd := rootCmd()
182+
if err := cmd.Execute(); err != nil {
183+
log.Fatalf("Error executing command: %v\n", err)
184+
}
175185
}

main_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/gkampitakis/go-snaps/snaps"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestCheck(t *testing.T) {
12+
cmd := rootCmd()
13+
cmd.SetArgs([]string{"check", "."})
14+
err := cmd.Execute()
15+
require.NoError(t, err)
16+
}
17+
18+
func TestReport(t *testing.T) {
19+
cmd := rootCmd()
20+
cmd.SetArgs([]string{"report", "."})
21+
err := cmd.Execute()
22+
require.NoError(t, err)
23+
content, err := os.ReadFile("docs/_licenses.md")
24+
require.NoError(t, err)
25+
snaps.MatchSnapshot(t, string(content))
26+
defer os.Remove("docs/_licenses.md")
27+
}

tools/tools.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
package tools
55

66
import (
7-
_ "github.com/google/go-licenses"
7+
_ "github.com/google/go-licenses/v2"
88
)

0 commit comments

Comments
 (0)