git.iko.soy/rowtype-yoga/package-sets
on psc-0.14.3-20210823 help sign in
rowtype-yoga/package-sets/update-latest-compatible-sets.sh
42 lines 1.6 kB history raw
1#!/usr/bin/env nix-shell
2#!nix-shell -i bash
4set -euo pipefail
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.
11if [ $# -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
15fi
17function 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]): .}'
27function 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'
39tag=${1#refs/tags/}
40echo >&2 "Updating latest-compatible-sets.json for $tag"
41get_inputs $tag | combine > latest-compatible-sets.json.tmp
42mv latest-compatible-sets.json.tmp latest-compatible-sets.json