From b5b5978352e15375132cc2056037d2e8ec7238e5 Mon Sep 17 00:00:00 2001 From: Christian Zangl Date: Mon, 3 Jun 2024 15:45:39 +0200 Subject: [PATCH] ci --- .github/workflows/ci.yml | 23 ++++++++++++++++++++ .gitignore | 1 + cmd/zfind/main.go | 8 +++++++ scripts/chkfmt | 10 +++++++++ scripts/xbuild | 46 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100755 scripts/chkfmt create mode 100755 scripts/xbuild diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..83eec4d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,23 @@ +name: ci + +on: + push: + branches: [ master ] + pull_request: + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: "1.22" + + - name: chkfmt + run: scripts/chkfmt + + - name: xbuild + run: scripts/xbuild + diff --git a/.gitignore b/.gitignore index dd85f6a..70bb543 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /zfind +/dist diff --git a/cmd/zfind/main.go b/cmd/zfind/main.go index 478daec..a1cc323 100644 --- a/cmd/zfind/main.go +++ b/cmd/zfind/main.go @@ -26,6 +26,8 @@ type FileInfo struct { ModTime time.Time } +var appVersion = "vdev" + func (file FileInfo) Context() filter.VariableGetter { return func(name string) *filter.Value { @@ -223,6 +225,7 @@ func main() { Where string `short:"w" help:"The where-filter (using sql-where syntax, see -H)."` Long bool `short:"l" help:"Show long listing."` Paths []string `arg:"" name:"path" optional:"" help:"Paths to search."` + Version bool `short:"V" help:"Show version."` } arg := kong.Parse(&cli) @@ -232,6 +235,11 @@ func main() { os.Exit(0) } + if cli.Version { + fmt.Println(appVersion) + os.Exit(0) + } + if cli.Where == "" { cli.Where = "1" } diff --git a/scripts/chkfmt b/scripts/chkfmt new file mode 100755 index 0000000..ad53325 --- /dev/null +++ b/scripts/chkfmt @@ -0,0 +1,10 @@ +#!/bin/bash +set -eE -o pipefail + +res="$(gofmt -l . 2>&1)" + +if [ -n "$res" ]; then + echo "gofmt check failed:" + echo "${res}" + exit 1 +fi diff --git a/scripts/xbuild b/scripts/xbuild new file mode 100755 index 0000000..57b14bf --- /dev/null +++ b/scripts/xbuild @@ -0,0 +1,46 @@ +#!/bin/bash +set -eE -o pipefail + +if [ -z "$version" ]; then + version=$(git rev-parse HEAD) +fi + +mkdir -p dist +rm -f dist/* + +build() { + echo "- $1-$2" + rm -f dist/zfind + CGO_ENABLED=0 GOOS="$1" GOARCH="$2" go build -o dist -ldflags="-X main.appVersion=$version" ./cmd/zfind + + pushd dist + + case "$1" in + windows) + outfile="zfind-$1-$2.zip" + zip "$outfile" zfind.exe --move + ;; + *) + outfile="zfind-$1-$2.tar.gz" + tar -czf "$outfile" zfind --remove-files + ;; + esac + + popd +} + +build android arm64 +build darwin amd64 +build darwin arm64 +build freebsd amd64 +build freebsd arm64 +build freebsd riscv64 +build linux amd64 +build linux arm64 +build linux riscv64 +build netbsd amd64 +build netbsd arm64 +build openbsd amd64 +build openbsd arm64 +build windows amd64 +build windows arm64