1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p jq
3
4set -o pipefail -o errexit -o nounset
5
6trace() { echo >&2 "$@"; }
7
8tmp=$(mktemp -d)
9cleanup() {
10 # Don't exit early if anything fails to cleanup
11 set +o errexit
12
13 trace -n "Cleaning up.. "
14
15 [[ -e "$tmp/base" ]] && git worktree remove --force "$tmp/base"
16 [[ -e "$tmp/merged" ]] && git worktree remove --force "$tmp/merged"
17
18 rm -rf "$tmp"
19
20 trace "Done"
21}
22trap cleanup exit
23
24
25repo=https://github.com/NixOS/nixpkgs.git
26
27if (( $# != 0 )); then
28 baseBranch=$1
29 shift
30else
31 trace "Usage: $0 BASE_BRANCH [REPOSITORY]"
32 trace "BASE_BRANCH: The base branch to use, e.g. master or release-23.11"
33 trace "REPOSITORY: The repository to fetch the base branch from, defaults to $repo"
34 exit 1
35fi
36
37if (( $# != 0 )); then
38 repo=$1
39 shift
40fi
41
42if [[ -n "$(git status --porcelain)" ]]; then
43 trace -e "\e[33mWarning: Dirty tree, uncommitted changes won't be taken into account\e[0m"
44fi
45headSha=$(git rev-parse HEAD)
46trace -e "Using HEAD commit \e[34m$headSha\e[0m"
47
48trace -n "Creating Git worktree for the HEAD commit in $tmp/merged.. "
49git worktree add --detach -q "$tmp/merged" HEAD
50trace "Done"
51
52trace -n "Fetching base branch $baseBranch to compare against.. "
53git fetch -q "$repo" refs/heads/"$baseBranch"
54baseSha=$(git rev-parse FETCH_HEAD)
55trace -e "\e[34m$baseSha\e[0m"
56
57trace -n "Creating Git worktree for the base branch in $tmp/base.. "
58git worktree add -q "$tmp/base" "$baseSha"
59trace "Done"
60
61trace -n "Merging base branch into the HEAD commit in $tmp/merged.. "
62git -C "$tmp/merged" merge -q --no-edit "$baseSha"
63trace -e "\e[34m$(git -C "$tmp/merged" rev-parse HEAD)\e[0m"
64
65trace "Running nixpkgs-vet.."
66nix-build ci -A nixpkgs-vet --arg base "$tmp/base" --arg head "$tmp/merged"