Skip to content
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

Add arm64 support for M1 Mac, replace golint #46

Merged
merged 28 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a56dccd
ignore vscode files
physik932 Mar 29, 2022
37929d2
bump version of gomock for arm
physik932 Mar 29, 2022
3d4c258
add arm64 as supported release arch
physik932 Mar 29, 2022
3389d65
add go-version file for asdf and goenv users
physik932 Mar 29, 2022
092cb27
update versions referenced in contributing docs
physik932 Mar 29, 2022
2d33063
remove second param in DoAndReturn - breaking change introduced by la…
physik932 Mar 29, 2022
d1c5972
remove golint for now
physik932 Apr 1, 2022
8450146
add arm64 to sopstoolinstall script
physik932 Apr 1, 2022
9dd176d
an attempt and more verbose install docs
physik932 Apr 1, 2022
2cd7c3d
golangci-lint support
physik932 Apr 1, 2022
794ad8b
fix golangci-lint in travis
physik932 Apr 1, 2022
9f9e518
lint: remove trailing newline
physik932 Apr 4, 2022
07b9845
fmt sprintf not needed for multiline string
physik932 Apr 4, 2022
5b2353c
use less stutter in class naming
physik932 Apr 4, 2022
e828bad
rename test helper without underscore
physik932 Apr 4, 2022
2aea030
use shorter name for os wrap instance
physik932 Apr 4, 2022
e7a50cf
smaller oswrap instance name
physik932 Apr 4, 2022
ed9a397
remove redundant return statement
physik932 Apr 4, 2022
0007afb
add new archive step with arch, add id, specify in brewfile
physik932 Apr 4, 2022
0667efe
use golangci-lint tap to install latest
physik932 Apr 4, 2022
03f3f2a
update style doc for golangcilint
physik932 Apr 4, 2022
7606726
more arch additions
onyxraven Apr 4, 2022
a616f92
also have to add to installer
onyxraven Apr 4, 2022
0b903af
add binary based on goreleaser builds
physik932 Apr 5, 2022
27287ab
add note about docker build for linuxamd64
physik932 Apr 6, 2022
5a8b8c3
add note about releases
physik932 Apr 6, 2022
1bc64f6
Update README.md
physik932 Apr 6, 2022
004bbf7
accidentally an L
physik932 Apr 6, 2022
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: 0 additions & 2 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---
engines:
golint:
enabled: true
physik932 marked this conversation as resolved.
Show resolved Hide resolved
gofmt:
enabled: true
govet:
Expand Down
84 changes: 50 additions & 34 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,82 @@

## Getting Started

## Layout

This is a single top-level namespace filled with packages. Each directory is potentially a package. Binary builds are done on packages with a main subpackage.

## Building Locally
## Install Golang

### Go Version
### Using asdf-vm
We utilize a `.go-version` file that can be used by [asdf-vm](https://github.com/kennyp/asdf-golang) like so:

Requires Go `>= 1.14`.
```bash
cd /path/to/sopstool/repository/
asdf plugin add golang
asdf install golang
```

1. Install go (currently 1.14)
### Using goenv

You may want to use a version manager.
[goenv](https://github.com/syndbg/goenv) will prefer the `GOENV_VERSION` environment variable first before looking for the `.go-version` file when [determining which Golang version](https://github.com/syndbg/goenv/blob/master/HOW_IT_WORKS.md#choosing-the-go-version) to install. If you do not have this set (`echo $GOENV_VERSION` is empty), install like so:

- [asdf](https://github.com/kennyp/asdf-golang)
```bash
cd /path/to/sopstool/repository/
goenv install
```

```sh
asdf install golang 1.14
# use global to update default go version. local set just for current directory
asdf local golang 1.14
```
### Using gimme
[gimme](https://github.com/travis-ci/gimme) uses `eval` in a simple way:

- [goenv](https://github.com/syndbg/goenv) is another option.
```bash
eval "$(gimme 1.17)"
```

```sh
goenv install 1.14
go version
# go version go1.14 darwin/amd64
```
### From the developers

- [gimme](https://github.com/travis-ci/gimme)
You can download and install the Golang [directly from the website](https://go.dev/dl/).

1. Install gomock
### Additional Go Libraries

```sh
go get -u github.com/golang/mock/gomock && go install github.com/golang/mock/mockgen
```
Install [gomock](https://github.com/golang/mock)

```sh
go get -u github.com/golang/mock/gomock && go install github.com/golang/mock/mockgen
```

### Build
Install [golangci-lint](https://golangci-lint.run/)

With go 1.11+ and addition of [Modules](https://github.com/golang/go/wiki/Modules), go projects can be located outside the GOPATH.
```sh
brew install golangci-lint
```

## Build

If you are having issues review [faq](https://github.com/golang/go/wiki/Modules#faqs--most-common)
With Go 1.11+ and addition of [Modules](https://github.com/golang/go/wiki/Modules), Go projects can be located outside the `$GOPATH`.

If generate has already run, then it does not need to run again.
If you are having issues, review the [FAQ](https://github.com/golang/go/wiki/Modules#faqs--most-common).

If `generate` has already run, then it does not need to run again.

```sh
go build
go fmt ./...
golint ./...
physik932 marked this conversation as resolved.
Show resolved Hide resolved
physik932 marked this conversation as resolved.
Show resolved Hide resolved
```

### Unit Test
## Unit Tests

Each module is unit tested, and passes all tests.

```sh
go test ./...
```

## Linting

`golangci-lint` runs several popular Go linters quickly:

```sh
golangci-lint run
```

## Releasing

This project uses [GoReleaser](https://goreleaser.com/) for builds and releases. Doing the tag/release below triggers the appropriate actions.
Expand All @@ -70,25 +86,25 @@ This project uses [GoReleaser](https://goreleaser.com/) for builds and releases.

You can preview the package changes by running `scripts/release-preview`. This will show a summary of changes since the last release.

1. Prepare the release
1. Prepare the release:

```sh
git checkout master && git pull
```

Commit and tag with the intended version bump
Commit and tag with the intended version bump:

```sh
git commit -am "Tagging release $VERSION" && git tag v$VERSION
```

for example:
For example:

```sh
git commit -am "Tagging release 0.1.1" && git tag v0.1.1
```

Then push the tag and commit to github
Then push the tag and commit to Github:

```sh
git push && git push --tags # or git push --follow-tags but YMMV
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ sopstool
c.out
*.cover
.idea
.vscode
1 change: 1 addition & 0 deletions .go-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.17
20 changes: 20 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
run:
physik932 marked this conversation as resolved.
Show resolved Hide resolved
timeout: 2m

linters:
disable-all: true
enable:
# defaults
- govet
- staticcheck
- gosimple
- typecheck
- revive
# additional
- goimports
- gosec
- misspell
- whitespace

output:
format: colored-line-number
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ builds:
- darwin
- linux
goarch:
# sops is only available for amd64
- amd64
- arm64
onyxraven marked this conversation as resolved.
Show resolved Hide resolved
physik932 marked this conversation as resolved.
Show resolved Hide resolved

archives:
- id: zips
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ cache:
- "$HOME/gopath/pkg/mod"

before_script:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.45.2
physik932 marked this conversation as resolved.
Show resolved Hide resolved
- go mod download && go build

script:
# See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
- 'if [ "$TRAVIS_PULL_REQUEST" = "true" ]; then bash go test ./...; fi'
- 'if [ "$TRAVIS_PULL_REQUEST" = "true" ]; then bash go test ./...; golangci-lint run; fi'
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./scripts/coverage_test; fi'

after_script:
physik932 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Ibotta/sopstool
go 1.17

require (
github.com/golang/mock v1.5.0
github.com/golang/mock v1.6.0
github.com/mozilla-services/yaml v0.0.0-20201007153854-c369669a6625
github.com/spf13/cobra v1.2.1
)
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.5.0 h1:jlYHihg//f7RRwuPfptm04yp4s7O6Kw8EZiVYIGcH0g=
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -446,6 +448,7 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
1 change: 1 addition & 0 deletions sopstoolinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ execute() {
get_binaries() {
case "$PLATFORM" in
darwin/amd64) BINARIES="sopstool" ;;
darwin/arm64) BINARIES="sopstool" ;;
physik932 marked this conversation as resolved.
Show resolved Hide resolved
linux/amd64) BINARIES="sopstool" ;;
physik932 marked this conversation as resolved.
Show resolved Hide resolved
*)
log_crit "platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX}/issues/new"
Expand Down
46 changes: 23 additions & 23 deletions sopsyaml/sopsyaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestFindConfigFile(t *testing.T) {
defer ctrl.Finish()
mock := mock_oswrap.NewMockOsWrap(ctrl)

mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, nil
})

Expand All @@ -42,10 +42,10 @@ func TestFindConfigFile(t *testing.T) {
defer ctrl.Finish()
mock := mock_oswrap.NewMockOsWrap(ctrl)

mock.EXPECT().Stat(test_helpers.RegexMatches(`^.*\.git$`)).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(test_helpers.RegexMatches(`^.*\.git$`)).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, fmt.Errorf("Not Found") // Never git
}).AnyTimes()
mock.EXPECT().Stat(test_helpers.RegexMatches(`^.*\.sops.yaml$`)).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(test_helpers.RegexMatches(`^.*\.sops.yaml$`)).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, fmt.Errorf("Not Found")
}).AnyTimes()

Expand All @@ -64,17 +64,17 @@ func TestFindConfigFile(t *testing.T) {
defer ctrl.Finish()
mock := mock_oswrap.NewMockOsWrap(ctrl)

mock.EXPECT().Stat(test_helpers.RegexMatches(`^.*\.git$`)).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(test_helpers.RegexMatches(`^.*\.git$`)).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, fmt.Errorf("Not Found") // Never git
}).AnyTimes()

mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, fmt.Errorf("Not Found")
})
mock.EXPECT().Stat(gomock.Eq("../.sops.yaml")).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(gomock.Eq("../.sops.yaml")).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, fmt.Errorf("Not Found")
})
mock.EXPECT().Stat(gomock.Eq("../../.sops.yaml")).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(gomock.Eq("../../.sops.yaml")).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, nil //found
})

Expand All @@ -96,14 +96,14 @@ func TestFindConfigFile(t *testing.T) {
defer ctrl.Finish()
mock := mock_oswrap.NewMockOsWrap(ctrl)

mock.EXPECT().Stat(test_helpers.RegexMatches(`^.*\.git$`)).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(test_helpers.RegexMatches(`^.*\.git$`)).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, fmt.Errorf("Not Found") // Never git
}).AnyTimes()

mock.EXPECT().Stat(gomock.Not(gomock.Eq("directory/.sops.yaml"))).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(gomock.Not(gomock.Eq("directory/.sops.yaml"))).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, fmt.Errorf("Not Found")
}).AnyTimes()
mock.EXPECT().Stat(gomock.Eq("directory/.sops.yaml")).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(gomock.Eq("directory/.sops.yaml")).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, nil //found
})

Expand All @@ -126,10 +126,10 @@ func TestFindConfigFile(t *testing.T) {
defer ctrl.Finish()
mock := mock_oswrap.NewMockOsWrap(ctrl)

mock.EXPECT().Stat(gomock.Eq(".git")).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(gomock.Eq(".git")).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, nil //find git immediately
})
mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, fmt.Errorf("Not Found")
})

Expand All @@ -152,7 +152,7 @@ func TestLoadConfigFile(t *testing.T) {
defer ctrl.Finish()
mock := mock_oswrap.NewMockOsWrap(ctrl)

mock.EXPECT().ReadFile(gomock.Eq("filepath")).DoAndReturn(func(c string, args ...string) ([]byte, error) {
mock.EXPECT().ReadFile(gomock.Eq("filepath")).DoAndReturn(func(c string) ([]byte, error) {
return nil, fmt.Errorf("a file read error")
})

Expand All @@ -172,7 +172,7 @@ func TestLoadConfigFile(t *testing.T) {
defer ctrl.Finish()
mock := mock_oswrap.NewMockOsWrap(ctrl)

mock.EXPECT().ReadFile(gomock.Eq("filepath")).DoAndReturn(func(c string, args ...string) ([]byte, error) {
mock.EXPECT().ReadFile(gomock.Eq("filepath")).DoAndReturn(func(c string) ([]byte, error) {
yml := []byte(`
~~~not yaml
at all
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestLoadConfigFile(t *testing.T) {
defer ctrl.Finish()
mock := mock_oswrap.NewMockOsWrap(ctrl)

mock.EXPECT().ReadFile(gomock.Eq("filepath")).DoAndReturn(func(c string, args ...string) ([]byte, error) {
mock.EXPECT().ReadFile(gomock.Eq("filepath")).DoAndReturn(func(c string) ([]byte, error) {
yml := []byte(`
yaml:
- in
Expand Down Expand Up @@ -364,10 +364,10 @@ func TestGetConfigEncryptFiles(t *testing.T) {
defer ctrl.Finish()
mock := mock_oswrap.NewMockOsWrap(ctrl)

mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, nil
})
mock.EXPECT().ReadFile(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string, args ...string) ([]byte, error) {
mock.EXPECT().ReadFile(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string) ([]byte, error) {
yml := []byte(`
foo: bar
encrypted_files:
Expand Down Expand Up @@ -398,10 +398,10 @@ encrypted_files:
defer ctrl.Finish()
mock := mock_oswrap.NewMockOsWrap(ctrl)

mock.EXPECT().Stat(gomock.Eq(".git")).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(gomock.Eq(".git")).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, nil //find git immediately
}).AnyTimes()
mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, fmt.Errorf("Not Found")
}).AnyTimes()

Expand All @@ -421,10 +421,10 @@ encrypted_files:
defer ctrl.Finish()
mock := mock_oswrap.NewMockOsWrap(ctrl)

mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, nil
})
mock.EXPECT().ReadFile(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string, args ...string) ([]byte, error) {
mock.EXPECT().ReadFile(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string) ([]byte, error) {
yml := []byte(`~~not good`)

return yml, nil
Expand All @@ -446,10 +446,10 @@ encrypted_files:
defer ctrl.Finish()
mock := mock_oswrap.NewMockOsWrap(ctrl)

mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string, args ...string) (*os.FileInfo, error) {
mock.EXPECT().Stat(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string) (*os.FileInfo, error) {
return nil, nil
})
mock.EXPECT().ReadFile(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string, args ...string) ([]byte, error) {
mock.EXPECT().ReadFile(gomock.Eq(".sops.yaml")).DoAndReturn(func(c string) ([]byte, error) {
yml := []byte(`encrypted_files: [1,2,3]`)

return yml, nil
Expand Down