Skip to content

Commit 54b4520

Browse files
committed
chore: clean up, set up automatic builds
1 parent 0aafd67 commit 54b4520

File tree

9 files changed

+122
-36
lines changed

9 files changed

+122
-36
lines changed

.envrc

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
eval $(gimme 1.20)
21
PATH_add dist

.github/workflows/00-release.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: goreleaser
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
goreleaser:
12+
runs-on: ubuntu-latest
13+
steps:
14+
-
15+
name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
-
20+
name: Set up Go
21+
uses: actions/setup-go@v5
22+
-
23+
name: Run GoReleaser
24+
uses: goreleaser/goreleaser-action@v6
25+
with:
26+
# either 'goreleaser' (default) or 'goreleaser-pro'
27+
distribution: goreleaser
28+
# 'latest', 'nightly', or a semver
29+
version: '~> v2'
30+
args: release --clean
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
34+
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
.vscode
3+
.goreleaser
34
dist

.goreleaser.yaml

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
2+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
3+
version: 2
4+
15
before:
26
hooks:
37
- go mod tidy
8+
49
builds:
510
- main: ./cmd/goprompt
611
binary: goprompt
@@ -9,21 +14,12 @@ builds:
914
goos:
1015
- linux
1116
- darwin
17+
1218
archives:
13-
- name_template: >-
14-
{{- .ProjectName }}_
15-
{{- title .Os }}_
16-
{{- if eq .Arch "amd64" }}x86_64
17-
{{- else if eq .Arch "386" }}i386
18-
{{- else }}{{ .Arch }}{{ end }}
19-
{{- if .Arm }}v{{ .Arm }}{{ end -}}
20-
format: binary
21-
wrap_in_directory: false
19+
- format: binary
2220

2321
checksum:
2422
name_template: 'checksums.txt'
23+
2524
snapshot:
2625
name_template: "{{ incpatch .Version }}-next"
27-
28-
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
29-
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

.mise.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tools]
2+
go = "1.21"

Makefile

+57-19
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,69 @@
1-
export prefix?=$(HOME)/.local
2-
export bindir?=$(prefix)/bin
1+
#? https://www.gnu.org/prep/standards/html_node/DESTDIR.html
2+
export DESTDIR ?=
3+
export PREFIX ?= $(HOME)/.local
4+
5+
.default: info
6+
7+
# ------------------------------------------------------------------------------
38

49
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
510
CURRENT_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
11+
HOST_OS := $(shell uname -s)
12+
HOST_ARCH := $(shell uname -m)
613

7-
ZSH_PROMPT_SETUP_SCRIPT := $(CURRENT_DIR)/plugin/zsh/prompt_asynczle_setup.zsh
14+
GORELEASER_VERSION := v2.0.1
15+
GORELEASER_TAR_URL := https://github.com/goreleaser/goreleaser/releases/download/$(GORELEASER_VERSION)/goreleaser_$(HOST_OS)_$(HOST_ARCH).tar.gz
816

9-
USR_BIN_DIR := $(HOME)/bin
10-
USR_ZSH_DIR := $(HOME)/.local/share/zsh-funcs
17+
GORELEASER := ./.goreleaser
1118

12-
.PHONY: publish
13-
publish:
14-
goreleaser release --rm-dist
19+
GO_FILES = $(sort $(shell find . -type f -name '*.go') go.mod go.sum)
20+
STATIC_FILES = $(sort $(shell find ./plugin -type f))
21+
GORELEASER_FILES = $(sort .goreleaser .goreleaser.yaml)
1522

