Skip to content

Commit

Permalink
golangci-lint and npm-check build steps with various code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonMcCullough authored Nov 21, 2023
1 parent 01ec2dd commit eb3ebc1
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 103 deletions.
8 changes: 8 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,11 @@ steps:
- bin/arm64-macos-bugsnag-cli
upload:
- maze_output/**/*

- label: ":lint-roller::go: Lint Go Code"
commands:
- make go-lint

- label: ":lint-roller::npm: Lint NPM Dependencies"
commands:
- make npm-lint
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/alecthomas/kong v0.7.1
github.com/mattn/go-isatty v0.0.18
github.com/stretchr/testify v1.8.0
golang.org/x/text v0.14.0
google.golang.org/protobuf v1.30.0
)

Expand Down
16 changes: 5 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
github.com/alecthomas/kong v0.6.1 h1:1kNhcFepkR+HmasQpbiKDLylIL8yh5B5y1zPp5bJimA=
github.com/alecthomas/kong v0.6.1/go.mod h1:JfHWDzLmbh/puW6I3V7uWenoh56YNVONW+w8eKeUr9I=
github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0=
github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4=
github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142 h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48=
github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
42 changes: 4 additions & 38 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const axios = require('axios');
const fs = require('fs');
const path = require('path');
const os = require('os');
const yaml = require('js-yaml');

const supportedPlatformsConfig = fs.readFileSync(path.join(__dirname, 'supported-platforms.yml'), 'utf8');
const { name, repository, version } = require('./package.json');

