1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p curl common-updater-scripts coreutils jq yarn-berry.yarn-berry-fetcher
3
4set -o errexit -o nounset -o pipefail
5set -o xtrace # debugging
6
7# Configuration
8owner='prettier'
9repo='prettier'
10package='prettier'
11
12cleanup() {
13 rm --force --recursive "${tmpdir}"
14}
15trap cleanup EXIT
16tmpdir="$(mktemp --directory)"
17
18disable_cleanup() {
19 # We want to keep the temporary directory in case of error
20 trap - EXIT
21}
22trap disable_cleanup ERR
23
24curl_command=(curl --fail ${GITHUB_TOKEN:+--user ":${GITHUB_TOKEN}"})
25jq_command=(jq --raw-output)
26
27current_version=$(nix-instantiate --eval --expr "with import ./. {}; ${package}.version or (lib.getVersion ${package})" --raw)
28echo "Current version: ${current_version}"
29
30latest_version="$("${curl_command[@]}" "https://api.github.com/repos/${owner}/${repo}/releases/latest" | "${jq_command[@]}" .tag_name)"
31echo "Latest version: ${latest_version}"
32
33if [[ "${current_version}" == "${latest_version}" ]]; then
34 echo "${package} is up to date: ${current_version}"
35 exit 0
36else
37 echo "Updating ${package} from ${current_version} to ${latest_version}…"
38fi
39
40package_dir="pkgs/by-name/${package::2}/${package}"
41"${curl_command[@]}" --output "${package_dir}/package.json" "https://raw.githubusercontent.com/${owner}/${repo}/${latest_version}/package.json"
42
43update-source-version "${package}" "${latest_version}"
44
45echo "Update yarn offline cache hash…"
46nix-build --attr "${package}.src"
47yarn-berry-fetcher missing-hashes result/yarn.lock >"${package_dir}/missing-hashes.json"