-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Replace goreleaser with justfile and scripts
- Loading branch information
Showing
6 changed files
with
433 additions
and
50 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
GIT_DIR := `git rev-parse --show-toplevel` | ||
|
||
MAIN := "./cmd/deepl" | ||
BIN_NAME := "deepl" | ||
BIN_DIR := "bin" | ||
DIST_DIR := "dist" | ||
|
||
# list available recipes | ||
default: | ||
@just --list | ||
|
||
# format code | ||
fmt: | ||
go fmt ./... | ||
|
||
# lint code | ||
lint: | ||
golangci-lint run ./... | ||
|
||
# vet code | ||
vet: | ||
go vet ./... | ||
|
||
# build application | ||
build *args="": | ||
{{GIT_DIR}}/scripts/build.sh -p {{MAIN}} {{args}} | ||
|
||
# create binary distribution | ||
dist *args="": | ||
{{GIT_DIR}}/scripts/dist.sh -p {{MAIN}} {{args}} | ||
|
||
# create a new release | ||
release *args="": clean | ||
{{GIT_DIR}}/scripts/release.sh {{args}} | ||
|
||
changes from="" to="": | ||
#!/bin/sh | ||
source {{GIT_DIR}}/scripts/functions.sh | ||
get_changes {{from}} {{to}} | ||
|
||
clean: | ||
@# build artifacts | ||
@echo "rm {{BIN_DIR}}/{{BIN_NAME}}" | ||
@-[ -f {{BIN_DIR}}/{{BIN_NAME}} ] && rm {{BIN_DIR}}/{{BIN_NAME}} | ||
@-[ -d {{BIN_DIR}} ] && rmdir {{BIN_DIR}} | ||
|
||
@# distribution archives | ||
@echo "rm {{DIST_DIR}}/{{BIN_NAME}}_*.tar.gz" | ||
@rm {{DIST_DIR}}/{{BIN_NAME}}_*.tar.gz 2>/dev/null || true | ||
@echo "rm {{DIST_DIR}}/{{BIN_NAME}}_*.zip" | ||
@rm {{DIST_DIR}}/{{BIN_NAME}}_*.zip 2>/dev/null || true | ||
@-[ -d {{DIST_DIR}} ] && rmdir {{DIST_DIR}} | ||
|
||
# --- | ||
|
||
_system-info: | ||
@echo "{{os()}}_{{arch()}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
usage() { echo "usage: $(basename -- $0) [-h] [-v] [-o OUT] [-p PKG]" 1>&2; } | ||
|
||
package="" | ||
output="" | ||
verbose=false | ||
while getopts ":ho:p:v" opt; do | ||
case "${opt}" in | ||
h) | ||
usage | ||
exit 0 | ||
;; | ||
o) | ||
output=${OPTARG} | ||
;; | ||
p) | ||
package=${OPTARG} | ||
;; | ||
v) | ||
verbose=true | ||
;; | ||
*) | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# load common helpers | ||
scriptsdir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) | ||
source "${scriptsdir}/functions.sh" | ||
|
||
version=$(get_version) | ||
commit_sha=$(get_commit_sha) | ||
commit_date=$(get_commit_date) | ||
|
||
if [ -z "${package}" ]; then | ||
package="." | ||
fi | ||
|
||
if [ -z "${output}" ]; then | ||
git_dir=$(get_git_dir) | ||
bin_dir="${git_dir}/bin" | ||
bin_name=$(basename $(realpath "${package}")) | ||
output="${bin_dir}/${bin_name}" | ||
fi | ||
|
||
goos=${GOOS:-$(go env GOHOSTOS)} | ||
goarch=${GOARCH:-$(go env GOHOSTARCH)} | ||
|
||
${verbose} && echo "Building for ${goos}/${goarch}..." | ||
GOOS=${goos} GOARCH=${goarch} go build \ | ||
-ldflags "-X 'main.version=${version}' -X 'main.commit=${commit_sha}' -X 'main.date=${commit_date}'" \ | ||
-o "${output}" \ | ||
"${package}" | ||
${verbose} && echo "Building for ${goos}/${goarch}... done" | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
usage() { echo "usage: $(basename -- $0) [-h] [-v] [-n NAME] [-d DIR] [-p PKG]" 1>&2; } | ||
|
||
package="" | ||
dist_dir="" | ||
bin_name="" | ||
verbose=false | ||
while getopts ":hd:n:p:v" opt; do | ||
case "${opt}" in | ||
h) | ||
usage | ||
exit 0 | ||
;; | ||
d) | ||
dist_dir=${OPTARG} | ||
;; | ||
n) | ||
bin_name=${OPTARG} | ||
;; | ||
p) | ||
package=${OPTARG} | ||
;; | ||
v) | ||
verbose=true | ||
;; | ||
*) | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# load common helpers | ||
scriptsdir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) | ||
source "${scriptsdir}/functions.sh" | ||
|
||
if [ -z "${package}" ]; then | ||
package="." | ||
fi | ||
|
||
if [ -z "${dist_dir}" ]; then | ||
git_dir=$(get_git_dir) | ||
dist_dir="${git_dir}/dist" | ||
fi | ||
|
||
if [ -z "${bin_name}" ]; then | ||
bin_name=$(basename $(realpath "${package}")) | ||
fi | ||
|
||
version=$(get_version) | ||
|
||
declare -A OSARCHMAP=( | ||
[linux]="amd64,arm,arm64" | ||
[darwin]="amd64,arm64" | ||
[windows]="amd64,arm,arm64" | ||
) | ||
|
||
${verbose} && echo "Building binaries..." | ||
for os in ${!OSARCHMAP[@]}; do | ||
for arch in ${OSARCHMAP[$os]//,/ }; do | ||
tmp_dir=${dist_dir}/${bin_name}_${version}_${os}_${arch} | ||
|
||
out="${tmp_dir}/${bin_name}" | ||
|
||
${verbose} && echo " for ${os}/${arch}" | ||
GOOS=${os} GOARCH=${arch} ${scriptsdir}/build.sh -o "${out}" -p "${package}" | ||
done | ||
done | ||
${verbose} && echo "Building binaries... done" | ||
|
||
${verbose} && echo "Creating package archives..." | ||
for os in ${!OSARCHMAP[@]}; do | ||
dirs=$(find ${dist_dir}/ -mindepth 1 -maxdepth 1 -type d -name ${bin_name}_${version}_${os}_*) | ||
|
||
case "${os}" in | ||
linux | darwin) | ||
for dir in ${dirs}; do | ||
find $dir -printf "%P\n" \ | ||
| tar -czf ${dir}.tar.gz --no-recursion -C ${dir} -T - | ||
|
||
rm -r ${dir} | ||
done | ||
;; | ||
windows) | ||
for dir in ${dirs}; do | ||
(cd ${dir} && zip -q -r - .) > ${dir}.zip | ||
|
||
rm -r ${dir} | ||
done | ||
;; | ||
esac | ||
done | ||
${verbose} && echo "Creating package archives... done" | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/sh | ||
|
||
get_git_dir() { | ||
git rev-parse --show-toplevel | ||
} | ||
|
||
get_tag() { | ||
git describe --exact-match 2>/dev/null | ||
} | ||
|
||
get_commit_sha() { | ||
git rev-parse --verify ${1:-HEAD} | ||
} | ||
|
||
get_commit_date() { | ||
TZ=UTC git show --no-patch --format='%cd' --date='format-local:%Y-%m-%dT%H:%M:%SZ' ${1:-HEAD} | ||
} | ||
|
||
get_pseudo_version() { | ||
ref=${1:-"HEAD"} | ||
prefix=${2:-"v0.0.0"} | ||
|
||
latest_tag=$(git describe --tags --abbrev=0) | ||
if [ -n "${latest_tag}" ]; then | ||
prefix=${latest_tag}-$(git rev-list --count ${latest_tag}..${ref}) | ||
fi | ||
|
||
# UTC time the revision was created (yyyymmddhhmmss). | ||
timestamp=$(TZ=UTC git show --no-patch --format='%cd' --date='format-local:%Y%m%d%H%M%S' ${ref}) | ||
|
||
# 12-character prefix of the commit hash | ||
revision=$(git rev-parse --short=12 --verify ${ref}) | ||
|
||
echo "${prefix}-${timestamp}-${revision}" | ||
} | ||
|
||
get_version() { | ||
version=$(get_pseudo_version) | ||
|
||
tag=$(git describe --exact-match 2>/dev/null || true) | ||
if [ -n "${tag}" ]; then | ||
version=${tag} | ||
fi | ||
|
||
echo ${version} | ||
} | ||
|
||
is_dirty() { | ||
! git diff --quiet | ||
} | ||
|
||
is_tagged() { | ||
test -n "$(get_tag)" | ||
} | ||
|
||
get_changes() { | ||
from=${1:-$(git describe --tags --abbrev=0)} | ||
to=${2:-HEAD} | ||
|
||
if [ "${from}" == "$(git describe --tags --exact-match ${to} 2>/dev/null)" ]; then | ||
from=$(git describe --tags --abbrev=0 --exclude=${from}) | ||
fi | ||
|
||
git log --oneline --no-decorate ${from}..${to} | ||
} |
Oops, something went wrong.