const handleError = (msg) => {
Expand All @@ -17,44 +19,8 @@ const removeGitPrefixAndSuffix = (input) => {
return result;
};

const supportedPlatforms = [
{
TYPE: 'Windows',
ARCHITECTURE: 'x64',
ARTIFACT_NAME: 'x86_64-windows-bugsnag-cli.exe',
BINARY_NAME: 'bugsnag-cli.exe'
},
{
TYPE: 'Windows',
ARCHITECTURE: 'i386',
ARTIFACT_NAME: 'i386-windows-bugsnag-cli.exe',
BINARY_NAME: 'bugsnag-cli.exe'
},
{
TYPE: 'Linux',
ARCHITECTURE: 'x64',
ARTIFACT_NAME: 'x86_64-linux-bugsnag-cli',
BINARY_NAME: 'bugsnag-cli'
},
{
TYPE: 'Linux',
ARCHITECTURE: 'i386',
ARTIFACT_NAME: 'i386-linux-bugsnag-cli',
BINARY_NAME: 'bugsnag-cli'
},
{
TYPE: 'Darwin',
ARCHITECTURE: 'x64',
ARTIFACT_NAME: 'x86_64-macos-bugsnag-cli',
BINARY_NAME: 'bugsnag-cli'
},
{
TYPE: 'Darwin',
ARCHITECTURE: 'arm64',
ARTIFACT_NAME: 'arm64-macos-bugsnag-cli',
BINARY_NAME: 'bugsnag-cli'
}
];
// Parse supported-platforms.yml into an iterable array
const supportedPlatforms = yaml.load(supportedPlatformsConfig);

const getPlatformMetadata = () => {
const type = os.type();
Expand Down
10 changes: 10 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ unit-test:
fmt:
gofmt -w ./


.PHONY: npm-lint
npm-lint:
npm i && npm install -g npm-check && npm-check

.PHONY: go-lint
go-lint:
go install github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint run

.PHONY: bump
bump:
ifneq ($(shell git diff --staged),)
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
},
"homepage": "https://github.com/bugsnag/bugsnag-cli#readme",
"dependencies": {
"axios": "^1.4.0",
"console.table": "^0.10.0"
"axios": "^1.6.2",
"js-yaml": "^4.1.0"
},
"files": [
"install.js"
"install.js",
"supported-platforms.yml"
],
"scripts": {
"postinstall": "node install.js"
Expand Down
2 changes: 0 additions & 2 deletions pkg/android/build-objcopy-path.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,4 @@ func BuildObjcopyPath(path string) (string, error) {

return filepath.Join(directoryMatches[0], "llvm-objcopy"), nil
}

return "", nil
}
6 changes: 3 additions & 3 deletions pkg/android/get-variant.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package android

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

"github.com/bugsnag/bugsnag-cli/pkg/utils"
Expand All @@ -12,7 +12,7 @@ import (
func BuildVariantsList(path string) ([]string, error) {
var variants []string

fileInfo, err := ioutil.ReadDir(path)
fileInfo, err := os.ReadDir(path)

if err != nil {
return nil, err
Expand All @@ -28,7 +28,7 @@ func BuildVariantsList(path string) ([]string, error) {
func GetVariantDirectory(path string) (string, error) {
var variants []string

fileInfo, err := ioutil.ReadDir(path)
fileInfo, err := os.ReadDir(path)

if err != nil {
return "", err
Expand Down
18 changes: 3 additions & 15 deletions pkg/android/manifest-reader-xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package android
import (
"encoding/xml"
"fmt"
"io/ioutil"
"os"
)

Expand All @@ -28,27 +27,16 @@ type MetaData struct {

// ParseAndroidManifestXML - Pulls information from a human-readable xml file into a struct
func ParseAndroidManifestXML(manifestFile string) (*Manifest, error) {
file, err := os.Open(manifestFile)

if err != nil {
return nil, fmt.Errorf("unable to open " + manifestFile + " : " + err.Error())
}

defer file.Close()

data, err := ioutil.ReadAll(file)

data, err := os.ReadFile(manifestFile)
if err != nil {
return nil, fmt.Errorf("unable to read " + manifestFile + " : " + err.Error())
}

manifestData := Manifest{}

var manifestData *Manifest
err = xml.Unmarshal(data, &manifestData)

if err != nil {
return nil, fmt.Errorf("unable to parse data from " + manifestFile + " : " + err.Error())
}

return &manifestData, nil
return manifestData, nil
}
8 changes: 4 additions & 4 deletions pkg/android/process-objcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import (
func Objcopy(objcopyPath string, file string, outputPath string) (string, error) {

objcopyLocation, err := exec.LookPath(objcopyPath)

if err != nil {
return "", err
}

outputFile := filepath.Join(outputPath, filepath.Base(file))
outputFile = strings.ReplaceAll(outputFile, filepath.Ext(outputFile), ".so.sym")

cmd := exec.Command(objcopyLocation, "--compress-debug-sections=zlib", "--only-keep-debug", file, outputFile)

_, err = cmd.CombinedOutput()
_, err = exec.Command(objcopyLocation, "--compress-debug-sections=zlib", "--only-keep-debug", file, outputFile).CombinedOutput()
if err != nil {
return "", err
}

return outputFile, nil
}
13 changes: 10 additions & 3 deletions pkg/server/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package server
import (
"bytes"
"fmt"
"github.com/bugsnag/bugsnag-cli/pkg/log"
"io"
"mime/multipart"
"net/http"
"os"
"path/filepath"
"time"

"github.com/bugsnag/bugsnag-cli/pkg/log"
)

// BuildFileRequest - Create a multi-part form request adding a file as a parameter
Expand All @@ -30,11 +31,17 @@ func BuildFileRequest(url string, fieldData map[string]string, fileFieldData map
return nil, err
}

io.Copy(part, file)
_, err = io.Copy(part, file)
if err != nil {
return nil, err
}
}

for key, value := range fieldData {
writer.WriteField(key, value)
err := writer.WriteField(key, value)
if err != nil {
return nil, err
}
}

writer.Close()
Expand Down
32 changes: 17 additions & 15 deletions pkg/upload/dart.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"debug/elf"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand All @@ -16,6 +15,9 @@ import (
"github.com/bugsnag/bugsnag-cli/pkg/utils"
)

var androidSymbolFileRegex = regexp.MustCompile("android-([^;]*).symbols")
var iosSymbolFileRegex = regexp.MustCompile("ios-([^;]*).symbols")

type DartSymbolOptions struct {
Path utils.Paths `arg:"" name:"path" help:"(required) Path to directory or file to upload" type:"path"`
IosAppPath string `help:"(optional) the path to the built iOS app."`
Expand All @@ -40,15 +42,15 @@ func Dart(paths []string, version string, versionCode string, bundleVersion stri
for _, file := range fileList {

// Check if we're dealing with an android or iOS symbol file
androidPlatform, _ := regexp.MatchString("android-([^;]*).symbols", file)
iosPlatform, _ := regexp.MatchString("ios-([^;]*).symbols", file)
isAndroidPlatform := androidSymbolFileRegex.MatchString(file)
isIosPlatform := iosSymbolFileRegex.MatchString(file)

// Start processing the android symbol file
if androidPlatform {
if isAndroidPlatform {
log.Info("Processing android symbol file: " + file)

buildId, err := GetBuildIdFromElfFile(file)

var buildId string
buildId, err = GetBuildIdFromElfFile(file)
if err != nil {
return err
}
Expand All @@ -75,7 +77,7 @@ func Dart(paths []string, version string, versionCode string, bundleVersion stri
}

// Process iOS file
if iosPlatform {
if isIosPlatform {
log.Info("Processing iOS symbol file: " + file)

if iosAppPath == "" {
Expand All @@ -86,14 +88,14 @@ func Dart(paths []string, version string, versionCode string, bundleVersion stri
}
}

arch, err := GetArchFromElfFile(file)

var arch string
arch, err = GetArchFromElfFile(file)
if err != nil {
return err
}

buildId, err := DwarfDumpUuid(file, iosAppPath, arch)

var buildId string
buildId, err = DwarfDumpUuid(file, iosAppPath, arch)
if err != nil {
return err
}
Expand Down Expand Up @@ -154,8 +156,8 @@ func GetBuildIdFromElfFile(symbolFile string) (string, error) {
}

if sect := elfData.Section(".note.gnu.build-id"); sect != nil {
data, err := sect.Data()

var data []byte
data, err = sect.Data()
if err != nil {
return "", fmt.Errorf("error reading symbol file")
}
Expand Down Expand Up @@ -200,7 +202,7 @@ func GetArchFromElfFile(symbolFile string) (string, error) {
func GetIosAppPath(symbolFile string) (string, error) {
sampleRegexp := regexp.MustCompile(`/[^/]*/[^/]*$`)
basePath := filepath.Join(sampleRegexp.ReplaceAllString(symbolFile, "") + "/build/ios/iphoneos")
files, err := ioutil.ReadDir(basePath)
files, err := os.ReadDir(basePath)

if err != nil {
return "", err
Expand All @@ -210,7 +212,7 @@ func GetIosAppPath(symbolFile string) (string, error) {
if strings.Contains(file.Name(), ".app") && file.IsDir() {
iosAppPath := filepath.Join(basePath + "/" + file.Name() + "/Frameworks/App.framework/App")

_, err := os.Stat(iosAppPath)
_, err = os.Stat(iosAppPath)

if errors.Is(err, os.ErrNotExist) {
return "", err
Expand Down
Loading

0 comments on commit eb3ebc1

Please sign in to comment.