-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bruno Calza <[email protected]>
- Loading branch information
1 parent
8f862a7
commit 628b6b7
Showing
6 changed files
with
192 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Generate binaries | ||
on: | ||
release: | ||
types: | ||
- created | ||
permissions: | ||
contents: write | ||
jobs: | ||
binaries: | ||
runs-on: ubuntu-latest | ||
container: | ||
image: ghcr.io/goreleaser/goreleaser-cross:v1.18 | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: 'true' | ||
- name: Fetch repo | ||
run: git fetch --prune --unshallow | ||
- name: Install Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: v1.21.x | ||
- name: Release | ||
uses: goreleaser/goreleaser-action@v4 | ||
with: | ||
distribution: goreleaser | ||
version: latest | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# goreleaser.yml | ||
before: | ||
hooks: | ||
- go mod tidy | ||
|
||
env: | ||
- CGO_ENABLED=1 | ||
|
||
project_name: sqlite-exporter | ||
|
||
builds: | ||
- id: sqlite-exporter-darwin-amd64 | ||
binary: sqlite-exporter | ||
main: . | ||
goarch: | ||
- amd64 | ||
goos: | ||
- darwin | ||
env: | ||
- CC=o64-clang | ||
- CXX=o64-clang++ | ||
flags: | ||
- -trimpath | ||
ldflags: | ||
- -s -w -X main.version={{.Version}} -X main.commit={{.FullCommit}} -X main.date={{.CommitDate}} | ||
- id: sqlite-exporter-darwin-arm64 | ||
binary: sqlite-exporter | ||
main: . | ||
goarch: | ||
- arm64 | ||
goos: | ||
- darwin | ||
env: | ||
- CC=oa64-clang | ||
- CXX=oa64-clang++ | ||
flags: | ||
- -trimpath | ||
ldflags: | ||
- -s -w -X main.version={{.Version}} -X main.commit={{.FullCommit}} -X main.date={{.CommitDate}} | ||
- id: sqlite-exporter-linux-amd64 | ||
binary: sqlite-exporter | ||
main: . | ||
goarch: | ||
- amd64 | ||
goos: | ||
- linux | ||
env: | ||
- CC=x86_64-linux-gnu-gcc | ||
- CXX=x86_64-linux-gnu-g++ | ||
flags: | ||
- -trimpath | ||
ldflags: | ||
- -s -w -X main.version={{.Version}} -X main.commit={{.FullCommit}} -X main.date={{.CommitDate}} | ||
- id: sqlite-exporter-linux-arm64 | ||
binary: sqlite-exporter | ||
main: . | ||
goarch: | ||
- arm64 | ||
goos: | ||
- linux | ||
env: | ||
- CC=aarch64-linux-gnu-gcc | ||
- CXX=aarch64-linux-gnu-g++ | ||
flags: | ||
- -trimpath | ||
ldflags: | ||
- -s -w -X main.version={{.Version}} -X main.commit={{.FullCommit}} -X main.date={{.CommitDate}} | ||
|
||
archives: | ||
- id: sqlite-exporter-archive | ||
format: tar.gz | ||
files: | ||
- none* | ||
builds: | ||
- sqlite-exporter-darwin-amd64 | ||
- sqlite-exporter-darwin-arm64 | ||
- sqlite-exporter-linux-amd64 | ||
- sqlite-exporter-linux-arm64 | ||
name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}" | ||
|
||
checksum: | ||
disable: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/DataDog/zstd" | ||
"github.com/pkg/errors" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
// Decompress decompresses a zstd file. | ||
func Decompress(path string) (string, error) { | ||
file, err := os.Open(path) | ||
if err != nil { | ||
return "", fmt.Errorf("open file: %s", err) | ||
} | ||
pr, pw := io.Pipe() | ||
gzR := zstd.NewReader(file) | ||
|
||
errs := errgroup.Group{} | ||
errs.Go(func() error { | ||
if _, err := io.Copy(pw, gzR); err != nil { | ||
return errors.Errorf("copy to writer: %s", err) | ||
} | ||
|
||
if err := gzR.Close(); err != nil { | ||
return errors.Errorf("closing reader: %s", err) | ||
} | ||
if err := pw.Close(); err != nil { | ||
return errors.Errorf("closing pipe writer: %s", err) | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
newFilepath := strings.TrimSuffix(path, "."+filepath.Ext(path)) | ||
df, err := os.OpenFile(newFilepath, os.O_CREATE|os.O_WRONLY, 0o755) | ||
if err != nil { | ||
return "", errors.Errorf("open new file: %s", err) | ||
} | ||
|
||
writer := bufio.NewWriter(df) | ||
if _, err := io.Copy(writer, pr); err != nil { | ||
return "", errors.Errorf("copy dest file: %s", err) | ||
} | ||
|
||
if err := errs.Wait(); err != nil { | ||
return "", errors.Errorf("errgroup wait: %s", err) | ||
} | ||
return newFilepath, nil | ||
} |