From 54b45206553d99e8980a65b968c0a8761fa1104c Mon Sep 17 00:00:00 2001 From: Oleg Utkin Date: Wed, 21 Aug 2024 10:35:48 -0700 Subject: [PATCH] chore: clean up, set up automatic builds --- .envrc | 1 - .github/workflows/00-release.yml | 34 +++++++++ .gitignore | 1 + .goreleaser.yaml | 20 ++--- .mise.toml | 2 + Makefile | 76 ++++++++++++++----- cmd/goprompt/cmdRender.go | 9 ++- .../prompt_asynczle_setup.adv.zsh | 0 scripts/fetch-goreleaser.sh | 15 ++++ 9 files changed, 122 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/00-release.yml create mode 100644 .mise.toml rename {plugin/zsh => misc}/prompt_asynczle_setup.adv.zsh (100%) create mode 100644 scripts/fetch-goreleaser.sh diff --git a/.envrc b/.envrc index aa94036..2c34c63 100644 --- a/.envrc +++ b/.envrc @@ -1,2 +1 @@ -eval $(gimme 1.20) PATH_add dist diff --git a/.github/workflows/00-release.yml b/.github/workflows/00-release.yml new file mode 100644 index 0000000..5a799e7 --- /dev/null +++ b/.github/workflows/00-release.yml @@ -0,0 +1,34 @@ +name: goreleaser + +on: + pull_request: + push: + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v5 + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + # either 'goreleaser' (default) or 'goreleaser-pro' + distribution: goreleaser + # 'latest', 'nightly', or a semver + version: '~> v2' + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/.gitignore b/.gitignore index bb3fabb..848b5d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea .vscode +.goreleaser dist diff --git a/.goreleaser.yaml b/.goreleaser.yaml index d799f6d..2f5efc7 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,6 +1,11 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj +version: 2 + before: hooks: - go mod tidy + builds: - main: ./cmd/goprompt binary: goprompt @@ -9,21 +14,12 @@ builds: goos: - linux - darwin + archives: - - name_template: >- - {{- .ProjectName }}_ - {{- title .Os }}_ - {{- if eq .Arch "amd64" }}x86_64 - {{- else if eq .Arch "386" }}i386 - {{- else }}{{ .Arch }}{{ end }} - {{- if .Arm }}v{{ .Arm }}{{ end -}} - format: binary - wrap_in_directory: false + - format: binary checksum: name_template: 'checksums.txt' + snapshot: name_template: "{{ incpatch .Version }}-next" - -# yaml-language-server: $schema=https://goreleaser.com/static/schema.json -# vim: set ts=2 sw=2 tw=0 fo=cnqoj diff --git a/.mise.toml b/.mise.toml new file mode 100644 index 0000000..fabed83 --- /dev/null +++ b/.mise.toml @@ -0,0 +1,2 @@ +[tools] +go = "1.21" diff --git a/Makefile b/Makefile index b4077f3..2430319 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,69 @@ -export prefix?=$(HOME)/.local -export bindir?=$(prefix)/bin +#? https://www.gnu.org/prep/standards/html_node/DESTDIR.html +export DESTDIR ?= +export PREFIX ?= $(HOME)/.local + +.default: info + +# ------------------------------------------------------------------------------ MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) CURRENT_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH))) +HOST_OS := $(shell uname -s) +HOST_ARCH := $(shell uname -m) -ZSH_PROMPT_SETUP_SCRIPT := $(CURRENT_DIR)/plugin/zsh/prompt_asynczle_setup.zsh +GORELEASER_VERSION := v2.0.1 +GORELEASER_TAR_URL := https://github.com/goreleaser/goreleaser/releases/download/$(GORELEASER_VERSION)/goreleaser_$(HOST_OS)_$(HOST_ARCH).tar.gz -USR_BIN_DIR := $(HOME)/bin -USR_ZSH_DIR := $(HOME)/.local/share/zsh-funcs +GORELEASER := ./.goreleaser -.PHONY: publish -publish: - goreleaser release --rm-dist +GO_FILES = $(sort $(shell find . -type f -name '*.go') go.mod go.sum) +STATIC_FILES = $(sort $(shell find ./plugin -type f)) +GORELEASER_FILES = $(sort .goreleaser .goreleaser.yaml) -.PHONY: release -release: - goreleaser release --rm-dist --snapshot --skip-publish +# ------------------------------------------------------------------------------ + +BUILD_DIST ?= dist +BUILD_GORELEASER_BIN ?= $(BUILD_DIST)/goreleaser + +INSTALL_BIN_DIR ?= $(DESTDIR)$(PREFIX)/bin +INSTALL_ZSH_FUNCS_DIR ?= $(DESTDIR)$(PREFIX)/share/zsh-funcs + +# ------------------------------------------------------------------------------ + +.PNONY: info +info: + @echo "OS: $(HOST_OS)" + @echo "ARCH: $(HOST_ARCH)" + @echo + @echo "PREFIX: $(PREFIX)" + @echo "INSTALL_BIN_DIR: $(INSTALL_BIN_DIR)" + @echo "INSTALL_ZSH_FUNCS_DIR: $(INSTALL_ZSH_FUNCS_DIR)" + +$(GORELEASER): + sh scripts/fetch-goreleaser.sh "$(GORELEASER_TAR_URL)" "$(GORELEASER)" -.PHONY: build -build: - goreleaser build --rm-dist --snapshot --single-target --output dist/goprompt +$(INSTALL_BIN_DIR) $(INSTALL_ZSH_FUNCS_DIR): + mkdir -p $@ -.PHONY: install -install: build - mkdir -p "$(USR_BIN_DIR)" - cp dist/goprompt "$(USR_BIN_DIR)/goprompt" +# ------------------------------------------------------------------------------ + +.PHONY: clean build install release publish -.PHONY: clean clean: rm -rf dist + +build: $(BUILD_GORELEASER_BIN) + +install: $(BUILD_GORELEASER_BIN) $(INSTALL_BIN_DIR) $(INSTALL_ZSH_FUNCS_DIR) + cp "$(BUILD_GORELEASER_BIN)" "$(INSTALL_BIN_DIR)/goprompt" + +$(BUILD_GORELEASER_BIN): $(GO_FILES) $(STATIC_FILES) $(GORELEASER_FILES) + $(GORELEASER) build --clean --snapshot --single-target \ + --id goreleaser \ + --output "$(BUILD_GORELEASER_BIN)" + +release: + $(GORELEASER) release --clean --auto-snapshot --skip=publish + +publish: + $(GORELEASER) release --clean diff --git a/cmd/goprompt/cmdRender.go b/cmd/goprompt/cmdRender.go index cea29cb..50ff533 100644 --- a/cmd/goprompt/cmdRender.go +++ b/cmd/goprompt/cmdRender.go @@ -17,14 +17,15 @@ var ( Short: "render the prompt based on the results of query", } - flgRLoading = cmdRender.PersistentFlags().Bool( - "prompt-loading", false, - "is prompt query not yet done rendering", - ) flgREscapeMode = cmdRender.PersistentFlags().String( "escape-mode", "none", "color / escape rendering mode of the prompt (zsh, ascii, none)", ) + + flgRLoading = cmdRender.PersistentFlags().Bool( + "prompt-loading", false, + "notify that prompt query is ongoing", + ) flgRMode = cmdRender.PersistentFlags().String( "prompt-mode", "normal", "mode of the prompt (normal, edit)", diff --git a/plugin/zsh/prompt_asynczle_setup.adv.zsh b/misc/prompt_asynczle_setup.adv.zsh similarity index 100% rename from plugin/zsh/prompt_asynczle_setup.adv.zsh rename to misc/prompt_asynczle_setup.adv.zsh diff --git a/scripts/fetch-goreleaser.sh b/scripts/fetch-goreleaser.sh new file mode 100644 index 0000000..17602b3 --- /dev/null +++ b/scripts/fetch-goreleaser.sh @@ -0,0 +1,15 @@ +#!/bin/sh +set -euxo pipefail + +readonly GORELEASER_TAR_URL=$1 +readonly TARGET_BIN_PATH=$2 +readonly TMPDIR=$(mktemp -d) + +on_exit() { + rm -rf "$TMPDIR" +} +trap on_exit EXIT + +curl -sfL "${GORELEASER_TAR_URL}" -o "${TMPDIR}/goreleaser.tar.gz" +tar -xf "${TMPDIR}/goreleaser.tar.gz" -C "$TMPDIR" +cp "${TMPDIR}/goreleaser" "${TARGET_BIN_PATH}"