Skip to content

Add a licenses subcommand that prints the licenses of all dependencies. #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: 1.14.7
- name: Install Pkger
run: go get github.com/markbates/pkger/cmd/pkger
- name: Build
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: 1.14.7
- name: Install Pkger
run: go get github.com/markbates/pkger/cmd/pkger
- name: Release
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/codeql-action-sync
/dist/
/pkged.go
4 changes: 4 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
project_name: codeql-action-sync

before:
hooks:
- pkger

builds:
- goos: [linux, darwin, windows]
goarch: [386, amd64, arm64]
Expand Down
32 changes: 32 additions & 0 deletions .licenses/go/github.com/gobuffalo/here.dep.yml

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

32 changes: 32 additions & 0 deletions .licenses/go/github.com/markbates/pkger.dep.yml

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

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

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

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

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

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

14 changes: 14 additions & 0 deletions cmd/licenses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cmd

import (
"github.com/github/codeql-action-sync/internal/licenses"
"github.com/spf13/cobra"
)

var licensesCmd = &cobra.Command{
Use: "licenses",
Short: "Display the licenses of all the dependencies of this tool.",
RunE: func(cmd *cobra.Command, args []string) error {
return licenses.PrintLicenses()
},
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func Execute(ctx context.Context) error {
}

rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(licensesCmd)

rootCmd.AddCommand(pullCmd)
pullFlags.Init(pullCmd)
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ require (
github.com/go-git/go-git/v5 v5.1.0
github.com/google/go-github/v32 v32.1.0
github.com/gorilla/mux v1.8.0
github.com/markbates/pkger v0.17.0
github.com/mitchellh/ioprogress v0.0.0-20180201004757-6a23b12fa88e
github.com/pkg/errors v0.8.1
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.6.1
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 // indirect
)
16 changes: 16 additions & 0 deletions go.sum

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

41 changes: 41 additions & 0 deletions internal/licenses/licenses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package licenses

import (
"fmt"
"io/ioutil"
"os"

"github.com/markbates/pkger"
"github.com/pkg/errors"
)

const errorMessage = "Error reading licenses."

func PrintLicenses() error {
fmt.Println("This tool could not have been built without all the wonderful developer communities who maintain these dependencies.")
err := pkger.Walk("/.licenses", func(path string, info os.FileInfo, err error) error {
if err != nil {
return errors.Wrap(err, errorMessage)
}
if info.IsDir() {
return nil
}

reader, err := pkger.Open(path)
if err != nil {
return errors.Wrap(err, errorMessage)
}
defer reader.Close()
content, err := ioutil.ReadAll(reader)
if err != nil {
return errors.Wrap(err, errorMessage)
}
fmt.Println(string(content))

return nil
})
if err != nil {
return errors.Wrap(err, errorMessage)
}
return nil
}