16-
.PHONY: release
17-
release:
18-
goreleaser release --rm-dist --snapshot --skip-publish
23+
# ------------------------------------------------------------------------------
24+
25+
BUILD_DIST ?= dist
26+
BUILD_GORELEASER_BIN ?= $(BUILD_DIST)/goreleaser
27+
28+
INSTALL_BIN_DIR ?= $(DESTDIR)$(PREFIX)/bin
29+
INSTALL_ZSH_FUNCS_DIR ?= $(DESTDIR)$(PREFIX)/share/zsh-funcs
30+
31+
# ------------------------------------------------------------------------------
32+
33+
.PNONY: info
34+
info:
35+
@echo "OS: $(HOST_OS)"
36+
@echo "ARCH: $(HOST_ARCH)"
37+
@echo
38+
@echo "PREFIX: $(PREFIX)"
39+
@echo "INSTALL_BIN_DIR: $(INSTALL_BIN_DIR)"
40+
@echo "INSTALL_ZSH_FUNCS_DIR: $(INSTALL_ZSH_FUNCS_DIR)"
41+
42+
$(GORELEASER):
43+
sh scripts/fetch-goreleaser.sh "$(GORELEASER_TAR_URL)" "$(GORELEASER)"
1944

20-
.PHONY: build
21-
build:
22-
goreleaser build --rm-dist --snapshot --single-target --output dist/goprompt
45+
$(INSTALL_BIN_DIR) $(INSTALL_ZSH_FUNCS_DIR):
46+
mkdir -p $@
2347

24-
.PHONY: install
25-
install: build
26-
mkdir -p "$(USR_BIN_DIR)"
27-
cp dist/goprompt "$(USR_BIN_DIR)/goprompt"
48+
# ------------------------------------------------------------------------------
49+
50+
.PHONY: clean build install release publish
2851

29-
.PHONY: clean
3052
clean:
3153
rm -rf dist
54+
55+
build: $(BUILD_GORELEASER_BIN)
56+
57+
install: $(BUILD_GORELEASER_BIN) $(INSTALL_BIN_DIR) $(INSTALL_ZSH_FUNCS_DIR)
58+
cp "$(BUILD_GORELEASER_BIN)" "$(INSTALL_BIN_DIR)/goprompt"
59+
60+
$(BUILD_GORELEASER_BIN): $(GO_FILES) $(STATIC_FILES) $(GORELEASER_FILES)
61+
$(GORELEASER) build --clean --snapshot --single-target \
62+
--id goreleaser \
63+
--output "$(BUILD_GORELEASER_BIN)"
64+
65+
release:
66+
$(GORELEASER) release --clean --auto-snapshot --skip=publish
67+
68+
publish:
69+
$(GORELEASER) release --clean

cmd/goprompt/cmdRender.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ var (
1717
Short: "render the prompt based on the results of query",
1818
}
1919

20-
flgRLoading = cmdRender.PersistentFlags().Bool(
21-
"prompt-loading", false,
22-
"is prompt query not yet done rendering",
23-
)
2420
flgREscapeMode = cmdRender.PersistentFlags().String(
2521
"escape-mode", "none",
2622
"color / escape rendering mode of the prompt (zsh, ascii, none)",
2723
)
24+
25+
flgRLoading = cmdRender.PersistentFlags().Bool(
26+
"prompt-loading", false,
27+
"notify that prompt query is ongoing",
28+
)
2829
flgRMode = cmdRender.PersistentFlags().String(
2930
"prompt-mode", "normal",
3031
"mode of the prompt (normal, edit)",

scripts/fetch-goreleaser.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
set -euxo pipefail
3+
4+
readonly GORELEASER_TAR_URL=$1
5+
readonly TARGET_BIN_PATH=$2
6+
readonly TMPDIR=$(mktemp -d)
7+
8+
on_exit() {
9+
rm -rf "$TMPDIR"
10+
}
11+
trap on_exit EXIT
12+
13+
curl -sfL "${GORELEASER_TAR_URL}" -o "${TMPDIR}/goreleaser.tar.gz"
14+
tar -xf "${TMPDIR}/goreleaser.tar.gz" -C "$TMPDIR"
15+
cp "${TMPDIR}/goreleaser" "${TARGET_BIN_PATH}"

0 commit comments

Comments
 (0)