-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-push
executable file
·47 lines (38 loc) · 1.59 KB
/
pre-push
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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