diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8676e0f..0f0ca13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,31 +40,49 @@ jobs: if [[ $GITHUB_REF != "refs/tags/v"* ]]; then VERSION="${GITHUB_SHA::7}" fi - EXE="zsv-playground-$VERSION-linux-amd64" - ZIP="$EXE.zip" - { - echo "VERSION=$VERSION" - echo "EXE=$EXE" - echo "ZIP=$ZIP" - } | tee -a "$GITHUB_ENV" + echo "VERSION=$VERSION" | tee -a "$GITHUB_ENV" - - name: Build (linux/amd64) + - name: Build run: | - GOOS=linux GOARCH=amd64 go build -v -x -ldflags '-w -s' -o "$EXE" - zip "$ZIP" "$EXE" + for OS in linux darwin freebsd; do + EXE="zsv-playground-$VERSION-amd64-$OS" + GOOS="$OS" GOARCH=amd64 go build -ldflags '-w -s' -o "$EXE" + ZIP="$EXE.zip" + zip "$ZIP" "$EXE" + echo "$(echo $OS | tr [:lower:] [:upper:])_ZIP=$ZIP" | tee -a "$GITHUB_ENV" + done + file zsv-playground* + ls -hl *.zip - - name: Upload build artifact [${{ env.ZIP }}] + - name: Upload [${{ env.LINUX_ZIP }}] uses: actions/upload-artifact@v4 with: - name: '${{ env.ZIP }}' - path: '${{ env.ZIP }}' + name: ${{ env.LINUX_ZIP }} + path: ${{ env.LINUX_ZIP }} if-no-files-found: error - - name: Upload with release [${{ env.ZIP }}] + - name: Upload ${{ env.DARWIN_ZIP }} + uses: actions/upload-artifact@v4 + with: + name: ${{ env.DARWIN_ZIP }} + path: ${{ env.DARWIN_ZIP }} + if-no-files-found: error + + - name: Upload ${{ env.FREEBSD_ZIP }} + uses: actions/upload-artifact@v4 + with: + name: ${{ env.FREEBSD_ZIP }} + path: ${{ env.FREEBSD_ZIP }} + if-no-files-found: error + + - name: Upload with release uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/v') with: - files: '${{ env.ZIP }}' + files: | + ${{ env.LINUX_ZIP }} + ${{ env.DARWIN_ZIP }} + ${{ env.FREEBSD_ZIP }} - name: Bump version on release [${{ env.VERSION }}] if: startsWith(github.ref, 'refs/tags/v') diff --git a/README.md b/README.md index b08f595..93e081c 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,10 @@ [![GitHub release (latest by date)](https://img.shields.io/github/v/release/iamAzeem/zsv-playground?style=flat-square)](https://github.com/iamazeem/zsv-playground/releases) [![Buy Me a Coffee](https://img.shields.io/badge/Support-Buy%20Me%20A%20Coffee-orange.svg?style=flat-square)](https://www.buymeacoffee.com/iamazeem) -[`zsv-playground`](https://github.com/iamazeem/zsv-playground) is an x64 Linux -playground for [`zsv`](https://github.com/liquidaty/zsv) CLI executable. +[`zsv-playground`](https://github.com/iamazeem/zsv-playground) is a playground +for [`zsv`](https://github.com/liquidaty/zsv) CLI executable. -Locally tested on Ubuntu 22.04 LTS with Chrome 122.0.6261.128. +It is available for AMD64 Linux, MacOS, and FreeBSD. > [!NOTE] > @@ -40,7 +40,7 @@ Locally tested on Ubuntu 22.04 LTS with Chrome 122.0.6261.128. ## Download -Download the latest binary from the +Download the latest binaries from the [releases](https://github.com/iamazeem/zsv-playground/releases) page. ## Run diff --git a/cache.go b/cache.go index 566f0fd..53d2eeb 100644 --- a/cache.go +++ b/cache.go @@ -10,11 +10,31 @@ import ( "net/http" "os" "path/filepath" + "runtime" "strings" "github.com/google/go-github/v60/github" ) +const ( + archive = "tar.gz" + cacheDir = "zsv" +) + +func getTriplet() string { + switch runtime.GOOS { + case "linux": + return "amd64-linux-gcc" + case "darwin": + return "amd64-macosx-gcc" + case "freebsd": + return "amd64-freebsd-gcc" + default: + log.Printf("%v not supported", runtime.GOOS) + return "" + } +} + func initCache() bool { log.Println("initializing cache") @@ -116,6 +136,9 @@ func setupCache() ([]string, error) { return nil, fmt.Errorf("failed to load cache") } + owner := "liquidaty" + repo := "zsv" + ctx := context.Background() client := github.NewClient(nil) opts := &github.ListOptions{Page: 1, PerPage: 3} @@ -133,6 +156,7 @@ func setupCache() ([]string, error) { // tag > id m := map[string]int64{} + suffix := getTriplet() + "." + archive for _, r := range releases { tag := r.GetTagName() versions = append(versions, tag) @@ -245,7 +269,7 @@ func untarZsvTarGz(targetDir string, r io.Reader) error { } func getExePath(version string) string { - return fmt.Sprintf("%v/%v/%v/bin/zsv", cacheDir, version, triplet) + return filepath.Join(cacheDir, version, getTriplet(), "bin", "zsv") } func getExePaths(versions []string) []string { diff --git a/constants.go b/constants.go deleted file mode 100644 index 0ff790f..0000000 --- a/constants.go +++ /dev/null @@ -1,10 +0,0 @@ -package main - -const ( - owner = "liquidaty" - repo = "zsv" - triplet = "amd64-linux-gcc" - archive = "tar.gz" - suffix = triplet + "." + archive - cacheDir = "zsv" -) diff --git a/http_server.go b/http_server.go index 4643c9d..aa0e2fa 100644 --- a/http_server.go +++ b/http_server.go @@ -106,7 +106,7 @@ func startHTTPServer(address string, zsvVersions []string, zsvCLIsJson string) { server := &http.Server{Addr: address} go func() { - log.Printf("starting http server on %v [graceful shutdown on SIGINT]", address) + log.Printf("starting http server on %v [press CTRL+C for graceful shutdown]", address) if err := server.ListenAndServe(); err != nil { log.Fatalf("failed to start HTTP server, error: %v", err) } diff --git a/main.go b/main.go index 768ce16..386b505 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "log" + "runtime" ) func init() { @@ -20,7 +21,7 @@ func main() { return } - log.Printf("starting zsv playground [%v]", version) + log.Printf("starting zsv-playground %v [os: %v, arch: %v]", version, runtime.GOOS, runtime.GOARCH) zsvVersions, err := setupCache() if err != nil {