Skip to content

Commit

Permalink
Implement GH Actions - 1 (#1)
Browse files Browse the repository at this point in the history
* Gofumpt

* Workflow for formatting check and test

* Docker build step
  • Loading branch information
mahesh-hegde authored Mar 9, 2024
1 parent cb5e790 commit 52a25d0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: default-pipeline
on: [push]
jobs:
check-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '^1.21.2'
- name: Install gofumpt
run: go install mvdan.cc/gofumpt@latest
- name: Check formatting
run: gofumpt -w -l . && git diff --exit-code
unit-test:
runs-on: ubuntu-latest
needs: [check-format]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '^1.21.2'
- name: Run tests
run: go test
build-docker-image:
runs-on: ubuntu-latest
needs: [unit-test]
if: ${{ startsWith(github.ref, 'refs/tags/') }}
env:
TAG_NAME: ${{ github.ref_name }}
IMAGE_NAME: ghcr.io/mahesh-hegde/zserv
steps:
- name: Docker login
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Docker build
run: docker build -t ghcr.io/mahesh-hegde/zserv:latest .
- name: Push latest image
run: docker push $IMAGE_NAME:latest
- name: Tag image
run: docker tag $IMAGE_NAME:latest $IMAGE_NAME:${TAG_NAME#v}
- name: Push tagged image
run: docker push $IMAGE_NAME:${TAG_NAME#v}
6 changes: 4 additions & 2 deletions streaming_zip_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ func (s *StreamingZipEntryReader) Seek(offset int64, whence int) (int64, error)
return -1, fmt.Errorf("unsupported seek parameters")
}

var _ io.ReadSeekCloser = &StreamingZipEntryReader{}
var _ fs.File = &StreamingZipEntryReader{}
var (
_ io.ReadSeekCloser = &StreamingZipEntryReader{}
_ fs.File = &StreamingZipEntryReader{}
)

// NewStreamingZipEntryReader returns a lazy reader with limited seek.
// `file` must not be a directory.
Expand Down
9 changes: 6 additions & 3 deletions zip_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ func NewBufferedZipEntry(f fs.File) *BufferedZipEntry {
return &BufferedZipEntry{f, bytes.NewReader(buf.Bytes())}
}

var _ io.ReadSeeker = &BufferedZipEntry{}
var _ fs.File = &BufferedZipEntry{}
var (
_ io.ReadSeeker = &BufferedZipEntry{}
_ fs.File = &BufferedZipEntry{}
)

var errBufferSizeExceeded = fmt.Errorf("size exceeds maximum allowed buffer size")

Expand Down Expand Up @@ -81,7 +83,8 @@ func OpenZipReaderFS(path string, options *Options) fs.FS {
}

func GetBufferingZipFS(reader io.ReaderAt, size int64,
maxBufferSize int64) BufferingZipFS {
maxBufferSize int64,
) BufferingZipFS {
zipReader, err := zip.NewReader(reader, size)
checkError(err, "cannot open input ZIP file")
return BufferingZipFS{zipReader, maxBufferSize}
Expand Down
1 change: 0 additions & 1 deletion zserv.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func main() {
}

if options.DetectRoot {

verbose("Detect root as: %s")
}

Expand Down
6 changes: 4 additions & 2 deletions zserv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ func TestBasicDownload(t *testing.T) {
}
for index, fs := range createBothTestZipReaderFS(entries) {
t.Run(fs.Name(), func(t *testing.T) {
go StartServer(&Options{Port: port + index, Host: "127.0.0.1",
Root: "."}, fs)
go StartServer(&Options{
Port: port + index, Host: "127.0.0.1",
Root: ".",
}, fs)
for _, entry := range entries {
bytes := downloadFile(port+index, entry.Name)
assert.Equal(t, entry.Body, string(bytes), "Download %s",
Expand Down

0 comments on commit 52a25d0

Please sign in to comment.