Skip to content

Instantly share code, notes, and snippets.

@bobby285271
Last active June 29, 2024 13:34
Show Gist options
  • Save bobby285271/d23fb0b2b1fdf5317a17dbf88af792a3 to your computer and use it in GitHub Desktop.
Save bobby285271/d23fb0b2b1fdf5317a17dbf88af792a3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# motivation
# during release cycle mint sometimes can release 5-20 updates in a day,
# and most of them are "just translations". fixup these commits.
nix_eval_wip() {
# $1: expression
# ret: result
ret_nix_eval_wip=$(NIX_PATH=nixpkgs=. \
nix-instantiate --expr "with import <nixpkgs> { }; ${1}" --eval | \
sed 's/^"//' | sed 's/"$//')
}
nix_eval_checkout() {
# $1: expression
# $2: checkout
# ret: result
ret_nix_eval_checkout=$(nix eval \
"git+file://$(pwd)?ref=${2}#${1}" --raw)
}
is_running_in_nixpkgs() {
# ret: 0 for yes, else no
nix_eval_wip "cinnamon.cinnamon-common.meta.homepage"
echo "${ret_nix_eval_wip}" | grep "https://github.com/linuxmint/cinnamon"
ret_is_running_in_nixpkgs=${?}
}
is_worktree_clean() {
# ret: 0 for yes, 1 for no
if [ -z "$(git status --porcelain)" ]; then
echo "Worktree clean"
ret_is_worktree_clean=0
else
git status
echo "The git repo has uncommitted changes, please confirm"
read
ret_is_worktree_clean=1
fi
}
git_reset() {
# $1: commit reset to, no --hard
echo "You are currently on:"
git rev-parse HEAD
git reset $1
}
get_cinnamon_pkgs_attr() {
local url="https://raw.githubusercontent.com/bobby285271/what-changed/master/data/003-cinnamon.json"
echo "Fetch cinnamon info: $url"
# This works f**king well since I maintain this
ret_get_cinnamon_pkgs_attr=$(curl $url | \
grep '"attr_path": "' | sed 's/ //g' | sed 's/"attr_path":"//g' | sed 's/"$//g')
}
echo_yellow() {
# $1: text to echo
echo -e "\033[0;33m${1}\033[0m"
}
commit_pkgs_change() {
# $1: pkgs attr
# $2: base commit
echo_yellow "Processing $1"
nix_eval_checkout "${1}.version" "$2"
local old_version=$ret_nix_eval_checkout
nix_eval_wip "${1}.version"
local new_version=$ret_nix_eval_wip
nix_eval_checkout "${1}.src.rev" "$2"
local old_rev=$ret_nix_eval_checkout
nix_eval_wip "${1}.src.rev"
local new_rev=$ret_nix_eval_wip
if [ "$new_rev" == "$old_rev" ]; then
return
fi
nix_eval_wip "${1}.src.meta.homepage"
local diffurl="$ret_nix_eval_wip/compare/${old_rev}...${new_rev}"
nix_eval_wip "${1}.meta.position"
local dir_to_add=$(dirname $(echo $ret_nix_eval_wip | cut -d : -f 1))
echo_yellow "-> Dir to add: $dir_to_add"
git add $dir_to_add
git commit -m "${1}: ${old_version} -> ${new_version}" -m "${diffurl}"
}
main() {
if [ "$#" != 1 ]; then
echo "Expect exactly one arg for base commit" && exit 1
fi
is_running_in_nixpkgs
if [ "$ret_is_running_in_nixpkgs" != 0 ]; then
echo "You must run in nixpkgs root" && exit 1
fi
is_worktree_clean
git_reset "$1"
get_cinnamon_pkgs_attr
for attr in $(echo $ret_get_cinnamon_pkgs_attr); do
commit_pkgs_change "$attr" "$1"
done
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment