1#! /usr/bin/env nix-shell
2#! nix-shell -i bash -p git gh -I nixpkgs=.
3#
4# Script to merge the currently open haskell-updates PR , bump the Stackage
5# version and Hackage versions, and open the next haskell-updates PR.
6
7set -eu -o pipefail
8
9# exit after printing first argument to this function
10function die {
11 # echo the first argument
12 echo "ERROR: $1"
13 echo "Aborting!"
14
15 exit 1
16}
17
18function help {
19 echo "Usage: $0 HASKELL_UPDATES_PR_NUM"
20 echo "Merge the currently open haskell-updates PR into master, and open the next one."
21 echo
22 echo " -h, --help print this help"
23 echo " HASKELL_UPDATES_PR_NUM number of the currently open PR on NixOS/nixpkgs"
24 echo " for the haskell-updates branch"
25 echo
26 echo "Example:"
27 echo " \$ $0 137340"
28
29 exit 1
30}
31
32# Read in the current haskell-updates PR number from the command line.
33while [[ $# -gt 0 ]]; do
34 key="$1"
35
36 case $key in
37 -h|--help)
38 help
39 ;;
40 *)
41 curr_haskell_updates_pr_num="$1"
42 shift
43 ;;
44 esac
45done
46
47if [[ -z "${curr_haskell_updates_pr_num-}" ]] ; then
48 die "You must pass the current haskell-updates PR number as the first argument to this script."
49fi
50
51# Make sure you have gh authentication setup.
52if ! gh auth status 2>/dev/null ; then
53 die "You must setup the \`gh\` command. Run \`gh auth login\`."
54fi
55
56# Make sure this is configured before we start doing anything
57push_remote="$(git config branch.haskell-updates.pushRemote)" \
58 || die 'Can'\''t determine pushRemote for haskell-updates. Please set using `git config branch.haskell-updates.pushremote <remote name>`.'
59
60# Fetch nixpkgs to get an up-to-date origin/haskell-updates branch.
61echo "Fetching origin..."
62git fetch origin >/dev/null
63
64# Make sure we are currently on a local haskell-updates branch.
65curr_branch="$(git rev-parse --abbrev-ref HEAD)"
66if [[ "$curr_branch" != "haskell-updates" ]]; then
67 die "Current branch is not called \"haskell-updates\"."
68fi
69
70# Make sure our local haskell-updates branch is on the same commit as
71# origin/haskell-updates.
72curr_branch_commit="$(git rev-parse haskell-updates)"
73origin_haskell_updates_commit="$(git rev-parse origin/haskell-updates)"
74if [[ "$curr_branch_commit" != "$origin_haskell_updates_commit" ]]; then
75 die "Current branch is not at the same commit as origin/haskell-updates"
76fi
77
78# Merge the current open haskell-updates PR.
79echo "Merging https://github.com/NixOS/nixpkgs/pull/${curr_haskell_updates_pr_num}..."
80gh pr merge --repo NixOS/nixpkgs --merge "$curr_haskell_updates_pr_num"
81
82# Update stackage, Hackage hashes, and regenerate Haskell package set
83./maintainers/scripts/haskell/update-package-set.sh
84
85# Push these new commits to the haskell-updates branch
86echo "Pushing commits just created to the remote $push_remote/haskell-updates branch..."
87git push "$push_remote" haskell-updates
88
89# Open new PR
90new_pr_body=$(cat <<EOF
91### This Merge
92
93This PR is the regular merge of the \`haskell-updates\` branch into \`staging\`.
94
95This branch is being continually built and tested by hydra at https://hydra.nixos.org/jobset/nixpkgs/haskell-updates. You may be able to find an up-to-date Hydra build report at [cdepillabout/nix-haskell-updates-status](https://github.com/cdepillabout/nix-haskell-updates-status).
96
97We roughly aim to merge these \`haskell-updates\` PRs at least once every two weeks. See the @NixOS/haskell [team calendar](https://cloud.maralorn.de/apps/calendar/p/H6migHmKX7xHoTFa) for who is currently in charge of this branch.
98
99### haskellPackages Workflow Summary
100
101Our workflow is currently described in [\`pkgs/development/haskell-modules/HACKING.md\`](https://github.com/NixOS/nixpkgs/blob/haskell-updates/pkgs/development/haskell-modules/HACKING.md).
102
103The short version is this:
104* We regularly update the Stackage and Hackage pins on \`haskell-updates\` (normally at the beginning of a merge window).
105* The community fixes builds of Haskell packages on that branch.
106* We aim at at least one merge of \`haskell-updates\` into \`staging\` every two weeks.
107* We only do the merge if the [\`mergeable\`](https://hydra.nixos.org/job/nixpkgs/haskell-updates/mergeable) job is succeeding on hydra.
108* If a [\`maintained\`](https://hydra.nixos.org/job/nixpkgs/haskell-updates/maintained) package is still broken at the time of merge, we will only merge if the maintainer has been pinged 7 days in advance. (If you care about a Haskell package, become a maintainer!)
109
110More information about Haskell packages in nixpkgs can be found [in the nixpkgs manual](https://nixos.org/manual/nixpkgs/unstable/#haskell).
111
112---
113
114This is the follow-up to #${curr_haskell_updates_pr_num}. Come to [#haskell:nixos.org](https://matrix.to/#/#haskell:nixos.org) if you have any questions.
115EOF
116)
117
118echo "Opening a PR for the next haskell-updates merge cycle..."
119gh pr create --repo NixOS/nixpkgs --base staging --head haskell-updates --title "haskellPackages: update stackage and hackage" --body "$new_pr_body"