Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/reusable-update-flake-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ on:
default: '["self-hosted"]'
required: false
type: string
flake-input:
description: 'Parameter for determining which flake will get updated'
default: ''
required: false
type: string

secrets:
NIX_GITHUB_TOKEN:
Expand Down Expand Up @@ -46,7 +51,7 @@ jobs:
curl -fsSL --proto '=https' --tlsv1.2 \
https://raw.githubusercontent.com/metacraft-labs/nixos-modules/main/scripts/commit_flake_update.bash \
-o commit_flake_update.bash
bash commit_flake_update.bash
FLAKE_INPUT=${{ inputs.flake-input }} bash commit_flake_update.bash
- uses: tibdex/[email protected]
id: generate-token
Expand Down
24 changes: 19 additions & 5 deletions scripts/commit_flake_update.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -euo pipefail

FLAKE_INPUT=${FLAKE_INPUT:-""}

if ! git config --get user.name >/dev/null 2>&1 || \
[ "$(git config --get user.name)" = "" ] ||
! git config --get user.email >/dev/null 2>&1 || \
Expand All @@ -15,11 +17,15 @@ fi
current_commit="$(git rev-parse HEAD)"
export PRE_COMMIT_ALLOW_NO_CONFIG=1

nix flake update --accept-flake-config --commit-lock-file
nix flake update $FLAKE_INPUT --accept-flake-config --commit-lock-file
commit_after_update="$(git rev-parse HEAD)"

if [[ "$commit_after_update" = "$current_commit" ]]; then
echo "All flake inputs are up to date."
if [[ "$FLAKE_INPUT" = "" ]]; then
echo "All flake inputs are up to date."
else
echo "$FLAKE_INPUT input is up to date."
fi
exit 0
fi

Expand All @@ -30,11 +36,19 @@ msg_file=./commit_msg_body.txt
echo '```'
} > $msg_file

git commit --amend -F - <<EOF
chore(flake.lock): Update all Flake inputs ($(date -I))
if [[ "$FLAKE_INPUT" = "" ]]; then
git commit --amend -F - <<EOF
chore(flake.lock): Update all Flake inputs ($(date -I))

$(cat $msg_file)
EOF
else
git commit --amend -F - <<EOF
chore(flake.lock): Update \`$FLAKE_INPUT\` Flake input ($(date -I))

$(cat $msg_file)
$(cat $msg_file)
EOF
fi

if [ -z "${CI+x}" ]; then
rm -v $msg_file
Expand Down