Use Logrus for logging.
This commit is contained in:
Родитель
cb31118798
Коммит
a4598c20bb
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
name: github.com/sirupsen/logrus
|
||||
version: v1.2.0
|
||||
type: go
|
||||
summary: Package logrus is a structured logger for Go, completely API compatible with
|
||||
the standard library logger.
|
||||
homepage: https://godoc.org/github.com/sirupsen/logrus
|
||||
license: mit
|
||||
licenses:
|
||||
- sources: LICENSE
|
||||
text: |
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Simon Eskildsen
|
||||
|
||||
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.
|
||||
notices: []
|
1
go.mod
1
go.mod
|
@ -9,6 +9,7 @@ require (
|
|||
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/sirupsen/logrus v1.2.0
|
||||
github.com/spf13/cobra v1.0.0
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/stretchr/testify v1.6.1
|
||||
|
|
|
@ -86,6 +86,7 @@ github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v
|
|||
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
|
@ -129,6 +130,7 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
|
|||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
|
|
|
@ -6,11 +6,12 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/github/codeql-action-sync/internal/actionconfiguration"
|
||||
"github.com/mitchellh/ioprogress"
|
||||
"golang.org/x/oauth2"
|
||||
|
@ -44,9 +45,9 @@ type pullService struct {
|
|||
|
||||
func (pullService *pullService) pullGit(fresh bool) error {
|
||||
if fresh {
|
||||
log.Print("Pulling Git contents fresh...")
|
||||
log.Debug("Pulling Git contents fresh...")
|
||||
} else {
|
||||
log.Print("Updating Git contents...")
|
||||
log.Debug("Updating Git contents...")
|
||||
}
|
||||
gitPath := pullService.cacheDirectory.GitPath()
|
||||
|
||||
|
@ -107,7 +108,7 @@ func (pullService *pullService) pullGit(fresh bool) error {
|
|||
}
|
||||
|
||||
func (pullService *pullService) findRelevantReleases() ([]string, error) {
|
||||
log.Print("Finding release references...")
|
||||
log.Debug("Finding release references...")
|
||||
localRepository, err := git.PlainOpen(pullService.cacheDirectory.GitPath())
|
||||
if err != nil {
|
||||
return []string{}, errors.Wrap(err, "Error opening Git repository cache.")
|
||||
|
@ -121,7 +122,7 @@ func (pullService *pullService) findRelevantReleases() ([]string, error) {
|
|||
releases := []string{}
|
||||
err = references.ForEach(func(reference *plumbing.Reference) error {
|
||||
if relevantReferences.MatchString(reference.Name().String()) {
|
||||
log.Printf("Found %s.", reference.Name().String())
|
||||
log.Debugf("Found %s.", reference.Name().String())
|
||||
commit, err := localRepository.CommitObject(reference.Hash())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("Error loading commit %s for reference %s.", reference.Hash(), reference.Name().String()))
|
||||
|
@ -129,7 +130,7 @@ func (pullService *pullService) findRelevantReleases() ([]string, error) {
|
|||
file, err := commit.File(defaultConfigurationPath)
|
||||
if err != nil {
|
||||
if err == object.ErrFileNotFound {
|
||||
log.Printf("Ignoring reference %s as it does not have a default configuration.", reference.Name().String())
|
||||
log.Debugf("Ignoring reference %s as it does not have a default configuration.", reference.Name().String())
|
||||
return nil
|
||||
}
|
||||
return errors.Wrap(err, fmt.Sprintf("Error loading default configuration file from commit %s for reference %s.", reference.Hash(), reference.Name().String()))
|
||||
|
@ -156,14 +157,14 @@ func (pullService *pullService) findRelevantReleases() ([]string, error) {
|
|||
}
|
||||
|
||||
func (pullService *pullService) pullReleases() error {
|
||||
log.Print("Pulling CodeQL bundles...")
|
||||
log.Debug("Pulling CodeQL bundles...")
|
||||
relevantReleases, err := pullService.findRelevantReleases()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for index, releaseTag := range relevantReleases {
|
||||
log.Printf("Pulling CodeQL bundle %s (%d/%d)...", releaseTag, index+1, len(relevantReleases))
|
||||
log.Debugf("Pulling CodeQL bundle %s (%d/%d)...", releaseTag, index+1, len(relevantReleases))
|
||||
release, _, err := pullService.githubDotComClient.Repositories.GetReleaseByTag(pullService.ctx, sourceOwner, sourceRepository, releaseTag)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error loading CodeQL release information.")
|
||||
|
@ -187,11 +188,11 @@ func (pullService *pullService) pullReleases() error {
|
|||
return errors.Wrap(err, "Error creating assets directory.")
|
||||
}
|
||||
for _, asset := range release.Assets {
|
||||
log.Printf("Downloading asset %s...", asset.GetName())
|
||||
log.Debugf("Downloading asset %s...", asset.GetName())
|
||||
downloadPath := pullService.cacheDirectory.AssetPath(releaseTag, asset.GetName())
|
||||
downloadPathStat, err := os.Stat(downloadPath)
|
||||
if err == nil && downloadPathStat.Size() == int64(asset.GetSize()) {
|
||||
log.Println("Asset is already in cache.")
|
||||
log.Debug("Asset is already in cache.")
|
||||
continue
|
||||
}
|
||||
err = os.RemoveAll(downloadPath)
|
||||
|
@ -275,6 +276,6 @@ func Pull(ctx context.Context, cacheDirectory cachedirectory.CacheDirectory, sou
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Print("Finished pulling the CodeQL Action repository and bundles!")
|
||||
log.Info("Finished pulling the CodeQL Action repository and bundles!")
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -14,6 +13,8 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/github/codeql-action-sync/internal/cachedirectory"
|
||||
"github.com/github/codeql-action-sync/internal/version"
|
||||
"github.com/go-git/go-git/v5"
|
||||
|
@ -41,7 +42,7 @@ type pushService struct {
|
|||
}
|
||||
|
||||
func (pushService *pushService) createRepository() (*github.Repository, error) {
|
||||
log.Printf("Ensuring repository exists...")
|
||||
log.Debug("Ensuring repository exists...")
|
||||
user, _, err := pushService.githubEnterpriseClient.Users.Get(pushService.ctx, "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Error getting current user.")
|
||||
|
@ -59,7 +60,7 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
|
|||
return nil, errors.Wrap(err, "Error checking if destination organization exists.")
|
||||
}
|
||||
if response.StatusCode == http.StatusNotFound {
|
||||
log.Printf("The organization %s does not exist. Creating it...", pushService.destinationRepositoryOwner)
|
||||
log.Debugf("The organization %s does not exist. Creating it...", pushService.destinationRepositoryOwner)
|
||||
_, _, err := pushService.githubEnterpriseClient.Admin.CreateOrg(pushService.ctx, &github.Organization{
|
||||
Login: github.String(pushService.destinationRepositoryOwner),
|
||||
Name: github.String(pushService.destinationRepositoryOwner),
|
||||
|
@ -106,9 +107,9 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
|
|||
func (pushService *pushService) pushGit(repository *github.Repository, initialPush bool) error {
|
||||
remoteURL := repository.GetCloneURL()
|
||||
if initialPush {
|
||||
log.Printf("Pushing Git releases to %s...", remoteURL)
|
||||
log.Debugf("Pushing Git releases to %s...", remoteURL)
|
||||
} else {
|
||||
log.Printf("Pushing Git references to %s...", remoteURL)
|
||||
log.Debugf("Pushing Git references to %s...", remoteURL)
|
||||
}
|
||||
gitRepository, err := git.PlainOpen(pushService.cacheDirectory.GitPath())
|
||||
if err != nil {
|
||||
|
@ -190,7 +191,7 @@ func (pushService *pushService) createOrUpdateRelease(releaseName string) (*gith
|
|||
return nil, errors.Wrap(err, "Error checking for existing CodeQL release.")
|
||||
}
|
||||
if release == nil {
|
||||
log.Printf("Creating release %s...", releaseMetadata.GetTagName())
|
||||
log.Debugf("Creating release %s...", releaseMetadata.GetTagName())
|
||||
release, _, err := pushService.githubEnterpriseClient.Repositories.CreateRelease(pushService.ctx, pushService.destinationRepositoryOwner, pushService.destinationRepositoryName, &releaseMetadata)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Error creating release.")
|
||||
|
@ -199,7 +200,7 @@ func (pushService *pushService) createOrUpdateRelease(releaseName string) (*gith
|
|||
}
|
||||
release, _, err = pushService.githubEnterpriseClient.Repositories.EditRelease(pushService.ctx, pushService.destinationRepositoryOwner, pushService.destinationRepositoryName, release.GetID(), &releaseMetadata)
|
||||
if err != nil {
|
||||
log.Printf("Updating release %s...", releaseMetadata.GetTagName())
|
||||
log.Debugf("Updating release %s...", releaseMetadata.GetTagName())
|
||||
return nil, errors.Wrap(err, "Error updating release.")
|
||||
}
|
||||
return release, nil
|
||||
|
@ -231,7 +232,7 @@ func (pushService *pushService) createOrUpdateReleaseAsset(release *github.Repos
|
|||
}
|
||||
}
|
||||
}
|
||||
log.Printf("Uploading release asset %s...", assetPathStat.Name())
|
||||
log.Debugf("Uploading release asset %s...", assetPathStat.Name())
|
||||
assetFile, err := os.Open(pushService.cacheDirectory.AssetPath(release.GetTagName(), assetPathStat.Name()))
|
||||
defer assetFile.Close()
|
||||
progressReader := &ioprogress.Reader{
|
||||
|
@ -250,7 +251,7 @@ func (pushService *pushService) createOrUpdateReleaseAsset(release *github.Repos
|
|||
}
|
||||
|
||||
func (pushService *pushService) pushReleases() error {
|
||||
log.Print("Pushing CodeQL bundles...")
|
||||
log.Debugf("Pushing CodeQL bundles...")
|
||||
releasesPath := pushService.cacheDirectory.ReleasesPath()
|
||||
|
||||
releasePathStats, err := ioutil.ReadDir(releasesPath)
|
||||
|
@ -348,6 +349,6 @@ func Push(ctx context.Context, cacheDirectory cachedirectory.CacheDirectory, des
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("Finished pushing CodeQL Action to %s!", destinationRepository)
|
||||
log.Infof("Finished pushing CodeQL Action to %s!", destinationRepository)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package version
|
||||
|
||||
import "log"
|
||||
import log "github.com/sirupsen/logrus"
|
||||
|
||||
var version = "development"
|
||||
var commit = "0000000000000000000000000000000000000000"
|
||||
|
@ -14,5 +14,5 @@ func Commit() string {
|
|||
}
|
||||
|
||||
func LogVersion() {
|
||||
log.Printf("Starting CodeQL Action sync tool version %s...", Version())
|
||||
log.Infof("Starting CodeQL Action sync tool version %s...", Version())
|
||||
}
|
||||
|
|
4
main.go
4
main.go
|
@ -2,13 +2,15 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/github/codeql-action-sync/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
ctx := context.Background()
|
||||
if err := cmd.Execute(ctx); err != nil {
|
||||
if err == cmd.SilentErr {
|
||||
|
|
Загрузка…
Ссылка в новой задаче