-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(dev/tools): move dev dependencies management to mise
Signed-off-by: Bart Smykla <[email protected]>
- Loading branch information
1 parent
6152636
commit cde248b
Showing
25 changed files
with
1,563 additions
and
25 deletions.
There are no files selected for viewing
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,54 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit # Exit immediately if any command has a non-zero exit status (error) | ||
set -o errtrace # Ensure that traps are inherited by functions, command substitutions, and subshells | ||
set -o nounset # Treat any unset variables as an error and exit immediately | ||
set -o pipefail # If any command in a pipeline fails, the entire pipeline fails | ||
|
||
export __GOPATH_MOD="${GOPATH_MOD:-$__GOPATH/pkg/mod}" | ||
export __GOPATH_MOD_GITHUB="$__GOPATH_MOD/github.com" | ||
|
||
# Project directory setup | ||
export __KUMA_DIR="${KUMA_DIR:-.}" | ||
|
||
export __TASKS_SCRIPTS_PATH="${TASKS_SCRIPTS_PATH:-$(realpath "$__KUMA_DIR")/.mise/scripts}" | ||
|
||
# Kubernetes version range for CI | ||
export __K8S_MIN_VERSION="v1.25.16-k3s4" | ||
export __K8S_MAX_VERSION="v1.31.1-k3s1" | ||
|
||
# GitHub Action prefix (can be set externally) | ||
export __ACTION_PREFIX="" | ||
|
||
# Derive the project name from the current directory if not explicitly set | ||
export __PROJECT_NAME="${PROJECT_NAME:-$(basename "${PWD:-kuma}")}" | ||
|
||
export __BUILD_DIR="${BUILD_DIR:-$(realpath "$__KUMA_DIR")/build}" | ||
export __TOOLS_DIR="${TOOLS_DIR:-$__BUILD_DIR/tools}" | ||
export __TOOLS_DIR_BIN="${__TOOLS_DIR}/bin" | ||
export __TOOLS_DIR_PROTOS="${__TOOLS_DIR}/protos" | ||
|
||
# Paths for tools and imports | ||
export __GENERATE_ENVOY_IMPORTS="./pkg/xds/envoy/imports.go" | ||
export __GENERATE_TOOLS_DIR="${__TOOLS_DIR_BIN}/${__GOOS}-${__GOARCH}" | ||
export __GENERATE_TOOLS_POLICY_GEN_SOURCE="${__KUMA_DIR}/tools/policy-gen" | ||
export __GENERATE_TOOLS_POLICY_GEN_BIN="${__GENERATE_TOOLS_DIR}/policy-gen" | ||
export __GENERATE_TOOLS_RESOURCE_GEN_SOURCE="${__KUMA_DIR}/tools/resource-gen" | ||
export __GENERATE_TOOLS_RESOURCE_GEN_BIN="${__GENERATE_TOOLS_DIR}/resource-gen" | ||
|
||
# Protobuf directories and Go module | ||
export __GENERATE_PROTO_DIRS="${GENERATE_PROTO_DIRS:-./api ./pkg/config ./pkg/plugins ./test/server/grpc/api}" | ||
export __GENERATE_GO_MODULE="${GENERATE_GO_MODULE:-github.com/kumahq/kuma}" | ||
|
||
# Helm file paths and settings | ||
export __GENERATE_HELM_CHARTS_DIR="${HELM_CHARTS_DIR:-deployments/charts}" | ||
export __GENERATE_HELM_VALUES_FILE="${HELM_VALUES_FILE:-deployments/charts/kuma/values.yaml}" | ||
export __GENERATE_HELM_CRDS_DIR="${HELM_CRDS_DIR:-deployments/charts/kuma/crds}" | ||
export __GENERATE_HELM_VALUES_FILE_POLICY_PATH="${HELM_VALUES_FILE_POLICY_PATH:-.plugins.policies}" | ||
|
||
# Generation prerequisites and additional dependencies | ||
export __GENERATE_OAS_PREREQUISITES="${GENERATE_OAS_PREREQUISITES:-}" | ||
export __GENERATE_EXTRA_DEPS_TARGETS="${EXTRA_DEPS_TARGETS:-generate::envoy-imports}" | ||
|
||
export __GENERATE_POLICIES_DIR="${POLICIES_DIR:-pkg/plugins/policies}" | ||
export __GENERATE_RESOURCES_DIR="${RESOURCES_DIR:-pkg/core/resources/apis}" |
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,42 @@ | ||
#!/usr/bin/env bash | ||
|
||
common::export_build_info() { | ||
# Declare and populate an associative array | ||
declare -gA BUILD_INFO | ||
|
||
# Extract build information from the version script | ||
read -r BUILD_INFO["version"] \ | ||
BUILD_INFO["git_tag"] \ | ||
BUILD_INFO["git_commit"] \ | ||
BUILD_INFO["build_date"] \ | ||
BUILD_INFO["release"] <<< "$(tools/releases/version.sh)" | ||
|
||
# Export the associative array for use in the environment | ||
export BUILD_INFO | ||
} | ||
|
||
common::get_resources() { | ||
local resources_dir="$1" | ||
local resources | ||
local -a resources_array | ||
|
||
# Find directories and exclude specific names | ||
# -maxdepth 1: Search only one level deep | ||
# -mindepth 1: Skip the base directory itself | ||
# -type d: Include only directories | ||
# ! -name: Exclude directories named "core", "mesh", and "system" | ||
# -exec basename {} \;: Extract only the base names of the directories | ||
resources=$(find "$resources_dir" \ | ||
-maxdepth 1 \ | ||
-mindepth 1 \ | ||
-type d \ | ||
! -name "core" \ | ||
! -name "mesh" \ | ||
! -name "system" \ | ||
-exec basename {} \;) | ||
|
||
# Sort and store in an array | ||
mapfile -t resources_array < <(echo "$resources" | sort) | ||
|
||
echo "${resources_array[@]}" | ||
} |
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,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
should_log() { | ||
case "${LOG_QUIET:-}" in | ||
true|1|on|enabled) return 1 ;; | ||
esac | ||
return 0 | ||
} | ||
|
||
is_verbose() { | ||
case "${LOG_VERBOSE:-}" in | ||
true|1|on|enabled) return 0 ;; | ||
esac | ||
return 1 | ||
} | ||
|
||
log::info() { | ||
should_log || return 0 | ||
echo "[INFO]$(is_verbose && echo ' ') $*" >&2 | ||
} | ||
|
||
log::verbose() { | ||
should_log || return 0 | ||
is_verbose || return 0 | ||
echo "[VERBOSE] $*" >&2 | ||
} |
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,102 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Function to replace $HOME with ~ in a given string | ||
shorten_home() { | ||
echo "${1//$HOME/\~}" | ||
} | ||
|
||
log() { | ||
# Use the provided prefix or default to "___task_" if no prefix is given | ||
local prefix="${1:-___task_}" | ||
|
||
# Declare an associative array to store the table rows | ||
declare -A table_rows | ||
local var_name | ||
|
||
while read -r var_name; do | ||
# Skip variables that don't match the expected pattern (with optional parameters prefix) | ||
if ! [[ "$var_name" =~ $prefix([ar]{1,2}_)?([a-zA-Z0-9_]+) ]]; then | ||
continue | ||
fi | ||
|
||
# Extract the variable name without the prefix and convert it to lowercase | ||
local name="${BASH_REMATCH[-1],,}" | ||
|
||
# Dynamically reference the variable using `declare -n` | ||
declare -n full_var="$var_name" | ||
|
||
# Check if the variable is not an array (using grep to check for 'a' flag in `declare`) | ||
if ! declare -p "$var_name" 2>/dev/null | grep -qE 'declare -.*a.* '; then | ||
table_rows["$name"]="$(shorten_home "$full_var")" | ||
continue | ||
fi | ||
|
||
# For array-like variables, iterate through each element | ||
table_rows["${name}[]"]=$( | ||
for i in "${!full_var[@]}"; do | ||
echo "$(gum style --foreground 240 "$i:") $(shorten_home "${full_var[i]}")" | ||
done | ||
) | ||
done < <(declare -p | cut -d ' ' -f 3 | grep "^$prefix" | cut -d '=' -f 1) | ||
|
||
{ | ||
echo "Variable,Value" | ||
for key in $(printf "%s\n" "${!table_rows[@]}" | sort); do | ||
echo "$key,\"${table_rows[$key]}\"" | ||
done | ||
} | gum table --print | ||
} | ||
|
||
variables::verify() { | ||
local error_messages=() | ||
local var_name | ||
local prefix="${1:-___task_}" # Use the argument as prefix or default to ___task_ | ||
|
||
for var_name in $(declare -p | cut -d ' ' -f 3 | grep "^$prefix"); do | ||
var_name="${var_name%%=*}" # Remove everything after '=' including '=' | ||
|
||
# Parameters explanation: | ||
# r: Marks a variable as required. The function checks if it is set | ||
# a: Indicates the variable is specified via arguments and not flag | ||
# Variables must use the prefix and follow the format: <prefix><parameters>_<name> | ||
if ! [[ "$var_name" =~ ${prefix}([ar]{1,2})_([a-zA-Z0-9_]+) ]]; then | ||
continue | ||
fi | ||
|
||
local parameters="${BASH_REMATCH[1]}" | ||
local name="${BASH_REMATCH[2]}" | ||
|
||
# Skip the loop if variable is not required | ||
if [[ "$parameters" != *r* ]]; then | ||
continue | ||
fi | ||
|
||
if declare -p "$var_name" 2>/dev/null | grep -qE 'declare \-.*a.*\ '; then | ||
# Check if the array is non-empty, prevent unbound variable error with ':-' | ||
[[ "${!var_name[*]:-}" ]] && continue | ||
elif [[ -n ${!var_name} ]]; then | ||
# Check if the string variable is non-empty | ||
continue | ||
fi | ||
|
||
local flag="--${name//_/-}" # Replace underscores with dashes | ||
local env="${name^^}" # Convert to uppercase | ||
|
||
if [[ "$parameters" != *a* ]]; then | ||
error_messages+=("Error: $name not specified; provide via $flag flag or $env env var") | ||
else | ||
error_messages+=("Error: $name missing; provide as argument(s) or $env env var") | ||
fi | ||
done | ||
|
||
# If there are errors, log all of them and exit | ||
if [[ ${#error_messages[@]} -gt 0 ]]; then | ||
printf "%s\n" "${error_messages[@]}" >&2 | ||
exit 1 | ||
fi | ||
|
||
case "${VERBOSE_LOG:-}" in | ||
true|1|on|enabled) | ||
log "$prefix" ;; | ||
esac | ||
} |
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,3 @@ | ||
["ginkgo:unfocus"] | ||
description = "Unfocus any tests" | ||
run = "ginkgo unfocus" |
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,17 @@ | ||
["clean:generate:docs:openapi"] | ||
usage = ''' | ||
flag "--tmp-dir" { | ||
arg "<dir>" | ||
default "build/oapitmp" | ||
help "Temporary directory for OpenAPI generation" | ||
} | ||
flag "--openapi-output" { | ||
arg "<file>" | ||
default "docs/generated/openapi.yaml" | ||
help "Path to the generated OpenAPI file" | ||
} | ||
''' | ||
|
||
run = """ | ||
rm -rf "{{ flag(name='tmp-dir') }}" "{{ flag(name='openapi-output') }}" | ||
""" |
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,45 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit # Exit immediately if any command has a non-zero exit status (error) | ||
set -o errtrace # Ensure that traps are inherited by functions, command substitutions, and subshells | ||
set -o nounset # Treat any unset variables as an error and exit immediately | ||
set -o pipefail # If any command in a pipeline fails, the entire pipeline fails | ||
|
||
source "$__TASKS_SCRIPTS_PATH/variables.sh" | ||
|
||
#MISE description="Debug" | ||
#USAGE flag "--type" { | ||
#USAGE arg "<type>" | ||
#USAGE choices "all" "mise:diff" "mise:session" | ||
#USAGE default "all" | ||
#USAGE help "Type of what to debug" | ||
#USAGE } | ||
|
||
___task_debug_type="${usage_type:-all}" | ||
|
||
variables::verify | ||
|
||
# Function to process input using rq and jq | ||
process_mise_variables() { | ||
local var_name="$1" | ||
echo "Debugging variable: $var_name" | ||
rq --input-message-pack --output-json < <( | ||
zcat --quiet < <( | ||
printf '\x1f\x8b\x08\x00\x00\x00\x00\x00' | ||
base64 -d <<< "${!var_name}" | ||
) | ||
) | jq --color-output | ||
} | ||
|
||
case "$___task_debug_type" in | ||
all) | ||
process_mise_variables "__MISE_DIFF" | ||
process_mise_variables "__MISE_SESSION" | ||
;; | ||
mise:diff) | ||
process_mise_variables "__MISE_DIFF" | ||
;; | ||
mise:session) | ||
process_mise_variables "__MISE_SESSION" | ||
;; | ||
esac |
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,27 @@ | ||
["debug:a"] | ||
run = """ | ||
jq <<< cat <<'EOF' | ||
{{ __tera_context }} | ||
EOF | ||
""" | ||
|
||
["debug:clean"] | ||
run = """ | ||
cat <<'EOF' | sed -e "s|$PWD|/project|g" -e "s|$HOME||g" | jq '.env.PATH = "..."' | ||
{{ __tera_context }} | ||
EOF | ||
""" | ||
|
||
["debug:env"] | ||
run = """ | ||
jq <<< cat <<'EOF' | ||
{{ env | json_encode() }} | ||
EOF | ||
""" | ||
|
||
["debug:env:clean"] | ||
run = """ | ||
cat <<'EOF' | sed -e "s|$HOME||g" | jq '.PATH = "..."' | ||
{{ env | json_encode() }} | ||
EOF | ||
""" |
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,45 @@ | ||
["fmt:tidy"] | ||
description = "Run go mod tidy in directories containing go.mod files" | ||
|
||
run = "find . -name go.mod -execdir go mod tidy \\;" | ||
|
||
["fmt:proto"] | ||
description = "Format .proto files using clang-format" | ||
|
||
run = "find . -name *.proto -exec clang-format -i {} +" | ||
|
||
["fmt:ci:k8s"] | ||
description = "Sync Kubernetes version range in CI workflows with environment variables" | ||
|
||
run = """ | ||
yq -i \ | ||
'.env.K8S_MIN_VERSION = "{{ env.__K8S_MIN_VERSION }}" | \ | ||
.env.K8S_MAX_VERSION = "{{ env.__K8S_MAX_VERSION }}"' \ | ||
.github/workflows/{{ env.__ACTION_PREFIX }}_test.yaml | ||
""" | ||
|
||
["fmt:ci:golangci-lint"] | ||
description = "Sync golangci-lint version in workflows with the version installed by mise" | ||
|
||
run = """ | ||
{% set version = exec(command='mise tool --active golangci-lint') %} | ||
grep -rl "golangci/golangci-lint-action" .github/workflows \ | ||
--include "*.yaml" \ | ||
--include "*.yml" \ | ||
| xargs -n 1 yq -i '(.jobs.* \ | ||
| select(. | has("steps")) \ | ||
| .steps[] \ | ||
| select(.uses == "golangci/golangci-lint-action*") \ | ||
| .with.version) |= "v{{ version }}"' | ||
""" | ||
|
||
["fmt:ci"] | ||
description = "Run all CI-related formatting tasks" | ||
|
||
depends = ["fmt:ci:**:*"] | ||
|
||
["fmt"] | ||
description = "Run all formatting tasks" | ||
|
||
depends = ["fmt:*"] |
Oops, something went wrong.