diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa5cc21a..9a081d6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: uses: golangci/golangci-lint-action@v2 with: args: --timeout=10m - version: v1.28 + version: v1.49 github-token: ${{ secrets.GITHUB_TOKEN }} tests-on-windows: needs: golangci-lint # run after golangci-lint action to not produce duplicated errors @@ -31,7 +31,7 @@ jobs: strategy: matrix: golang: - - 1.15.x + - 1.18.x steps: - uses: actions/checkout@v2 - name: Install Go @@ -47,7 +47,7 @@ jobs: strategy: matrix: golang: - - 1.15.x + - 1.18.x steps: - uses: actions/checkout@v2 - name: Install Go @@ -68,8 +68,8 @@ jobs: strategy: matrix: golang: - - 1.14.x - - 1.15.x + - 1.18.x + - 1.19.x steps: - uses: actions/checkout@v2 - name: Install Go diff --git a/go.mod b/go.mod index 76023bf0..4e6fd0fb 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,7 @@ require ( github.com/tevino/abool v1.2.0 go.uber.org/zap v1.23.0 golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094 + golang.org/x/text v0.3.7 google.golang.org/genproto v0.0.0-20220829175752-36a9c930ecbf google.golang.org/grpc v1.49.0 howett.net/plist v1.0.0 @@ -65,7 +66,6 @@ require ( golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b // indirect golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect - golang.org/x/text v0.3.7 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go/cmd/yolo/main.go b/go/cmd/yolo/main.go index 8a286c16..952bd4c1 100644 --- a/go/cmd/yolo/main.go +++ b/go/cmd/yolo/main.go @@ -170,7 +170,7 @@ func yolo(args []string) error { } if artifactsCachePath != "" { - if err := os.MkdirAll(artifactsCachePath, 0755); err != nil { + if err := os.MkdirAll(artifactsCachePath, 0o755); err != nil { return err } } diff --git a/go/pkg/yolopb/types.go b/go/pkg/yolopb/types.go index 290f83c1..74cf6786 100644 --- a/go/pkg/yolopb/types.go +++ b/go/pkg/yolopb/types.go @@ -25,7 +25,6 @@ func (b *Build) PrepareOutput(salt string) error { // AddSignedURLs adds new fields containing URLs with a signature func (a *Artifact) AddSignedURLs(key string) error { - var err error a.DLArtifactSignedURL, err = signature.GetSignedURL("GET", "/api/artifact-dl/"+a.ID, "", key) if err != nil { diff --git a/go/pkg/yolopb/util.go b/go/pkg/yolopb/util.go index 6cccb4dc..8aa1dff8 100644 --- a/go/pkg/yolopb/util.go +++ b/go/pkg/yolopb/util.go @@ -5,9 +5,7 @@ import ( "strings" ) -var ( - signedOffByLine = regexp.MustCompile(`Signed-off-by: (.*)`) -) +var signedOffByLine = regexp.MustCompile(`Signed-off-by: (.*)`) func cleanupCommitMessage(msg string) string { if msg == "" { diff --git a/go/pkg/yolostore/store.go b/go/pkg/yolostore/store.go index 95e85b55..cb56c015 100644 --- a/go/pkg/yolostore/store.go +++ b/go/pkg/yolostore/store.go @@ -9,7 +9,6 @@ import ( ) type Store interface { - // artifacts store GetArtifactByID(id string) (*yolopb.Artifact, error) GetAllArtifactsWithoutBundleID() ([]*yolopb.Artifact, error) diff --git a/go/pkg/yolosvc/api_dev_test.go b/go/pkg/yolosvc/api_dev_test.go index c5838c92..443ab0d2 100644 --- a/go/pkg/yolosvc/api_dev_test.go +++ b/go/pkg/yolosvc/api_dev_test.go @@ -120,7 +120,6 @@ func TestServiceDevDumpObjects(t *testing.T) { assert.Equal(t, expectedDownloads, resp.Downloads) assert.Equal(t, expectedBatch, resp.Batch) - } func TestServiceDevDumpObjects_withPreloading(t *testing.T) { @@ -244,5 +243,4 @@ func TestServiceDevDumpObjects_withPreloading(t *testing.T) { assert.Equal(t, expectedDownloads, resp.Downloads) assert.Equal(t, expectedBatch, resp.Batch) - } diff --git a/go/pkg/yolosvc/api_download.go b/go/pkg/yolosvc/api_download.go index e13496a9..f3cca70a 100644 --- a/go/pkg/yolosvc/api_download.go +++ b/go/pkg/yolosvc/api_download.go @@ -6,7 +6,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -26,7 +25,6 @@ import ( ) func (svc *service) ArtifactDownloader(w http.ResponseWriter, r *http.Request) { - id := chi.URLParam(r, "artifactID") artifact, err := svc.store.GetArtifactByID(id) @@ -200,7 +198,7 @@ func (svc *service) signAndStreamIPA(artifact yolopb.Artifact, w io.Writer) erro // sign ipa var signed string { - tempdir, err := ioutil.TempDir("", "yolo") + tempdir, err := os.MkdirTemp("", "yolo") if err != nil { return err } @@ -209,7 +207,7 @@ func (svc *service) signAndStreamIPA(artifact yolopb.Artifact, w io.Writer) erro // write unsigned-file to tempdir unsigned := filepath.Join(tempdir, "unsigned.ipa") signed = filepath.Join(tempdir, "signed.ipa") - f, err := os.OpenFile(unsigned, os.O_RDWR|os.O_CREATE, 0755) + f, err := os.OpenFile(unsigned, os.O_RDWR|os.O_CREATE, 0o755) if err != nil { return err } @@ -308,7 +306,7 @@ func (svc *service) artifactDownloadFromProvider(artifact *yolopb.Artifact, w io return fmt.Errorf("failed to download artifact: %w", err) } defer resp.Body.Close() - zipContent, err = ioutil.ReadAll(resp.Body) + zipContent, err = io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("failed to download artifact stream: %w", err) } diff --git a/go/pkg/yolosvc/api_plist.go b/go/pkg/yolosvc/api_plist.go index b7291bc7..56e04a33 100644 --- a/go/pkg/yolosvc/api_plist.go +++ b/go/pkg/yolosvc/api_plist.go @@ -9,6 +9,8 @@ import ( "berty.tech/yolo/v2/go/pkg/plistgen" "github.com/go-chi/chi" "github.com/stretchr/signature" + "golang.org/x/text/cases" + "golang.org/x/text/language" "google.golang.org/grpc/codes" ) @@ -36,9 +38,10 @@ func (svc *service) PlistGenerator(w http.ResponseWriter, r *http.Request) { url = "/api/artifact-dl/" + id ) if artifact.HasBuild != nil && artifact.HasBuild.HasProject != nil { - title = strings.Title(artifact.HasBuild.HasProject.Name) + c := cases.Title(language.Und) + title = c.String(artifact.HasBuild.HasProject.Name) if artifact.HasBuild.HasProject.HasOwner != nil { - subtitle = strings.Title(artifact.HasBuild.HasProject.HasOwner.Name) + subtitle = c.String(artifact.HasBuild.HasProject.HasOwner.Name) } } pkgURL, err := signature.GetSignedURL("GET", url, "", svc.authSalt) diff --git a/go/pkg/yolosvc/driver_bintray.go b/go/pkg/yolosvc/driver_bintray.go index ce0cfe46..a9072a2c 100644 --- a/go/pkg/yolosvc/driver_bintray.go +++ b/go/pkg/yolosvc/driver_bintray.go @@ -23,7 +23,7 @@ type BintrayWorkerOpts struct { func (svc *service) BintrayWorker(ctx context.Context, opts BintrayWorkerOpts) error { opts.applyDefaults() - var logger = opts.Logger.Named("btry") + logger := opts.Logger.Named("btry") for iteration := 0; ; iteration++ { logger.Debug("bintray: refresh", zap.Int("iteration", iteration)) diff --git a/go/pkg/yolosvc/driver_circleci.go b/go/pkg/yolosvc/driver_circleci.go index 5bdcc99a..66279c1b 100644 --- a/go/pkg/yolosvc/driver_circleci.go +++ b/go/pkg/yolosvc/driver_circleci.go @@ -25,7 +25,7 @@ const circleciMaxPerPage = 30 func (svc *service) CircleciWorker(ctx context.Context, opts CircleciWorkerOpts) error { opts.applyDefaults() - var logger = opts.Logger.Named("circ") + logger := opts.Logger.Named("circ") for iteration := 0; ; iteration++ { since, err := lastBuildCreatedTime(ctx, svc.store, yolopb.Driver_CircleCI) diff --git a/go/pkg/yolosvc/driver_github.go b/go/pkg/yolosvc/driver_github.go index ebac6ba9..a385a462 100644 --- a/go/pkg/yolosvc/driver_github.go +++ b/go/pkg/yolosvc/driver_github.go @@ -34,7 +34,7 @@ type githubWorker struct { repoConfigs []githubRepoConfig } -func (worker githubWorker) ParseConfig() (bool, error) { +func (worker *githubWorker) ParseConfig() (bool, error) { if worker.opts.ReposFilter == "" { return false, nil } @@ -392,9 +392,9 @@ func (worker *githubWorker) batchFromWorkflowRun(run *github.WorkflowRun, prs [] newBuild.State = yolopb.Build_Skipped case conclusion == "timed_out": newBuild.State = yolopb.Build_Timedout - //case conclusion == "action_required": - //case conclusion == "neutral": - //case conclusion == "state": + // case conclusion == "action_required": + // case conclusion == "neutral": + // case conclusion == "state": default: newBuild.State = yolopb.Build_UnknownState worker.logger.Error( diff --git a/go/pkg/yolosvc/driver_pkgman.go b/go/pkg/yolosvc/driver_pkgman.go index 97258e5a..d836d8db 100644 --- a/go/pkg/yolosvc/driver_pkgman.go +++ b/go/pkg/yolosvc/driver_pkgman.go @@ -27,7 +27,7 @@ type PkgmanWorkerOpts struct { func (svc *service) PkgmanWorker(ctx context.Context, opts PkgmanWorkerOpts) error { opts.applyDefaults() // FIXME: handle pkgman version to recompute already computed artifacts with new filters - var logger = opts.Logger.Named("pman") + logger := opts.Logger.Named("pman") for iteration := 0; ; iteration++ { artifacts, err := svc.store.GetAllArtifactsWithoutBundleID() if err != nil { @@ -142,7 +142,7 @@ func (svc *service) pkgmanExtractIPAAppIcon(app *ipa.App) (string, error) { icon := md5Sum(b) + ".png" iconsPath := filepath.Join(svc.artifactsCachePath, "icons") - if err := os.MkdirAll(iconsPath, 0755); err != nil { + if err := os.MkdirAll(iconsPath, 0o755); err != nil { return "", err } iconPath := filepath.Join(iconsPath, icon) diff --git a/go/pkg/yolosvc/server.go b/go/pkg/yolosvc/server.go index c4141f33..5abcae05 100644 --- a/go/pkg/yolosvc/server.go +++ b/go/pkg/yolosvc/server.go @@ -4,6 +4,7 @@ import ( "context" "crypto/subtle" "fmt" + "google.golang.org/grpc/credentials/insecure" "net" "net/http" "strings" @@ -131,7 +132,7 @@ func NewServer(ctx context.Context, svc Service, opts ServerOpts) (*Server, erro runtime.WithMarshalerOption(runtime.MIMEWildcard, &gateway.JSONPb{EmitDefaults: false, Indent: " ", OrigName: true}), runtime.WithProtoErrorHandler(runtime.DefaultHTTPProtoErrorHandler), ) - grpcDialOpts := []grpc.DialOption{grpc.WithInsecure()} + grpcDialOpts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())} if err := yolopb.RegisterYoloServiceHandlerFromEndpoint(ctx, gwmux, srv.grpcListenerAddr, grpcDialOpts); err != nil { return nil, err } diff --git a/go/pkg/yolosvc/testing.go b/go/pkg/yolosvc/testing.go index b04f15e9..c933c4e7 100644 --- a/go/pkg/yolosvc/testing.go +++ b/go/pkg/yolosvc/testing.go @@ -59,7 +59,6 @@ func testingCreateEntities(t *testing.T, db *gorm.DB) { t.Helper() if err := db.Transaction(func(tx *gorm.DB) error { - // create artifact artifact := &yolopb.Artifact{ ID: "artif1", diff --git a/go/pkg/yolosvc/util.go b/go/pkg/yolosvc/util.go index c9a9b33a..14c6959c 100644 --- a/go/pkg/yolosvc/util.go +++ b/go/pkg/yolosvc/util.go @@ -10,15 +10,13 @@ import ( "berty.tech/yolo/v2/go/pkg/yolopb" ) -var ( - githubMasterMerge = regexp.MustCompile(`Merge pull request #([0-9]+) from (.*)`) -) +var githubMasterMerge = regexp.MustCompile(`Merge pull request #([0-9]+) from (.*)`) func artifactKindByPath(path string) yolopb.Artifact_Kind { switch filepath.Ext(path) { case ".ipa", ".unsigned-ipa", ".dummy-signed-ipa": return yolopb.Artifact_IPA - case ".dmg", ".unsigned-dmg" , ".dummy-signed-dmg": + case ".dmg", ".unsigned-dmg", ".dummy-signed-dmg": return yolopb.Artifact_DMG case ".apk": return yolopb.Artifact_APK