Skip to content

Commit

Permalink
fix gha
Browse files Browse the repository at this point in the history
  • Loading branch information
gjpin committed Dec 27, 2024
1 parent 4cb8ff9 commit 26944f5
Showing 1 changed file with 49 additions and 24 deletions.
73 changes: 49 additions & 24 deletions .github/workflows/check-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,58 @@ jobs:
- name: Extract and validate packages
run: |
failed_packages=()
validate_package() {
local package=$1
# Skip if empty, starts with #, or starts with --
if [ -z "$package" ] || [[ "$package" == \#* ]] || [[ "$package" == --* ]]; then
return 0
fi
if ! pacman -Ss "^${package}$" > /dev/null 2>&1; then
failed_packages+=("$package")
echo "❌ Package not found: $package"
else
echo "✅ Package exists: $package"
fi
}
# Find all .sh files in root directory
for file in *.sh; do
if [ -f "$file" ]; then
echo "Checking packages in $file..."
# Extract package names from pacman commands
# Matches packages after "pacman -S --noconfirm \" until the next command
packages=$(awk '/pacman -S --noconfirm/{p=1;next} /^[a-z]/{p=0} p{if($1!="\\") print $1}' "$file" |
grep -v '^$' |
tr -d '\\')
# Also catch single-line package installations
single_line_packages=$(grep -E "^pacman -S --noconfirm [^\\]" "$file" |
sed 's/pacman -S --noconfirm //')
all_packages="$packages $single_line_packages"
echo "📄 Checking packages in $file..."
# Check each package
echo "$all_packages" | tr ' ' '\n' | while read -r package; do
if [ ! -z "$package" ]; then
if pacman -Ss "^${package}$" > /dev/null 2>&1; then
echo "✅ Package exists: $package"
else
echo "❌ Package not found: $package"
exit 1
fi
# Extract multi-line package installations
while IFS= read -r line; do
if [[ "$line" =~ ^pacman\ -S\ --noconfirm ]]; then
# Start capturing packages
in_package_list=1
# Extract packages from the first line, skipping pacman command and known arguments
packages=$(echo "$line" | sed 's/pacman -S --noconfirm//g' | sed 's/--ask [0-9]//g' | tr '\\' ' ')
for pkg in $packages; do
validate_package "$pkg"
done
elif [ "$in_package_list" = "1" ] && [[ "$line" =~ ^[[:space:]]*[^[:space:]].*\\ *$ ]]; then
# Continue capturing packages from continuation lines
packages=$(echo "$line" | sed 's/\\//g')
for pkg in $packages; do
validate_package "$pkg"
done
else
in_package_list=0
fi
done
done < "$file"
fi
done
done
# Print summary of failed packages
if [ ${#failed_packages[@]} -eq 0 ]; then
echo "✅ All packages validated successfully!"
exit 0
else
echo "❌ The following packages were not found:"
printf '%s\n' "${failed_packages[@]}"
echo "Total failed packages: ${#failed_packages[@]}"
exit 1
fi

0 comments on commit 26944f5

Please sign in to comment.