2023-07-29 12:19:18 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2024-02-18 18:07:38 +01:00
|
|
|
xgit() {
|
2024-03-17 15:42:14 +01:00
|
|
|
git -c "user.name=Flake Update Bot" -c "user.email=flake-update-bot@clerie.de" -c "core.pager=cat" "$@"
|
2024-02-18 18:07:38 +01:00
|
|
|
}
|
|
|
|
|
2024-03-17 16:59:11 +01:00
|
|
|
xgit_merge_theirs() {
|
|
|
|
# base branch is the one currently checked out
|
|
|
|
|
|
|
|
# this is the branch we want to merge into the base branch
|
|
|
|
OTHER_BRANCH="$1"
|
|
|
|
|
|
|
|
# merge commit message
|
|
|
|
COMMIT_MESSAGE="$2"
|
|
|
|
|
|
|
|
# this branch gets used while merging
|
|
|
|
TEMP_BRANCH="tempbranch"
|
|
|
|
|
|
|
|
# create a merge commit between base branch and other branch, so it shows up correctly in git log
|
|
|
|
# we use `ours` so we make sure there are no merge conflicts
|
2024-07-14 01:08:55 +02:00
|
|
|
xgit merge -s ours "${OTHER_BRANCH}" -m "${COMMIT_MESSAGE}"
|
2024-03-17 16:59:11 +01:00
|
|
|
|
|
|
|
# save our newly created merge commit in a seperate branch
|
2024-07-14 01:08:55 +02:00
|
|
|
xgit branch "${TEMP_BRANCH}"
|
2024-03-17 16:59:11 +01:00
|
|
|
|
|
|
|
# export contents of other branch to current working directory
|
|
|
|
# this will change the last commit of our base branch too
|
2024-07-14 01:08:55 +02:00
|
|
|
xgit reset --hard "${OTHER_BRANCH}"
|
2024-03-17 16:59:11 +01:00
|
|
|
|
|
|
|
# return to our merge commit from the base branch
|
|
|
|
# but without touching the current working directory
|
2024-07-14 01:08:55 +02:00
|
|
|
xgit reset --soft "${TEMP_BRANCH}"
|
2024-03-17 16:59:11 +01:00
|
|
|
|
|
|
|
# Add the changes to our merge commit
|
2024-07-14 01:08:55 +02:00
|
|
|
xgit commit --amend --no-edit
|
2024-03-17 16:59:11 +01:00
|
|
|
|
|
|
|
# we are now on our base branch again
|
|
|
|
# so we can delete the temp branch
|
2024-07-14 01:08:55 +02:00
|
|
|
xgit branch -D "${TEMP_BRANCH}"
|
2024-03-17 16:59:11 +01:00
|
|
|
}
|
|
|
|
|
2024-02-18 18:07:38 +01:00
|
|
|
NOW="$(date --utc +%Y-%m-%d-%H-%M)"
|
|
|
|
|
|
|
|
xgit status || xgit clone gitea@git.clerie.de:clerie/nixfiles.git .
|
2023-07-29 12:19:18 +02:00
|
|
|
|
2023-09-01 16:38:34 +02:00
|
|
|
echo "[!] Download changes"
|
2024-02-18 18:07:38 +01:00
|
|
|
xgit fetch --all
|
|
|
|
|
|
|
|
echo "[!] Chechout remote master"
|
|
|
|
xgit checkout origin/master
|
|
|
|
|
2024-02-18 20:07:23 +01:00
|
|
|
UPDATE_BRANCH="updated-inputs-${NOW}"
|
2024-02-18 18:07:38 +01:00
|
|
|
echo "[!] Create branch ${UPDATE_BRANCH}"
|
|
|
|
xgit checkout -b "${UPDATE_BRANCH}"
|
|
|
|
|
|
|
|
echo "[!] Update nixpkgs"
|
|
|
|
nix flake lock --update-input nixpkgs
|
|
|
|
|
2023-09-01 16:38:34 +02:00
|
|
|
echo "[!] Commit changes"
|
2024-02-18 18:49:29 +01:00
|
|
|
xgit add flake.lock
|
2024-03-17 15:42:14 +01:00
|
|
|
|
2024-02-18 18:07:38 +01:00
|
|
|
xgit commit -m "Update nixpkgs ${NOW}" || true
|
|
|
|
|
2024-03-17 15:42:14 +01:00
|
|
|
xgit diff --name-status origin/updated-inputs "${UPDATE_BRANCH}"
|
|
|
|
|
|
|
|
echo "[!] biep"
|
|
|
|
if xgit diff --quiet origin/updated-inputs "${UPDATE_BRANCH}"
|
|
|
|
then
|
|
|
|
echo "[!] Nothing changed, removing branch"
|
2024-03-17 17:02:32 +01:00
|
|
|
xgit checkout updated-inputs
|
2024-03-17 15:42:14 +01:00
|
|
|
xgit branch -D "${UPDATE_BRANCH}"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2024-02-18 18:49:29 +01:00
|
|
|
echo "[!] Publish ${UPDATE_BRANCH}"
|
|
|
|
xgit push --set-upstream origin "${UPDATE_BRANCH}"
|
|
|
|
|
2024-02-18 18:07:38 +01:00
|
|
|
echo "[!] Merge ${UPDATE_BRANCH} into updated-inputs"
|
|
|
|
xgit checkout updated-inputs
|
2024-03-17 16:59:11 +01:00
|
|
|
xgit_merge_theirs "${UPDATE_BRANCH}" "Update from ${UPDATE_BRANCH}"
|
2024-02-18 18:07:38 +01:00
|
|
|
|
|
|
|
echo "[!] Publish updated-inputs"
|
|
|
|
xgit push origin updated-inputs
|