Skip to content

Commit

Permalink
enhance Makefile, fix linter issues and improve CI workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
maxihafer committed Oct 21, 2024
1 parent 9347e7f commit 4e46342
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 69 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
on: [push, pull_request]
env:
GO_VERSION: 1.23
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- run: go test -v ./...
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- uses: golangci/golangci-lint-action@v6
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea
bin
bin/
dist/
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
APP_NAME=content-prep
GOLANGCI_LINT_VERSION=1.61.0
LOCALBIN=$(shell pwd)/bin

.PHONY: dep
dep:
@echo "Installing dependencies..."
go mod tidy

.PHONY: build
build:
build: dep
@echo "Building..."
@go build -o bin/$(APP_NAME) main.go
go build -o dist/$(APP_NAME) main.go

.PHONY: lint
lint: $(LOCALBIN)/golangci-lint dep
@echo "Running golangci-lint version ${GOLANGCI_LINT_VERSION}..."
@$(LOCALBIN)/golangci-lint run

$(LOCALBIN)/golangci-lint:
@echo "Installing golangci-lint version ${GOLANGCI_LINT_VERSION}..."
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCALBIN) v${GOLANGCI_LINT_VERSION}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.23.2

require (
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
Expand All @@ -54,7 +52,6 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
Expand All @@ -68,7 +65,6 @@ go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
Expand Down
13 changes: 0 additions & 13 deletions pkg/cryptostream/aesstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,12 @@ import (
"crypto/sha256"
"errors"
"io"

"github.com/sirupsen/logrus"
)

const BufferSize int = 2097152
const IvSize int = 16
const HMACKeySize = 64

type loggingWriter struct {
w io.Writer
mode string
}

func (l loggingWriter) Write(p []byte) (n int, err error) {
logrus.WithField("mode", l.mode).Info("Write:", p)

return l.w.Write(p)
}

// Encrypt the stream using the given AES-CTR and SHA256-HMAC key
func Encrypt(in io.ReadSeeker, out io.WriteSeeker, keyAes []byte, iv []byte, hmacKey []byte) error {
AES, err := aes.NewCipher(keyAes)
Expand Down
48 changes: 1 addition & 47 deletions pkg/packager/packager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"testing"
"testing/fstest"

"github.com/pkg/errors"
"github.com/stretchr/testify/suite"
)

Expand All @@ -26,52 +25,6 @@ func (m mykeygen) GenerateKey(length int) ([]byte, error) {
return []byte(strings.Repeat(".", length)), nil
}

type mywriter struct {
buf []byte
pos int
}

func (m *mywriter) Write(p []byte) (n int, err error) {
minCap := m.pos + len(p)
if minCap > cap(m.buf) { // Make sure buf has enough capacity:
buf2 := make([]byte, len(m.buf), minCap+len(p)) // add some extra
copy(buf2, m.buf)
m.buf = buf2
}
if minCap > len(m.buf) {
m.buf = m.buf[:minCap]
}
copy(m.buf[m.pos:], p)
m.pos += len(p)
return len(p), nil
}

func (m *mywriter) Read(p []byte) (n int, err error) {
if m.pos >= len(m.buf) {
return 0, io.EOF
}
n = copy(p, m.buf[m.pos:])
m.pos += n
return n, nil
}

func (m *mywriter) Seek(offset int64, whence int) (int64, error) {
newPos, offs := 0, int(offset)
switch whence {
case io.SeekStart:
newPos = offs
case io.SeekCurrent:
newPos = m.pos + offs
case io.SeekEnd:
newPos = len(m.buf) + offs
}
if newPos < 0 {
return 0, errors.New("negative result pos")
}
m.pos = newPos
return int64(newPos), nil
}

func TestPackagerTestSuite(t *testing.T) {
suite.Run(t, new(PackagerTestSuite))
}
Expand Down Expand Up @@ -107,6 +60,7 @@ func (s *PackagerTestSuite) TestPackager() {
}

out, err := os.Create(path.Join(s.testDir, "test.intunewin"))
s.Require().NoError(err)

err = p.CreatePackage(context.Background(), s.fs, "test.exe", out)
s.Require().NoError(err)
Expand Down
5 changes: 4 additions & 1 deletion pkg/zipper/zipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ func UnzipToDirectory(ctx context.Context, archiveFilePath, outputFolderPath str
return errors.Errorf("illegal file path: %s", filePath)
}
if f.FileInfo().IsDir() {
os.MkdirAll(filePath, os.ModePerm)
err = os.MkdirAll(filePath, os.ModePerm)
if err != nil {
return errors.Wrapf(err, "failed to create directory")
}
continue
}

Expand Down

0 comments on commit 4e46342

Please sign in to comment.