rover: init at 0.4.8

Add Rover CLI for managing and maintaining graphs with Apollo Studio.
This commit is contained in:
ivanbrennan 2022-03-14 15:23:55 -04:00 committed by Yt
parent 276ee7bba8
commit 4bf427a738
6 changed files with 344 additions and 0 deletions

View File

@ -0,0 +1,56 @@
{ lib
, callPackage
, fetchFromGitHub
, perl
, rustPlatform
, librusty_v8 ? callPackage ./librusty_v8.nix { }
}:
rustPlatform.buildRustPackage rec {
pname = "rover";
version = "0.4.8";
src = fetchFromGitHub {
owner = "apollographql";
repo = pname;
rev = "v${version}";
sha256 = "sha256-9o2bGa9vxN7EprKgsy9TI7AFmwjo1OT1pDyiLierTq0=";
};
cargoSha256 = "sha256-4oNuyZ1xNK2jP9QFEcthCjEQRyvFykd5N0j5KCXrzVY=";
# The v8 package will try to download a `librusty_v8.a` release at build time
# to our read-only filesystem. To avoid this we pre-download the file and
# export it via RUSTY_V8_ARCHIVE
RUSTY_V8_ARCHIVE = librusty_v8;
nativeBuildInputs = [
perl
];
# The rover-client's build script (crates/rover-client/build.rs) will try to
# download the API's graphql schema at build time to our read-only filesystem.
# To avoid this we pre-download it to a location the build script checks.
preBuild = ''
mkdir crates/rover-client/.schema
cp ${./schema}/etag.id crates/rover-client/.schema/
cp ${./schema}/schema.graphql crates/rover-client/.schema/
'';
passthru.updateScript = ./update.sh;
# Some tests try to write configuration data to a location in the user's home
# directory. Since this would be /homeless-shelter during the build, point at
# a writeable location instead.
preCheck = ''
export APOLLO_CONFIG_HOME="$PWD"
'';
meta = with lib; {
description = "A CLI for managing and maintaining graphs with Apollo Studio";
homepage = "https://www.apollographql.com/docs/rover";
license = licenses.mit;
maintainers = [ maintainers.ivanbrennan ];
platforms = ["x86_64-linux"];
};
}

View File

@ -0,0 +1,17 @@
{ rust, stdenv, fetchurl }:
let
arch = rust.toRustTarget stdenv.hostPlatform;
fetch_librusty_v8 = args: fetchurl {
name = "librusty_v8-${args.version}";
url = "https://github.com/denoland/rusty_v8/releases/download/v${args.version}/librusty_v8_release_${arch}.a";
sha256 = args.shas.${stdenv.hostPlatform.system};
meta = { inherit (args) version; };
};
in
fetch_librusty_v8 {
version = "0.38.1";
shas = {
x86_64-linux = "sha256-vRkb5ZrIOYSKa84UbsJD+Oua0wve7f1Yf3kMg/kkYSY=";
};
}

View File

@ -0,0 +1 @@
1bdcf8916afc3cea660add457724dddd70154904f4e360e15da27fa7d5c43cd0

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,96 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl gnugrep gnused jq nix-prefetch
set -eu -o pipefail
dirname=$(realpath "$(dirname "$0")")
nixpkgs=$(realpath "${dirname}/../../../..")
old_rover_version=$(nix eval --raw -f "$nixpkgs" rover.version)
rover_url=https://api.github.com/repos/apollographql/rover/releases/latest
rover_tag=$(curl "$rover_url" | jq --raw-output ".tag_name")
rover_version="$(expr "$rover_tag" : 'v\(.*\)')"
if [[ "$old_rover_version" == "$rover_version" ]]; then
echo "rover is up-to-date: ${old_rover_version}"
exit 0
fi
echo "Fetching rover"
rover_tar_url="https://github.com/apollographql/rover/archive/refs/tags/${rover_tag}.tar.gz"
{
read rover_hash
read repo
} < <(nix-prefetch-url "$rover_tar_url" --unpack --type sha256 --print-path)
# Convert hash to SRI representation
rover_sri_hash=$(nix hash to-sri --type sha256 "$rover_hash")
# Identify librusty version and hash
librusty_version=$(
sed --quiet '/^name = "v8"$/{n;p}' "${repo}/Cargo.lock" \
| grep --only-matching --perl-regexp '^version = "\K[^"]+'
)
librusty_arch=x86_64-unknown-linux-gnu
librusty_url="https://github.com/denoland/rusty_v8/releases/download/v${librusty_version}/librusty_v8_release_${librusty_arch}.a"
echo "Fetching librusty"
librusty_hash=$(nix-prefetch-url "$librusty_url" --type sha256)
librusty_sri_hash=$(nix hash to-sri --type sha256 "$librusty_hash")
# Update rover version.
sed --in-place \
"s|version = \"[0-9.]*\"|version = \"$rover_version\"|" \
"$dirname/default.nix"
# Update rover hash.
sed --in-place \
"s|sha256 = \"[a-zA-Z0-9\/+-=]*\"|sha256 = \"$rover_sri_hash\"|" \
"$dirname/default.nix"
# Clear cargoSha256.
sed --in-place \
"s|cargoSha256 = \".*\"|cargoSha256 = \"sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\"|" \
"$dirname/default.nix"
# Update cargoSha256
echo "Computing cargoSha256"
cargoSha256=$(
nix-prefetch "{ sha256 }: (import $nixpkgs {}).rover.cargoDeps.overrideAttrs (_: { outputHash = sha256; })"
)
sed --in-place \
"s|cargoSha256 = \".*\"|cargoSha256 = \"$cargoSha256\"|" \
"$dirname/default.nix"
# Update librusty version
sed --in-place \
"s|version = \"[0-9.]*\"|version = \"$librusty_version\"|" \
"$dirname/librusty_v8.nix"
# Update librusty hash
sed --in-place \
"s|x86_64-linux = \"[^\"]*\"|x86_64-linux = \"$librusty_sri_hash\"|" \
"$dirname/librusty_v8.nix"
# Update apollo api schema info
response="$(mktemp)"
schemaUrl=https://graphql.api.apollographql.com/api/schema
mkdir -p "$dirname"/schema
# Fetch schema info
echo "Fetching Apollo GraphQL schema"
# include response headers, and append terminating newline to response body
curl --include --write-out "\n" "$schemaUrl" > "$response"
# Parse response headers and write the etag to schema/etag.id
grep \
--max-count=1 \
--only-matching \
--perl-regexp \
'^etag: \K\S*' \
"$response" \
> "$dirname"/schema/etag.id
# Discard headers and blank line (terminated by carriage return), and write the
# response body to schema/schema.graphql
sed '1,/^\r/d' "$response" > "$dirname"/schema/schema.graphql

View File

@ -20000,6 +20000,8 @@ with pkgs;
ronn = callPackage ../development/tools/ronn { };
rover = callPackage ../development/tools/rover { };
rshell = python3.pkgs.callPackage ../development/embedded/rshell { };
rttr = callPackage ../development/libraries/rttr { };