Skip to content

Commit

Permalink
Add pre-push hook
Browse files Browse the repository at this point in the history
  • Loading branch information
bryango committed Sep 30, 2024
1 parent 227e054 commit 63c70fc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 47 additions & 0 deletions pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env nix
#! nix env shell nixpkgs#bash nixpkgs#gh nixpkgs#jq nixpkgs#gh --command bash
# check if the dependent `nixpkgs-config` is successfully built with github actions
# shellcheck shell=bash

# This hook is called with the following parameters:
#
# $1 -- Name of the remote to which the push is being done
# $2 -- URL to which the push is being done
#
# If pushing without using a named remote those arguments will be equal.
#
# Information about the commits which are being pushed is supplied as lines to
# the standard input in the form:
#
# <local ref> <local oid> <remote ref> <remote oid>

set -e

while read -r local_ref local_oid remote_ref remote_oid
do
>&2 printf "pre-push: %s\t%s\n" "$local_ref" "$local_oid"
>&2 printf " -> %s\t%s\n" "$remote_ref" "$remote_oid"

rev=$(nix flake metadata --json | jq --raw-output '.locks.nodes."nixpkgs-config".locked.rev')
>&2 echo "flake.lock: nixpkgs-config @ $rev"

cd nixpkgs-config || exit 1
gh_runs=$(gh run list --commit "$rev" --json attempt,conclusion,databaseId,displayTitle,headSha,status,updatedAt,url)
echo "$gh_runs" | jq 'sort_by(.databaseId) | reverse'

latest_status=$(echo "$gh_runs" | jq --raw-output 'sort_by(.databaseId) | reverse | .[0].status')
if [[ "$latest_status" != "completed" ]]; then
>&2 echo "nixpkgs-config: $latest_status, not completed"
exit 1
fi

latest_conclusion=$(echo "$gh_runs" | jq --raw-output 'sort_by(.databaseId) | reverse | .[0].conclusion')
if [[ "$latest_conclusion" != "success" ]]; then
>&2 echo "nixpkgs-config: $latest_conclusion, not successful"
exit 1
fi
done

exit 0

# vim: ft=sh
2 changes: 1 addition & 1 deletion profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"active": true,
"priority": 5,
"storePaths": [
"/nix/store/775sjz37pzpmrdd3wzbmhcmjx3m2vk04-home-manager-path"
"/nix/store/mcdrzisivvzplw8asvf9wns1rwkmjx96-home-manager-path"
]
}
},
Expand Down

0 comments on commit 63c70fc

Please sign in to comment.