forked from purescript/package-sets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-latest-compatible-sets.sh
executable file
·42 lines (36 loc) · 1.55 KB
/
update-latest-compatible-sets.sh
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
#!/usr/bin/env nix-shell
#!nix-shell -i bash
set -euo pipefail
# This script takes one command-line argument of a package set tag which is
# about to be released, and updates the latest-compatible-sets.json file where
# necessary so that the new package set is marked as the latest compatible set
# for the appropriate compiler version.
if [ $# -ne 1 ]; then
echo >&2 "Expected one argument, got $#"
echo >&2 "Usage: update-latest-compatible-sets.sh PACKAGE_SET_VERSION"
exit 1
fi
function get_inputs() {
# Get the existing mapping of compiler versions to latest package sets for
# that version
cat latest-compatible-sets.json
# Print a JSON object in the same schema as the latest-compatible-sets.json
# file, containing just the version which is about to be released. e.g.
# { "0.13.8": "psc-0.13.8-20200911-2" }
echo $1 | jq --raw-input '{ (split("-")[1]): .}'
}
function combine() {
# Change the input JSON object into an array of objects like
#
# { key: "0.13.8", value: "psc-0.13.8-20200911-2" }
#
# then sort by 'value' so that more recent releases come later, and finally
# convert back to a JSON object. The sorting is important so that newer
# releases for a given compiler version that they take precedence when we
# combine the array back into a single object.
jq --slurp 'map(to_entries | .[]) | sort_by(.value) | from_entries'
}
tag=${1#refs/tags/}
echo >&2 "Updating latest-compatible-sets.json for $tag"
get_inputs $tag | combine > latest-compatible-sets.json.tmp
mv latest-compatible-sets.json.tmp latest-compatible-sets.json