Skip to content

Commit

Permalink
Support MacOS and FreeBSD builds (#13)
Browse files Browse the repository at this point in the history
* Remove constants.go

* Add Windows, MacOS, and FreeBSD builds

* Fix zip creation

* Fix *_ZIP env var

* Update README

* Scope constants

* Update log

* Fix CI build

* Fix build OS

* Remove redundant build flags

* Fix zsv extraction for Windows

* Add .exe suffix to Windows binary

* Use OS specific path separator

* Use cmd on Windows and sh on *nix

* Revert Windows changes

* Update log
  • Loading branch information
iamazeem authored Mar 23, 2024
1 parent e585d0f commit 3a54ebc
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 32 deletions.
48 changes: 33 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
>
Expand Down Expand Up @@ -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
Expand Down
26 changes: 25 additions & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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}
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 0 additions & 10 deletions constants.go

This file was deleted.

2 changes: 1 addition & 1 deletion http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"log"
"runtime"
)

func init() {
Expand All @@ -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 {
Expand Down

0 comments on commit 3a54ebc

Please sign in to comment.