Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Update go version, reduce PNG file size, add goreleaser #22

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
65 changes: 45 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
version: 2
version: 2.1
orbs:
gor: hubci/goreleaser@1.0.0
go: circleci/go@1.7.0

workflows:
main:
jobs:
- test
release:
jobs:
- test:
filters:
branches:
ignore: /.*/
tags:
only: /^v\d+\.\d+\.\d+$/
- gor/release:
version: 0.147.1
go-version: 1.16.5
filters:
branches:
ignore: /.*/
tags:
only: /^v\d+\.\d+\.\d+$/
jobs:
build:
docker:
- image: circleci/golang:1.14
working_directory: /go/src/github.com/remove-bg/go
test:
environment: # environment variables for the build itself
TEST_RESULTS: /tmp/test-results # path to where test results will be saved
executor:
name: go/default
tag: '1.16.5'
steps:
- checkout
- run: echo 'export PATH=$GOPATH/bin:$PATH' >> "$BASH_ENV"
- restore_cache:
keys:
- vendor-{{ checksum "Gopkg.lock" }}
- run: bin/setup
- run: bin/test
- save_cache:
key: vendor-{{ checksum "Gopkg.lock" }}
paths:
- vendor
- run: mkdir -p $TEST_RESULTS # create the test results directory
- go/load-cache
- go/mod-download
- go/save-cache
- run:
name: Run unit tests
# store the results of our tests in the $TEST_RESULTS directory
command: |
PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname)
gotestsum --junitfile ${TEST_RESULTS}/gotestsum-report.xml -- $PACKAGE_NAMES
- store_artifacts: # upload test summary for display in Artifacts
path: /tmp/test-results
destination: raw-test-output
- store_test_results: # upload test results for display in Test Summary
path: /tmp/test-results

workflows:
version: 2
build:
jobs:
- build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ vendor
.idea
tmp
removebg
dist
dist
pkg
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

[![CircleCI](https://circleci.com/gh/remove-bg/go.svg?style=shield)](https://circleci.com/gh/remove-bg/go)

Run the test locally. Workflows cannot be run locally!

```
circleci local execute --job test
```

brewmanandi marked this conversation as resolved.
Show resolved Hide resolved
## Installation

### Download
Expand Down
4 changes: 1 addition & 3 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

set -euox pipefail

dep ensure

go get -u github.com/onsi/ginkgo/ginkgo
go get -u github.com/maxbrunsfeld/counterfeiter
go get -u github.com/maxbrunsfeld/counterfeiter/v6
9 changes: 7 additions & 2 deletions composite/composite.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package composite

import (
"github.com/foobaz/lossypng/lossypng"
"github.com/remove-bg/go/storage"

"archive/zip"
Expand Down Expand Up @@ -48,9 +49,13 @@ func (c Compositor) Process(inputZipPath string, outputImagePath string) error {
return nil
}

func (c Compositor) savePng(image *image.NRGBA, outputPath string) {
func (c Compositor) savePng(image image.Image, outputPath string) {
compressedImage := lossypng.Compress(image, lossypng.NoConversion, 30)
buf := new(bytes.Buffer)
png.Encode(buf, image)
enc := &png.Encoder{
CompressionLevel: png.BestCompression,
}
enc.Encode(buf, compressedImage)
brewmanandi marked this conversation as resolved.
Show resolved Hide resolved
c.Storage.Write(outputPath, buf.Bytes())
}

Expand Down
21 changes: 21 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module kaleido.ai/go

go 1.16

require (
github.com/4kills/go-zlib v1.1.0 // indirect
github.com/bmatcuk/doublestar v1.3.4
github.com/foobaz/lossypng v0.0.0-20200814224715-48fa8819852a // indirect
github.com/joefitzgerald/rainbow-reporter v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.8
github.com/maxbrunsfeld/counterfeiter/v6 v6.4.1 // indirect
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.13.0
github.com/remove-bg/go v1.3.1
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/tools v0.1.4 // indirect
gopkg.in/AlecAivazis/survey.v1 v1.8.8
gopkg.in/h2non/gock.v1 v1.1.0
)
Loading