Skip to content

Commit

Permalink
build: fix misc
Browse files Browse the repository at this point in the history
  • Loading branch information
ginokent committed Aug 25, 2023
1 parent b6d14a7 commit 20cd698
Show file tree
Hide file tree
Showing 7 changed files with 308 additions and 121 deletions.
47 changes: 25 additions & 22 deletions .bin/direnv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# shellcheck disable=SC2155
# MIT License Copyright (c) 2022 ginokent https://github.com/versenv/versenv
# LISENCE: https://github.com/versenv/versenv/blob/HEAD/LICENSE
set -Eeu -o pipefail

# versenv unique
Expand Down Expand Up @@ -48,22 +48,23 @@ ExecProgram() {
exec "${prog_version_exe:?}" "$@" <&0
}

# MIT License Copyright (c) 2021 ginokent https://github.com/rec-logger/rec.sh
# LISENCE: https://github.com/kunitsucom/rec.sh/blob/HEAD/LICENSE
# Common
if [ -t 2 ]; then REC_COLOR=true; else REC_COLOR=''; fi
_recRFC3339() { date "+%Y-%m-%dT%H:%M:%S%z" | sed "s/\(..\)$/:\1/"; }
_recCmd() { for a in "$@"; do if echo "${a:-}" | grep -Eq "[[:blank:]]"; then printf "'%s' " "${a:-}"; else printf "%s " "${a:-}"; fi; done | sed "s/ $//"; }
# Color
RecDefault() { test " ${REC_SEVERITY:-0}" -gt 000 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;35m DEFAULT\\033[0m] \"\$0\"\"}" 1>&2; }
RecDebug() { test " ${REC_SEVERITY:-0}" -gt 100 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;34m DEBUG\\033[0m] \"\$0\"\"}" 1>&2; }
RecInfo() { test " ${REC_SEVERITY:-0}" -gt 200 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;32m INFO\\033[0m] \"\$0\"\"}" 1>&2; }
RecNotice() { test " ${REC_SEVERITY:-0}" -gt 300 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;36m NOTICE\\033[0m] \"\$0\"\"}" 1>&2; }
RecWarning() { test " ${REC_SEVERITY:-0}" -gt 400 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;33m WARNING\\033[0m] \"\$0\"\"}" 1>&2; }
RecError() { test " ${REC_SEVERITY:-0}" -gt 500 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;31m ERROR\\033[0m] \"\$0\"\"}" 1>&2; }
RecCritical() { test " ${REC_SEVERITY:-0}" -gt 600 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;1;31m CRITICAL\\033[0m] \"\$0\"\"}" 1>&2; }
RecAlert() { test " ${REC_SEVERITY:-0}" -gt 700 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;41m ALERT\\033[0m] \"\$0\"\"}" 1>&2; }
RecEmergency() { test "${REC_SEVERITY:-0}" -gt 800 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;1;41mEMERGENCY\\033[0m] \"\$0\"\"}" 1>&2; }
RecDefault() { test " ${REC_SEVERITY:-0}" -gt 000 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;35m} DEFAULT${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecDebug() { test " ${REC_SEVERITY:-0}" -gt 100 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;34m} DEBUG${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecInfo() { test " ${REC_SEVERITY:-0}" -gt 200 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;32m} INFO${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecNotice() { test " ${REC_SEVERITY:-0}" -gt 300 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;36m} NOTICE${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecWarning() { test " ${REC_SEVERITY:-0}" -gt 400 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;33m} WARNING${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecError() { test " ${REC_SEVERITY:-0}" -gt 500 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;31m} ERROR${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecCritical() { test " ${REC_SEVERITY:-0}" -gt 600 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;1;31m} CRITICAL${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecAlert() { test " ${REC_SEVERITY:-0}" -gt 700 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;41m} ALERT${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecEmergency() { test "${REC_SEVERITY:-0}" -gt 800 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;1;41m}EMERGENCY${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecExec() { RecInfo "$ $(_recCmd "$@")" && "$@"; }
RecRun() { _dlm="####R#E#C#D#E#L#I#M#I#T#E#R####" _all=$({ _out=$("$@") && _rtn=$? || _rtn=$? && printf "\n%s" "${_dlm:?}${_out:-}" && return ${_rtn:-0}; } 2>&1) && _rtn=$? || _rtn=$? && _dlmno=$(echo "${_all:-}" | sed -n "/${_dlm:?}/=") && _cmd=$(_recCmd "$@") && _stdout=$(echo "${_all:-}" | tail -n +"${_dlmno:-1}" | sed "s/^${_dlm:?}//") && _stderr=$(echo "${_all:-}" | head -n "${_dlmno:-1}" | grep -v "^${_dlm:?}") && RecInfo "$ ${_cmd:-}" && { [ -z "${_stdout:-}" ] || RecInfo "${_stdout:?}"; } && { [ -z "${_stderr:-}" ] || RecWarning "${_stderr:?}"; } && return ${_rtn:-0}; }
RecRun() { _dlm="####R#E#C#D#E#L#I#M#I#T#E#R####" && _all=$({ _out=$("$@") && _rtn=$? || _rtn=$? && printf "\n%s" "${_dlm:?}${_out:-}" && return "${_rtn:-0}"; } 2>&1) && _rtn=$? || _rtn=$? && _dlmno=$(echo "${_all:-}" | sed -n "/${_dlm:?}/=") && _cmd=$(_recCmd "$@") && _stdout=$(echo "${_all:-}" | tail -n +"${_dlmno:-1}" | sed "s/^${_dlm:?}//") && _stderr=$(echo "${_all:-}" | head -n "${_dlmno:-1}" | grep -v "^${_dlm:?}") && RecInfo "$ ${_cmd:-}" && { [ -z "${_stdout:-}" ] || RecInfo "${_stdout:?}"; } && { [ -z "${_stderr:-}" ] || RecWarning "${_stderr:?}"; } && return "${_rtn:-0}"; }

# versenv common
DownloadURL() {
Expand All @@ -79,16 +80,18 @@ DownloadURL() {
fi
}

GetURL() {
local url="${1:?}"
if command -v wget >/dev/null; then
wget --secure-protocol=TLSv1_2 --dns-timeout=2 --connect-timeout=2 -q -O- "${url:?}"
elif command -v curl >/dev/null; then
curl --tlsv1.2 --connect-timeout 2 -fLRSs "${url:?}"
else
RecCritical "command not found: curl or wget"
exit 127
fi
GetURLs() {
for arg in "$@"; do
local url="${arg:?}"
if command -v wget >/dev/null; then
wget --secure-protocol=TLSv1_2 --dns-timeout=2 --connect-timeout=2 -q -O- "${url:?}"
elif command -v curl >/dev/null; then
curl --tlsv1.2 --connect-timeout 2 -fLRSs "${url:?}"
else
RecCritical "command not found: curl or wget"
exit 127
fi
done
}

HeadURL() {
Expand Down
58 changes: 28 additions & 30 deletions .bin/golangci-lint
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
# shellcheck disable=SC2155
# MIT License Copyright (c) 2022 ginokent https://github.com/versenv/versenv
# LISENCE: https://github.com/versenv/versenv/blob/HEAD/LICENSE
set -Eeu -o pipefail

# versenv unique
exe_filename=golangci-lint
env_key_version=GOLANGCI_VERSION
env_key_version=GOLANGCI_LINT_VERSION
git_url_prefix=https://github.com/golangci/golangci-lint

GetProgramLatestStableVersion() { HeadURL "${git_url_prefix:?}/releases/latest" | awk -F"/tag/" "/^[Ll]ocation:/ {print \$2}" | tr -d "[:cntrl:]" | tr -d "^v" | tail -n 1; }
Expand All @@ -17,14 +17,9 @@ FindTargetZipDownloadURL() {
local prog_os="${2:?}"
local prog_arch="${3:?}"
local path_suffix && path_suffix=$(
if ! GetURL "${git_url_prefix:?}/releases" | grep -Eo "href=\"[^\"]+/v?${prog_version:?}/[^\"]*${prog_os:?}[^\"]*${prog_arch:?}[^\"]*\.(zip|tar|tgz|tar\.gz)" | sed 's/href="//'; then
i=2
until { GetURL "${git_url_prefix:?}/releases?page=${i:?}" | grep -Eo "href=\"[^\"]+/v?${prog_version:?}/[^\"]*${prog_os:?}[^\"]*${prog_arch:?}[^\"]*\.(zip|tar|tgz|tar\.gz)" | sed 's/href="//'; }; do
i=$((i+1))
done
fi
GetURLs "${git_url_prefix:?}/releases/expanded_assets/"{,v}"${prog_version:?}" | grep -Eo "href=\"[^\"]+/v?${prog_version:?}/[^\"]*${prog_os:?}[^\"]*${prog_arch:?}[^\"]*\.(zip|tar|tgz|tar\.gz)" | sed 's/href="//'
)
echo "https://github.com/${path_suffix:?}"
echo "https://github.com${path_suffix:?}"
}

Unzip() {
Expand Down Expand Up @@ -79,22 +74,23 @@ ExecProgram() {
exec "${prog_version_exe:?}" "$@" <&0
}

# MIT License Copyright (c) 2021 ginokent https://github.com/rec-logger/rec.sh
# LISENCE: https://github.com/kunitsucom/rec.sh/blob/HEAD/LICENSE
# Common
if [ -t 2 ]; then REC_COLOR=true; else REC_COLOR=''; fi
_recRFC3339() { date "+%Y-%m-%dT%H:%M:%S%z" | sed "s/\(..\)$/:\1/"; }
_recCmd() { for a in "$@"; do if echo "${a:-}" | grep -Eq "[[:blank:]]"; then printf "'%s' " "${a:-}"; else printf "%s " "${a:-}"; fi; done | sed "s/ $//"; }
# Color
RecDefault() { test " ${REC_SEVERITY:-0}" -gt 000 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;35m DEFAULT\\033[0m] \"\$0\"\"}" 1>&2; }
RecDebug() { test " ${REC_SEVERITY:-0}" -gt 100 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;34m DEBUG\\033[0m] \"\$0\"\"}" 1>&2; }
RecInfo() { test " ${REC_SEVERITY:-0}" -gt 200 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;32m INFO\\033[0m] \"\$0\"\"}" 1>&2; }
RecNotice() { test " ${REC_SEVERITY:-0}" -gt 300 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;36m NOTICE\\033[0m] \"\$0\"\"}" 1>&2; }
RecWarning() { test " ${REC_SEVERITY:-0}" -gt 400 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;33m WARNING\\033[0m] \"\$0\"\"}" 1>&2; }
RecError() { test " ${REC_SEVERITY:-0}" -gt 500 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;31m ERROR\\033[0m] \"\$0\"\"}" 1>&2; }
RecCritical() { test " ${REC_SEVERITY:-0}" -gt 600 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;1;31m CRITICAL\\033[0m] \"\$0\"\"}" 1>&2; }
RecAlert() { test " ${REC_SEVERITY:-0}" -gt 700 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;41m ALERT\\033[0m] \"\$0\"\"}" 1>&2; }
RecEmergency() { test "${REC_SEVERITY:-0}" -gt 800 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [\\033[0;1;41mEMERGENCY\\033[0m] \"\$0\"\"}" 1>&2; }
RecDefault() { test " ${REC_SEVERITY:-0}" -gt 000 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;35m} DEFAULT${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecDebug() { test " ${REC_SEVERITY:-0}" -gt 100 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;34m} DEBUG${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecInfo() { test " ${REC_SEVERITY:-0}" -gt 200 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;32m} INFO${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecNotice() { test " ${REC_SEVERITY:-0}" -gt 300 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;36m} NOTICE${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecWarning() { test " ${REC_SEVERITY:-0}" -gt 400 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;33m} WARNING${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecError() { test " ${REC_SEVERITY:-0}" -gt 500 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;31m} ERROR${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecCritical() { test " ${REC_SEVERITY:-0}" -gt 600 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;1;31m} CRITICAL${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecAlert() { test " ${REC_SEVERITY:-0}" -gt 700 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;41m} ALERT${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecEmergency() { test "${REC_SEVERITY:-0}" -gt 800 2>/dev/null || echo "$*" | awk "{print \"$(_recRFC3339) [${REC_COLOR:+\\033[0;1;41m}EMERGENCY${REC_COLOR:+\\033[0m}] \"\$0\"\"}" 1>&2; }
RecExec() { RecInfo "$ $(_recCmd "$@")" && "$@"; }
RecRun() { _dlm="####R#E#C#D#E#L#I#M#I#T#E#R####" _all=$({ _out=$("$@") && _rtn=$? || _rtn=$? && printf "\n%s" "${_dlm:?}${_out:-}" && return ${_rtn:-0}; } 2>&1) && _rtn=$? || _rtn=$? && _dlmno=$(echo "${_all:-}" | sed -n "/${_dlm:?}/=") && _cmd=$(_recCmd "$@") && _stdout=$(echo "${_all:-}" | tail -n +"${_dlmno:-1}" | sed "s/^${_dlm:?}//") && _stderr=$(echo "${_all:-}" | head -n "${_dlmno:-1}" | grep -v "^${_dlm:?}") && RecInfo "$ ${_cmd:-}" && { [ -z "${_stdout:-}" ] || RecInfo "${_stdout:?}"; } && { [ -z "${_stderr:-}" ] || RecWarning "${_stderr:?}"; } && return ${_rtn:-0}; }
RecRun() { _dlm="####R#E#C#D#E#L#I#M#I#T#E#R####" && _all=$({ _out=$("$@") && _rtn=$? || _rtn=$? && printf "\n%s" "${_dlm:?}${_out:-}" && return "${_rtn:-0}"; } 2>&1) && _rtn=$? || _rtn=$? && _dlmno=$(echo "${_all:-}" | sed -n "/${_dlm:?}/=") && _cmd=$(_recCmd "$@") && _stdout=$(echo "${_all:-}" | tail -n +"${_dlmno:-1}" | sed "s/^${_dlm:?}//") && _stderr=$(echo "${_all:-}" | head -n "${_dlmno:-1}" | grep -v "^${_dlm:?}") && RecInfo "$ ${_cmd:-}" && { [ -z "${_stdout:-}" ] || RecInfo "${_stdout:?}"; } && { [ -z "${_stderr:-}" ] || RecWarning "${_stderr:?}"; } && return "${_rtn:-0}"; }

# versenv common
DownloadURL() {
Expand All @@ -110,16 +106,18 @@ DownloadURL() {
fi
}

GetURL() {
local url="${1:?}"
if command -v wget >/dev/null; then
wget --secure-protocol=TLSv1_2 --dns-timeout=2 --connect-timeout=2 -q -O- "${url:?}"
elif command -v curl >/dev/null; then
curl --tlsv1.2 --connect-timeout 2 -fLRSs "${url:?}"
else
RecCritical "command not found: curl or wget"
exit 127
fi
GetURLs() {
for arg in "$@"; do
local url="${arg:?}"
if command -v wget >/dev/null; then
wget --secure-protocol=TLSv1_2 --dns-timeout=2 --connect-timeout=2 -q -O- "${url:?}"
elif command -v curl >/dev/null; then
curl --tlsv1.2 --connect-timeout 2 -fLRSs "${url:?}"
else
RecCritical "command not found: curl or wget"
exit 127
fi
done
}

HeadURL() {
Expand Down
67 changes: 0 additions & 67 deletions .github/workflows/ci.yml

This file was deleted.

115 changes: 115 additions & 0 deletions .github/workflows/go-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: go-lint
# ~~~~~~~
# https://github.com/kunitsucom/ilog.go/workflows/go-lint/badge.svg
# ~~~~~~~

on:
push:
branches:
- main
paths-ignore:
- '.github/dependabot.yml'
- '.github/pull_request_template.md'
- '.github/release.yml'
- 'README.md'
pull_request:
# branches:
# - main
paths-ignore:
- '.github/dependabot.yml'
- '.github/pull_request_template.md'
- '.github/release.yml'
- 'README.md'
workflow_dispatch:
inputs: {}

# NOTE: 連続で commit & push した時に最新の commit 以外のワークフローをキャンセルする
concurrency:
group: ${{ github.workflow }}-${{ github.base_ref }}-${{ github.head_ref }}-${{ github.ref }}
cancel-in-progress: true

permissions:
id-token: write
contents: read

env:
WORKDIR: .

defaults:
run:
shell: bash

jobs:
go-lint: # NOTE: for Branch protection rule `Status checks that are required.`
runs-on: ubuntu-latest # ref. https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
steps:
- uses: actions/checkout@v3
- name: DEBUG
run: |
cat <<'DEBUG_DOC'
== DEBUG =======================================================
github.ref: ${{ github.ref }}
github.event_name: ${{ github.event_name }}
-- toJSON(github.event.inputs) ---------------------------------
${{ toJSON(github.event.inputs) }}
-- toJSON(github) ----------------------------------------------
${{ toJSON(github) }}
================================================================
DEBUG_DOC
shell: bash
- name: actions/cache for versenv
uses: actions/cache@v3
with:
path: |
~/.cache/versenv
key: versenv-${{ runner.os }}-${{ hashFiles('**/.versenv.env') }}
restore-keys: |
versenv-${{ runner.os }}-
- name: Add GITHUB_PATH, GITHUB_ENV
run: |
# Update GITHUB_PATH
cat <<GITHUB_PATH >> $GITHUB_PATH
${PWD}/${{ env.WORKDIR }}/.local/bin
${PWD}/.bin
GITHUB_PATH
# Update GITHUB_ENV
grep -Ev '^\s*$|^\s*#' .versenv.env >> $GITHUB_ENV
- name: Setup versenv
run: |
# Setup versenv
direnv allow ${{ env.WORKDIR }}
make versenv
- uses: actions/setup-go@v4 # ref. https://github.com/actions/setup-go#usage
id: setup-go
with:
cache: false
go-version-file: ${{ env.WORKDIR }}/go.mod
- name: Get Golang info
id: golang-info
run: |
echo "GOVERSION=$(go version | cut -d' ' -f3)" >> "$GITHUB_OUTPUT"
echo "GOCACHE=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
- name: actions/cache for go
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
${{ steps.golang-info.outputs.GOCACHE }}
key: ${{ runner.os }}-go-${{ steps.golang-info.outputs.GOVERSION }}-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/*.go') }}
restore-keys: |
${{ runner.os }}-go-${{ steps.golang-info.outputs.GOVERSION }}-${{ hashFiles('**/go.sum') }}-
${{ runner.os }}-go-${{ steps.golang-info.outputs.GOVERSION }}-
${{ runner.os }}-go-
- name: Run go mod tidy
if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
working-directory: ${{ env.WORKDIR }}
run: |
direnv exec . go mod tidy
git diff --exit-code go.mod go.sum
- uses: golangci/[email protected] # ref. https://github.com/golangci/golangci-lint-action#how-to-use
with:
working-directory: ${{ env.WORKDIR }}
args: --timeout=600s
version: ${{ env.GOLANGCI_LINT_VERSION }}
Loading

0 comments on commit 20cd698

Please sign in to comment.