Skip to content

Commit

Permalink
Packages version checker (#82) [skip ci]
Browse files Browse the repository at this point in the history
* feat: packages version checker

* fix: check aquamarine package
  • Loading branch information
hesam-init authored Oct 11, 2024
1 parent c3776b5 commit b20dcbd
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions version-checker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

template_dir="srcpkgs"

log() {
local RED='\033[0;31m'
local GREEN='\033[0;32m'
local YELLOW='\033[0;33m'
local BLUE='\033[0;34m'
local NC='\033[0m'

case "$1" in
success)
echo -e "${GREEN}$2${NC}"
;;
info)
echo -e "${BLUE}$2${NC}"
;;
warning)
echo -e "${YELLOW}$2${NC}"
;;
error)
echo -e "${RED}$2${NC}"
;;
*)
echo "$2"
;;
esac
}

fetch_version() {
repo=$1
# latest_tag=$(curl -s "https://api.github.com/repos/hyprwm/$repo/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")')
latest_tag=$(curl -s "https://github.com/hyprwm/$repo/releases" | grep -Po 'href="[^"]*/releases/tag/\K[^"]+' | head -n 1)

echo $latest_tag
}

main() {
command -v curl >/dev/null || {
log error "Curl not found, please install. Exiting..." >&2

exit 1
}

for package_dir in "$template_dir"/aquamarine/ "$template_dir"/hypr*/ "$template_dir"/xdg-desktop-portal-hyprland/; do
pkgname=$(basename "$package_dir")

if [[ "$pkgname" == "hyprland-devel" ]]; then
continue
fi

template_file="${package_dir}template"

if [[ ! -f "$template_file" ]]; then
echo "Template file not found for $pkgname"

continue
fi

current_version="v$(grep -Po '^version=\K[0-9.]+(?=$)' "$template_file")"

latest_version=$(fetch_version "$pkgname")

echo "$pkgname ===> $current_version"

if [[ -z "$latest_version" ]]; then
log error "$pkgname ===> Failed to fetch the latest version from GitHub\n"

continue
elif [[ "$current_version" == "$latest_version" ]]; then
log success "${GREEN}$pkgname is up-to-date (Version: $current_version)\n"
else
log info "$pkgname: $current_version, but latest version is $latest_version\n"
fi
done
}

main

0 comments on commit b20dcbd

Please sign in to comment.