Unverified Commit 69981947 authored by Fernando Rodrigues's avatar Fernando Rodrigues Committed by GitHub
Browse files

serverpod_cli: init at 3.3.1 (#487828)

parents e881eed1 edb06beb
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -14278,6 +14278,13 @@
    githubId = 80984519;
    name = "Kristian Alvestad Nedevold-Hansen";
  };
  KristijanZic = {
    name = "Kristijan Zic";
    github = "KristijanZic";
    githubId = 10299892;
    email = "maintainer@zic.email";
    matrix = "@kristijan.zic:matrix.org";
  };
  kristoff3r = {
    email = "k.soeholm@gmail.com";
    github = "kristoff3r";
+69 −0
Original line number Diff line number Diff line
{
  lib,
  buildDartApplication,
  fetchFromGitHub,
  yq-go,
  versionCheckHook,
  writableTmpDirAsHomeHook,
}:
buildDartApplication rec {
  pname = "serverpod_cli";
  version = "3.3.1";

  # Fetch the whole monorepo
  src = fetchFromGitHub {
    owner = "serverpod";
    repo = "serverpod";
    rev = version;
    hash = "sha256-4vpZiqvzhcAziElfzssw4bLYTO5/dhai3C8LEpn0eAo=";
  };

  sourceRoot = "${src.name}/tools/serverpod_cli";

  dartEntryPoints = {
    "bin/serverpod" = "bin/serverpod_cli.dart";
  };

  pubspecLock = lib.importJSON ./pubspec.lock.json;

  nativeBuildInputs = [ yq-go ];

  nativeInstallCheckInputs = [
    versionCheckHook
    writableTmpDirAsHomeHook
  ];

  doInstallCheck = true;

  versionCheckKeepEnvironment = "HOME";

  preBuild = ''
    # Set productionMode to true.
    substituteInPlace lib/src/generated/version.dart \
      --replace-fail "const productionMode = false;" "const productionMode = true;"

    # Remove the dependency_overrides section.
    # Relative path overrides in the monorepo break the Nix build which expects
    # all dependencies to be resolved via the lockfile.
    yq -i 'del(.dependency_overrides)' pubspec.yaml
  '';

  passthru.updateScript = ./update.sh;

  meta = with lib; {
    mainProgram = "serverpod";
    homepage = "https://serverpod.dev";
    description = "Command line tools for Serverpod";
    longDescription = ''
      Serverpod is a next-generation app and web server,
      built for the Flutter community.
      It allows you to write your server-side code in Dart,
      automatically generate your APIs, and hook up your
      database with minimal effort. Serverpod is open-source,
      and you can host your server anywhere.
    '';
    changelog = "https://raw.githubusercontent.com/serverpod/serverpod/${version}/CHANGELOG.md";
    license = licenses.bsd3;
    maintainers = with lib.maintainers; [ KristijanZic ];
  };
}
+837 −0

File added.

Preview size limit exceeded, changes collapsed.

+56 −0
Original line number Diff line number Diff line
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p coreutils jq yq-go git nix-prefetch-github common-updater-scripts dart

set -euo pipefail

PACKAGE_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
NIX_FILE="$PACKAGE_DIR/package.nix"

echo "Checking for latest serverpod version..."
latest_version=$(git ls-remote --tags https://github.com/serverpod/serverpod.git | \
    grep -v "\^{}" | \
    cut -f2 | \
    sed 's/refs\/tags\///' | \
    grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | \
    sort -V | \
    tail -n 1)

current_version=$(sed -n 's/^[[:space:]]*version = "\(.*\)";/\1/p' "$NIX_FILE")

if [[ "$latest_version" == "$current_version" ]]; then
    echo "serverpod_cli is already up to date ($current_version)"
    exit 0
fi

echo "Updating serverpod_cli from $current_version to $latest_version"

echo "Prefetching source for $latest_version..."
PREFETCH_OUT=$(nix-prefetch-github serverpod serverpod --rev "$latest_version")
echo "Prefetch output: $PREFETCH_OUT"
new_hash=$(echo "$PREFETCH_OUT" | jq -r .hash)
echo "New hash: $new_hash"

update-source-version serverpod_cli "$latest_version" "$new_hash" --version-key=version --file="$NIX_FILE"

echo "Generating fresh pubspec.lock.json..."
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT

src=$(nix-build --no-link . -A serverpod_cli.src)

cp -r "$src/tools/serverpod_cli/"* "$TMPDIR/"
chmod -R +w "$TMPDIR"
cd "$TMPDIR"

# Remove dependency_overrides as in the nix build
yq -i 'del(.dependency_overrides)' pubspec.yaml

# Generate lockfile because it's not included in the source
if ! test -f pubspec.lock; then
  dart pub get
fi

# Convert to JSON
yq -o=json . pubspec.lock > "$PACKAGE_DIR/pubspec.lock.json"

echo "Update complete: $current_version -> $latest_version"