Skip to content

Commit

Permalink
chore: clean up, set up automatic builds
Browse files Browse the repository at this point in the history
  • Loading branch information
NonLogicalDev committed Aug 21, 2024
1 parent 0aafd67 commit 54b4520
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 36 deletions.
1 change: 0 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
eval $(gimme 1.20)
PATH_add dist
34 changes: 34 additions & 0 deletions .github/workflows/00-release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.vscode
.goreleaser
dist
20 changes: 8 additions & 12 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
go = "1.21"
76 changes: 57 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
9 changes: 5 additions & 4 deletions cmd/goprompt/cmdRender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions scripts/fetch-goreleaser.sh
Original file line number Diff line number Diff line change
@@ -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}"

0 comments on commit 54b4520

Please sign in to comment.