1
0
Fork 0
mirror of https://git.madhouse-project.org/actions/nix-flake-update-pr.git synced 2025-05-13 07:19:53 +02:00

Initial import

Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2024-02-18 17:13:08 +01:00
commit 130d7bfc05
No known key found for this signature in database
3 changed files with 370 additions and 0 deletions

36
bin/nix-flake-update-pr Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2024 Gergely Nagy
# SPDX-FileContributor: Gergely Nagy
#
# SPDX-License-Identifier: EUPL-1.2
set -euo pipefail
nfup_setup_credentials() {
git config --local "http.${GITHUB_SERVER_URL}/.extraHeader" "Authorization: bearer ${INPUT_TOKEN}"
git config --local user.name "${INPUT_AUTHOR_NAME}"
git config --local user.email "${INPUT_AUTHOR_EMAIL}"
}
nfup_update() {
nix flake update --commit-lock-file
}
nfup_push() {
git push -f origin "HEAD:refs/for/${INPUT_TARGET_BRANCH}" -o topic="${INPUT_BRANCH}" -o force-push=1
}
nfup_pick_output() {
url="$(grep "remote: *${GITHUB_SERVER_URL}" | sed -e "s,remote: *,," | sed -e 's, *$,,')"
pullid="${url//*\/pulls\/}"
echo "pull-request-number=${pullid}" >>"${GITHUB_OUTPUT}"
echo "pull-request-url=${url}" >>"${GITHUB_OUTPUT}"
}
PUSH_OUTPUT=$(mktemp)
nfup_setup_credentials
nfup_update
nfup_push 2>&1 | tee "${PUSH_OUTPUT}"
nfup_pick_output <"${PUSH_OUTPUT}"
rm -f "${PUSH_OUTPUT}"