Skip to content

Commit fbb311a

Browse files
authored
Merge pull request #5 from BerryBytes/fix/plugins
Upgraded asdf version to 18.0 upgraded asdf plugins upgraded asdf command modified script to fix few dependencies and installation issues
2 parents 50aa68e + 5fe12aa commit fbb311a

20 files changed

+1368
-684
lines changed

global/commit-msg.sh

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# #!/usr/bin/env bash
2+
# set -euo pipefail
3+
4+
# # Create commitlint config if it doesn't exist
5+
# if [ ! -f "$(git rev-parse --show-toplevel)/commitlint.config.js" ]; then
6+
# cat << 'CONFIG_EOF' > "$(git rev-parse --show-toplevel)/commitlint.config.js"
7+
# module.exports = {
8+
# extends: ['@commitlint/config-conventional'],
9+
# rules: {
10+
# 'type-enum': [2, 'always', [
11+
# 'feat', // A new feature
12+
# 'fix', // A bug fix
13+
# 'docs', // Documentation only changes
14+
# 'style', // Changes that do not affect code meaning
15+
# 'refactor', // A code change that neither fixes a bug nor adds a feature
16+
# 'perf', // A code change that improves performance
17+
# 'test', // Adding missing tests or correcting existing tests
18+
# 'build', // Build system or external dependencies
19+
# 'ci', // CI configuration changes
20+
# 'chore', // Other changes that don't modify src or test files
21+
# 'revert', // Reverts a previous commit
22+
# ]],
23+
# 'type-case': [2, 'always', 'lowerCase'],
24+
# 'type-empty': [2, 'never'],
25+
# 'scope-case': [2, 'always', 'lowerCase'],
26+
# 'subject-empty': [2, 'never'],
27+
# 'subject-full-stop': [2, 'never', '.'],
28+
# 'header-max-length': [2, 'always', 72],
29+
# },
30+
# };
31+
# CONFIG_EOF
32+
# echo "✅ Created commitlint.config.js in repository root"
33+
# fi
34+
35+
# # Ensure commitlint is available
36+
# if ! command -v commitlint >/dev/null 2>&1; then
37+
# echo "⚙️ Installing commitlint globally..."
38+
# npm install -g @commitlint/cli @commitlint/config-conventional >/dev/null 2>&1
39+
# fi
40+
41+
# # Read commit message
42+
# commit_msg_file="$1"
43+
# commit_msg=$(cat "$commit_msg_file")
44+
45+
# # Run commitlint and capture output (important!)
46+
# lint_output=$(echo "$commit_msg" | commitlint 2>&1) || lint_status=$?
47+
48+
# if [ "${lint_status:-0}" -ne 0 ]; then
49+
# RED='\033[0;31m'
50+
# YELLOW='\033[1;33m'
51+
# NC='\033[0m'
52+
53+
# echo -e "${RED}\n❌ Commit message format error detected.${NC}"
54+
# echo -e "${YELLOW}\nCommit message must follow the Conventional Commit format:\n${NC}"
55+
# echo -e "${YELLOW} type(scope): subject${NC}"
56+
# echo -e "\n${YELLOW}Types:${NC}"
57+
# echo " feat : A new feature"
58+
# echo " fix : A bug fix"
59+
# echo " docs : Documentation only changes"
60+
# echo " style : Changes that do not affect code meaning"
61+
# echo " refactor : Code change that neither fixes a bug nor adds a feature"
62+
# echo " perf : Code change that improves performance"
63+
# echo " test : Adding or correcting tests"
64+
# echo " build : Changes to the build system or external dependencies"
65+
# echo " ci : CI configuration or scripts"
66+
# echo " chore : Other changes that don't modify src or test files"
67+
# echo " revert : Reverts a previous commit"
68+
# echo -e "\n${YELLOW}Examples:${NC}"
69+
# echo " feat(auth): add password reset functionality"
70+
# echo " fix(api): handle null server response"
71+
# echo " docs(readme): update installation instructions"
72+
73+
# echo -e "\n${RED}Commitlint output:${NC}"
74+
# echo "$lint_output"
75+
76+
# echo -e "\n${RED}❗ Please fix your commit message and try again.${NC}"
77+
# exit 1
78+
# else
79+
# echo -e "\033[0;32m✅ Commit message passed Conventional Commit check.\033[0m"
80+
# fi
81+
82+
83+
#!/usr/bin/env bash
84+
set -euo pipefail
85+
86+
# Create commitlint config if it doesn't exist
87+
if [ ! -f "$(git rev-parse --show-toplevel)/commitlint.config.cjs" ]; then
88+
cat << 'CONFIG_EOF' > "$(git rev-parse --show-toplevel)/commitlint.config.cjs"
89+
module.exports = {
90+
extends: ['@commitlint/config-conventional'],
91+
rules: {
92+
'type-enum': [2, 'always', [
93+
'feat', // A new feature
94+
'fix', // A bug fix
95+
'docs', // Documentation only changes
96+
'style', // Changes that do not affect code meaning
97+
'refactor', // A code change that neither fixes a bug nor adds a feature
98+
'perf', // A code change that improves performance
99+
'test', // Adding missing tests or correcting existing tests
100+
'build', // Build system or external dependencies
101+
'ci', // CI configuration changes
102+
'chore', // Other changes that don't modify src or test files
103+
'revert', // Reverts a previous commit
104+
]],
105+
'type-case': [2, 'always', 'lowerCase'],
106+
'type-empty': [2, 'never'],
107+
'scope-case': [2, 'always', 'lowerCase'],
108+
'subject-empty': [2, 'never'],
109+
'subject-full-stop': [2, 'never', '.'],
110+
'header-max-length': [2, 'always', 72],
111+
},
112+
};
113+
CONFIG_EOF
114+
echo "✅ Created commitlint.config.cjs in repository root"
115+
fi
116+
117+
# Ensure commitlint is available
118+
if ! command -v commitlint >/dev/null 2>&1; then
119+
echo "⚙️ Installing commitlint globally..."
120+
npm install -g @commitlint/cli @commitlint/config-conventional >/dev/null 2>&1
121+
fi
122+
123+
# Read commit message
124+
commit_msg_file="$1"
125+
commit_msg=$(cat "$commit_msg_file")
126+
127+
# Run commitlint and capture output (important!)
128+
lint_output=$(echo "$commit_msg" | commitlint 2>&1) || lint_status=$?
129+
130+
if [ "${lint_status:-0}" -ne 0 ]; then
131+
RED='\033[0;31m'
132+
YELLOW='\033[1;33m'
133+
NC='\033[0m'
134+
135+
echo -e "${RED}\n❌ Commit message format error detected.${NC}"
136+
echo -e "${YELLOW}\nCommit message must follow the Conventional Commit format:\n${NC}"
137+
echo -e "${YELLOW} type(scope): subject${NC}"
138+
echo -e "\n${YELLOW}Types:${NC}"
139+
echo " feat : A new feature"
140+
echo " fix : A bug fix"
141+
echo " docs : Documentation only changes"
142+
echo " style : Changes that do not affect code meaning"
143+
echo " refactor : Code change that neither fixes a bug nor adds a feature"
144+
echo " perf : Code change that improves performance"
145+
echo " test : Adding or correcting tests"
146+
echo " build : Changes to the build system or external dependencies"
147+
echo " ci : CI configuration or scripts"
148+
echo " chore : Other changes that don't modify src or test files"
149+
echo " revert : Reverts a previous commit"
150+
echo -e "\n${YELLOW}Examples:${NC}"
151+
echo " feat(auth): add password reset functionality"
152+
echo " fix(api): handle null server response"
153+
echo " docs(readme): update installation instructions"
154+
155+
echo -e "\n${RED}Commitlint output:${NC}"
156+
echo "$lint_output"
157+
158+
echo -e "\n${RED}❗ Please fix your commit message and try again.${NC}"
159+
exit 1
160+
else
161+
echo -e "\033[0;32m✅ Commit message passed Conventional Commit check.\033[0m"
162+
fi

