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 into master, bump the
5# Stackage 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# Fetch nixpkgs to get an up-to-date origin/haskell-updates branch.
57echo "Fetching origin..."
58git fetch origin >/dev/null
59
60# Make sure we are currently on a local haskell-updates branch.
61curr_branch="$(git rev-parse --abbrev-ref HEAD)"
62if [[ "$curr_branch" != "haskell-updates" ]]; then
63 die "Current branch is not called \"haskell-updates\"."
64fi
65
66# Make sure our local haskell-updates branch is on the same commit as
67# origin/haskell-updates.
68curr_branch_commit="$(git rev-parse haskell-updates)"
69origin_haskell_updates_commit="$(git rev-parse origin/haskell-updates)"
70if [[ "$curr_branch_commit" != "$origin_haskell_updates_commit" ]]; then
71 die "Current branch is not at the same commit as origin/haskell-updates"
72fi
73
74# Merge the current open haskell-updates PR.
75echo "Merging https://github.com/NixOS/nixpkgs/pull/${curr_haskell_updates_pr_num}..."
76gh pr merge --repo NixOS/nixpkgs --merge "$curr_haskell_updates_pr_num"
77
78# Update the list of Haskell package versions in NixOS on Hackage.
79echo "Updating list of Haskell package versions in NixOS on Hackage..."
80./maintainers/scripts/haskell/upload-nixos-package-list-to-hackage.sh
81
82# Update stackage, Hackage hashes, and regenerate Haskell package set
83echo "Updating Stackage..."
84./maintainers/scripts/haskell/update-stackage.sh --do-commit
85echo "Updating Hackage hashes..."
86./maintainers/scripts/haskell/update-hackage.sh --do-commit
87echo "Regenerating Hackage packages..."
88./maintainers/scripts/haskell/regenerate-hackage-packages.sh --do-commit
89
90# Push these new commits to the haskell-updates branch
91echo "Pushing commits just created to the remote haskell-updates branch..."
92git push
93
94# Open new PR
95new_pr_body=$(cat <<EOF
96### This Merge
97
98This PR is the regular merge of the \`haskell-updates\` branch into \`master\`.
99
100This 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).
101
102We 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/Mw5WLnzsP7fC4Zky) for who is currently in charge of this branch.
103
104### haskellPackages Workflow Summary
105
106Our 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).
107
108The short version is this:
109* We regularly update the Stackage and Hackage pins on \`haskell-updates\` (normally at the beginning of a merge window).
110* The community fixes builds of Haskell packages on that branch.
111* We aim at at least one merge of \`haskell-updates\` into \`master\` every two weeks.
112* We only do the merge if the [\`mergeable\`](https://hydra.nixos.org/job/nixpkgs/haskell-updates/mergeable) job is succeeding on hydra.
113* 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!)
114
115---
116
117This 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.
118EOF
119)
120
121echo "Opening a PR for the next haskell-updates merge cycle..."
122gh pr create --repo NixOS/nixpkgs --base master --head haskell-updates --title "haskellPackages: update stackage and hackage" --body "$new_pr_body"