Commit 888f99c2 authored by KristijanZic's avatar KristijanZic
Browse files

pana: init at 0.23.10

parent 687fd7ba
Loading
Loading
Loading
Loading
+80 −0
Original line number Diff line number Diff line
{
  lib,
  buildDartApplication,
  fetchFromGitHub,
  callPackage,
  makeWrapper,
  flutter,
  dart,
}:
buildDartApplication rec {
  pname = "pana";
  version = "0.23.10";

  src = fetchFromGitHub {
    owner = "dart-lang";
    repo = "pana";
    tag = version;
    hash = "sha256-opkHUmfFbFHD1Gfx055YGNnxMoFFsTZvd/8VRN90HGA=";
  };

  dartEntryPoints = {
    "bin/pana" = "bin/pana.dart";
  };

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

  nativeBuildInputs = [ makeWrapper ];

  postInstall = ''
    # 1. Create a directory in the store to hold the license text files
    mkdir -p $out/share/pana/spdx-licenses

    # 2. Copy the .txt files from the source tree into the store
    # These are the files pana needs to perform license detection
    cp lib/src/third_party/spdx/licenses/*.txt $out/share/pana/spdx-licenses/

    # 3. Wrap the binary to always know where its data is and
    # where the dart-sdk and flutter-sdk are
    wrapProgram $out/bin/pana \
      --set FLUTTER_ROOT "${flutter}" \
      --prefix PATH : "${
        lib.makeBinPath [
          dart
          flutter
        ]
      }" \
      --add-flags "--dart-sdk ${dart} --flutter-sdk ${flutter} --license-data $out/share/pana/spdx-licenses"
  '';

  passthru = {
    updateScript = lib.getExe (callPackage ./update.nix { });
    tests = callPackage ./tests.nix { };
  };

  meta = {
    mainProgram = "pana";
    homepage = "https://pub.dev/packages/pana";
    description = "Package ANAlysis for Dart";
    longDescription = ''
      Package ANAlyzer - produce a report summarizing the health and quality of a Dart package.
    '';
    changelog = "https://pub.dev/packages/pana/changelog#${lib.replaceStrings [ "." ] [ "" ] version}";
    license = lib.licenses.bsd3;
    sourceProvenance = with lib.sourceTypes; [ fromSource ];
    identifiers.cpeParts =
      let
        versionSplit = lib.split "\\+" version;
        versionPart = lib.elemAt versionSplit 0;
        updatePart =
          if lib.count (x: lib.isList x) versionSplit > 0 then lib.elemAt versionSplit 2 else "*";
      in
      {
        vendor = "dart-lang";
        product = "pana";
        version = versionPart;
        update = updatePart;
      };
    maintainers = with lib.maintainers; [ KristijanZic ];
  };
}
+787 −0

File added.

Preview size limit exceeded, changes collapsed.

+148 −0
Original line number Diff line number Diff line
{
  testers,
  pana,
  git,
  jq,
}:
let
  testPkgName = "dummy_pkg";

  testLicense = ''
    MIT License

    Copyright (c) 2026 The Nixpkgs Authors

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
  '';
in
{
  usage = testers.runCommand {
    name = "pana-usage-test";
    buildInputs = [ pana ];
    script = ''
      export HOME=$TMPDIR
      pana > output.txt 2>&1 || true
      if grep -q "Usage: pana" output.txt; then
        touch $out
      else
        echo "Usage string not found in output."
        exit 1
      fi
    '';
  };

  # Comprehensive behavioral test
  json-output = testers.runCommand {
    name = "pana-json-test";
    buildInputs = [
      pana
      git
      jq
    ];

    script = ''
            # Nix sandbox environment setup
            export HOME=$TMPDIR
            export PUB_HOSTED_URL="http://localhost:0"

            init_package() {
              # Initialize a valid Dart package structure
              mkdir -p my_package/lib my_package/example
              cd my_package

              git init -b main
              git config user.email "test@example.com"
              git config user.name "Nix-Tester"

              cat > pubspec.yaml <<EOF
      name: ${testPkgName}
      version: 1.0.0
      description: >-
        A comprehensive test package for Nixpkgs validation that meets
        all the professional documentation requirements for pana scoring.
      repository: https://github.com/nixos/nixpkgs
      environment:
        sdk: '>=3.0.0 <4.0.0'
      EOF

              cat > lib/${testPkgName}.dart <<EOF
      /// A simple function to say hello.
      void hello() => print('hi');
      EOF

              cat > example/main.dart <<EOF
      import 'package:${testPkgName}/${testPkgName}.dart';
      void main() => hello();
      EOF

              echo "# Dummy Pkg" > README.md
              echo "## 1.0.0" > CHANGELOG.md
              cat > LICENSE <<EOF
      ${testLicense}
      EOF

              git add . && git commit -m "feat: initial package"
            }

            determine_marks() {
              PKG_NAME=$(jq -r '.packageName' report.json)
              # Extract the first license identifier found
              LICENSE_ID=$(jq -r '.result.licenses[0].spdxIdentifier' report.json)
              # Extract the status of the documentation section
              DOC_STATUS=$(jq -r '.report.sections[] | select(.id == "documentation") | .status' report.json)

              PASS="✅"
              FAIL="❌"

              # Determine marks
              [[ "$PKG_NAME" == "${testPkgName}" ]] && MARK_NAME="$PASS" || MARK_NAME="$FAIL"
              [[ "$LICENSE_ID" == "MIT" ]]     && MARK_LIC="$PASS"  || MARK_LIC="$FAIL"
              [[ "$DOC_STATUS" == "passed" ]]  && MARK_DOC="$PASS"  || MARK_DOC="$FAIL"

              echo "---------------------------------------"
              printf "%-10s %-20s %s\n" "Package:" "$PKG_NAME"   "$MARK_NAME"
              printf "%-10s %-20s %s\n" "License:" "$LICENSE_ID" "$MARK_LIC"
              printf "%-10s %-20s %s\n" "Docs:"    "$DOC_STATUS" "$MARK_DOC"
              echo "---------------------------------------"
            }

            check_marks() {
              if [[ "$MARK_NAME" == "$PASS" && "$MARK_LIC" == "$PASS" && "$MARK_DOC" == "$PASS" ]]; then
                echo "Integration test passed successfully! 🚀"
                touch $out
              else
                echo "Integration test failed metadata verification! ⚠️"
                # Print specifically why it failed to the log
                jq -r '.report.sections[] | select(.status == "failed") | "Section [\(.id)]: \(.summary)"' report.json
                exit 1
              fi
            }

            main() {
              init_package
              echo "Running pana analysis...🔍"
              pana --json . > report.json
              determine_marks
              check_marks
            }

            main
    '';
  };
}
+61 −0
Original line number Diff line number Diff line
{
  writeShellApplication,
  common-updater-scripts,
  nix-update,
  yq-go,
  dart,
  nix,
}:
let
  name = "update-pana";
  packageName = "pana";
  packageDir = toString ./.;
in
writeShellApplication {
  inherit name;
  runtimeInputs = [
    common-updater-scripts
    nix-update
    yq-go
    dart
    nix
  ];
  text = ''
    pname="''${UPDATE_NIX_PNAME:-${packageName}}"

    main() {
      old_version="''${UPDATE_NIX_OLD_VERSION:-$(get_version)}"
      nix-update "$pname" --version stable
      new_version=$(get_version)
      if [[ "$new_version" == "$old_version" ]]; then
        exit 0
      fi
      generate_lockfile
    }

    get_version() {
      nix-instantiate --raw --eval --strict -A "$pname.version"
    }

    generate_lockfile() {
      tmp_dir=$(mktemp -d)
      trap 'rm -rf "$tmp_dir"' EXIT

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

      cp -r "$src/." "$tmp_dir/"
      chmod -R +w "$tmp_dir"
      cd "$tmp_dir"

      # 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 > "${packageDir}/pubspec.lock.json"
    }

    main
  '';
}