@@ -0,0 +1,42 @@
1+#!/usr/bin/env nix-shell
2+#!nix-shell -i bash
3+
4+set -euo pipefail
5+
6+# This script takes one command-line argument of a package set tag which is
7+# about to be released, and updates the latest-compatible-sets.json file where
8+# necessary so that the new package set is marked as the latest compatible set
9+# for the appropriate compiler version.
10+
11+if [ $# -ne 1 ]; then
12+ echo >&2 "Expected one argument, got $#"
13+ echo >&2 "Usage: update-latest-compatible-sets.sh PACKAGE_SET_VERSION"
14+ exit 1
15+fi
16+
17+function get_inputs() {
18+ # Get the existing mapping of compiler versions to latest package sets for
19+ # that version
20+ cat latest-compatible-sets.json
21+ # Print a JSON object in the same schema as the latest-compatible-sets.json
22+ # file, containing just the version which is about to be released. e.g.
23+ # { "0.13.8": "psc-0.13.8-20200911-2" }
24+ echo $1 | jq --raw-input '{ (split("-")[1]): .}'
25+}
26+
27+function combine() {
28+ # Change the input JSON object into an array of objects like
29+ #
30+ # { key: "0.13.8", value: "psc-0.13.8-20200911-2" }
31+ #
32+ # then sort by 'value' so that more recent releases come later, and finally
33+ # convert back to a JSON object. The sorting is important so that newer
34+ # releases for a given compiler version that they take precedence when we
35+ # combine the array back into a single object.
36+ jq --slurp 'map(to_entries | .[]) | sort_by(.value) | from_entries'
37+}
38+
39+tag=${1#refs/tags/}
40+echo >&2 "Updating latest-compatible-sets.json for $tag"
41+get_inputs $tag | combine > latest-compatible-sets.json.tmp
42+mv latest-compatible-sets.json.tmp latest-compatible-sets.json