global/install_dependencies.sh

Lines changed: 71 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,55 +16,89 @@ detect_shell_and_configure_asdf() {
1616

1717
echo "Detected shell: $shell_name. Configuring asdf for $shell_config."
1818

19-
# Ensure asdf directory is clean
19+
# Ensure wget, curl, and tar are installed
20+
for cmd in wget curl tar; do
21+
if ! command -v "$cmd" &>/dev/null; then
22+
echo "$cmd not found. Installing $cmd..."
23+
if command -v apt-get &>/dev/null; then
24+
sudo apt-get update -y && sudo apt-get install -y "$cmd"
25+
elif command -v yum &>/dev/null; then
26+
sudo yum install -y "$cmd"
27+
elif command -v dnf &>/dev/null; then
28+
sudo dnf install -y "$cmd"
29+
elif command -v apk &>/dev/null; then
30+
sudo apk add --no-cache "$cmd"
31+
else
32+
echo "No supported package manager found. Please install $cmd manually."
33+
return 1
34+
fi
35+
fi
36+
done
37+
38+
39+
# Ensure $HOME/bin exists
40+
mkdir -p "$HOME/bin"
41+
42+
# Remove any old installation
2043
if [ -d "$HOME/.asdf" ]; then
21-
echo "Removing existing .asdf installation..."
22-
rm -rf "$HOME/.asdf" || {
23-
echo "Failed to remove existing .asdf directory."
24-
return 1
25-
}
44+
echo "Removing existing .asdf directory..."
45+
rm -rf "$HOME/.asdf"
2646
fi
2747

28-
# Install asdf if not already installed
29-
if ! command -v asdf &>/dev/null; then
30-
echo "Installing asdf..."
31-
git clone https://github.com/asdf-vm/asdf.git "$HOME/.asdf" --branch master || {
32-
echo "Failed to clone asdf repository."
33-
return 1
34-
}
35-
fi
48+
# Detect OS and Architecture
49+
local os arch
50+
os=$(uname -s | tr '[:upper:]' '[:lower:]')
51+
arch=$(uname -m)
3652

37-
# Configure asdf in the shell's config file
38-
if ! grep -q 'asdf.sh' "$shell_config"; then
39-
cat <<EOF >>"$shell_config"
53+
# Normalize architecture name
54+
case "$arch" in
55+
x86_64) arch="amd64" ;;
56+
aarch64) arch="arm64" ;;
57+
esac
4058

41-
# Load asdf
42-
. "$HOME/.asdf/asdf.sh"
43-
EOF
44-
if [[ "$shell_name" == "zsh" ]]; then
45-
cat <<EOF >>"$shell_config"
59+
local version="v0.18.0"
60+
local tarball="asdf-${version}-${os}-${arch}.tar.gz"
61+
local download_url="https://github.com/asdf-vm/asdf/releases/download/${version}/${tarball}"
4662

47-
# Append completions to fpath
48-
fpath=(${HOME}/.asdf/completions $fpath)
63+
echo "Downloading ASDF ${version} for ${os}-${arch}..."
64+
wget -q "$download_url" -O "/tmp/${tarball}" || {
65+
echo "Failed to download ${download_url}"
66+
return 1
67+
}
4968

50-
# Initialize completions with ZSH compinit
51-
autoload -Uz compinit && compinit
52-
EOF
53-
elif [[ "$shell_name" == "bash" ]]; then
54-
echo '. "$HOME/.asdf/completions/asdf.bash"' >>"$shell_config"
55-
fi
56-
echo "asdf initialization added to $shell_config."
69+
echo "Extracting ${tarball} to $HOME/bin..."
70+
tar -xzf "/tmp/${tarball}" -C "$HOME/bin" || {
71+
echo "Failed to extract asdf binary."
72+
return 1
73+
}
74+
75+
# Ensure binary is executable
76+
chmod +x "$HOME/bin/asdf" 2>/dev/null || true
77+
78+
# Configure PATH and environment variables in shell config
79+
if ! grep -q '## ADF' "$shell_config"; then
80+
{
81+
echo ""
82+
echo "## ADF"
83+
echo 'export PATH="$HOME/bin:$PATH"'
84+
echo 'export ASDF_DATA_DIR="$HOME/.asdf"'
85+
echo 'export PATH="$ASDF_DATA_DIR/shims:$PATH"'
86+
} >> "$shell_config"
5787
fi
5888

59-
# Source the shell configuration to load asdf
89+
echo "asdf configuration added to $shell_config."
6090
source "$shell_config"
6191

62-
# Verify asdf installation
92+
# Verify installation
6393
if ! command -v asdf &>/dev/null; then
64-
echo "asdf installation or sourcing failed. Please check $shell_config."
94+
echo "asdf installation or PATH setup failed. Please check $shell_config."
6595
return 1
6696
fi
67-
echo "asdf installed and configured successfully."
97+
98+
echo "asdf installed successfully."
99+
asdf --version
100+
asdf reshim
101+
echo "asdf configured and ready to use."
68102
}
69103

70104
# Function to install an asdf tool and its version
@@ -85,7 +119,7 @@ install_tool_with_asdf() {
85119
tflint) plugin_repo="https://github.com/skyzyx/asdf-tflint" ;;
86120
tfsec) plugin_repo="https://github.com/woneill/asdf-tfsec.git" ;;
87121
terraform-docs) plugin_repo="https://github.com/looztra/asdf-terraform-docs" ;;
88-
pre-commit) plugin_repo="git@github.com:jonathanmorley/asdf-pre-commit.git" ;;
122+
pre-commit) plugin_repo="https://github.com/jonathanmorley/asdf-pre-commit.git" ;;
89123
*)
90124
echo "No plugin URL specified for $tool."
91125
return 1
@@ -105,7 +139,7 @@ install_tool_with_asdf() {
105139
return 1
106140
}
107141
fi
108-
asdf global "$tool" "$version"
142+
asdf set "$tool" "$version"
109143
echo "$tool version $version installed and set globally."
110144
}
111145

global/main.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ mkdir -p "$TEMPLATE_DIR"
2323

2424
# cp global/commit-msg.sh "$TEMPLATE_DIR/commit-msg"
2525
cp global/pre-commit.sh "$TEMPLATE_DIR/pre-commit"
26+
cp global/commit-msg.sh "$TEMPLATE_DIR/commit-msg"
2627

27-
chmod +x "$TEMPLATE_DIR/pre-commit" #"$TEMPLATE_DIR/commit-msg"
28+
chmod +x "$TEMPLATE_DIR/pre-commit" "$TEMPLATE_DIR/commit-msg"
2829

2930
## automatically enabling pre-commit on repositories
3031
git config --global init.templateDir "$HOME/.git-templates"

0 commit comments

Comments
 (0)