summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/da/dataform/package.nix
blob: 780b6e89185438d6e5070dacc9302383147a0786 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
{
  lib,
  buildNpmPackage,
  fetchurl,
  nix-update-script,
  nodejs,
  makeWrapper,
  testers,
  runCommand,
  writableTmpDirAsHomeHook,
  cacert,
}:

buildNpmPackage (finalAttrs: {
  pname = "dataform";
  version = "3.0.69";

  __structuredAttrs = true;
  strictDeps = true;

  inherit nodejs;

  src = fetchurl {
    url = "https://registry.npmjs.org/@dataform/cli/-/cli-${finalAttrs.version}.tgz";
    hash = "sha256-1fOvQfSyl3a+pBZxJc52tSEPLxjMNcLd1SMQ4t4TqhM=";
  };

  # Inject the locally committed lockfile into the extracted source
  postPatch = ''
    cp ${./package-lock.json} package-lock.json
  '';

  npmDepsHash = "sha256-ZWGmCk9fZX9osQTy8BCyM4Hx2xA/QLaHNqhUCpaEceQ=";

  dontNpmBuild = true;

  nativeBuildInputs = [ makeWrapper ];

  postInstall = ''
    wrapProgram $out/bin/dataform \
      --prefix PATH : ${lib.makeBinPath [ nodejs ]}
  '';

  passthru = {
    updateScript = nix-update-script {
      extraArgs = [ "--generate-lockfile" ];
    };

    tests = {
      version = testers.testVersion {
        package = finalAttrs.finalPackage;
      };

      help = testers.runCommand {
        name = "${finalAttrs.pname}-help-test";
        nativeBuildInputs = [ finalAttrs.finalPackage ];
        script = ''
          dataform --help | grep -F "dataform [command]"
          touch $out
        '';
      };

      # `dataform install` should refuse to run against a workflow_settings.yaml
      # project -- this is expected behavior, not a bug: packages for these
      # projects are resolved at runtime instead.
      install-refuses = testers.testBuildFailure' {
        name = "${finalAttrs.pname}-install-refuses-test";
        drv =
          runCommand "${finalAttrs.pname}-install-refuses-test"
            {
              nativeBuildInputs = [ finalAttrs.finalPackage ];
            }
            ''
              dataform init test-project my-test-db US
              cd test-project
              dataform install .
            '';
        expectedBuilderLogEntries = [
          "No installation is needed when using workflow_settings.yaml"
        ];
      };

      # `dataform compile` on a freshly-initialized workflow_settings.yaml
      # project lazily fetches @dataform/core from the npm registry the
      # first time it's needed -- this is the "packages are installed at
      # runtime" behavior from the `install` refusal message actually
      # happening. Needs network + a CA bundle, unlike the other tests here.
      workflow = testers.runCommand {
        name = "${finalAttrs.pname}-workflow-test";
        nativeBuildInputs = [
          finalAttrs.finalPackage
          writableTmpDirAsHomeHook
          cacert
        ];
        script = ''
          dataform init test-project my-test-db US
          test -d test-project/definitions
          test -d test-project/includes
          test -f test-project/workflow_settings.yaml
          grep -F "my-test-db" test-project/workflow_settings.yaml
          grep -F "US" test-project/workflow_settings.yaml

          cd test-project
          dataform compile . | grep -F "Compiled 0 action(s)."

          touch $out
        '';
      };
    };
  };

  meta = {
    mainProgram = "dataform";
    description = "Dataform CLI";
    longDescription = ''
      Dataform is a framework for managing SQL based data operations in BigQuery
      Dataform CLI is an open-source command-line tool that allows developers to locally build,
      compile, test, and execute SQLX data transformation pipelines for BigQuery.
    '';
    homepage = "https://github.com/dataform-co/dataform";
    downloadPage = "https://www.npmjs.com/package/@dataform/cli";
    changelog = "https://github.com/dataform-co/dataform/releases#release-${finalAttrs.version}";
    license = lib.licenses.asl20;
    sourceProvenance = with lib.sourceTypes; [ binaryBytecode ];
    identifiers = {
      cpeParts = lib.meta.cpeFullVersionWithVendor "dataform-co" finalAttrs.version;
      purlParts = {
        type = "npm";
        spec = "%40dataform/cli@${finalAttrs.version}";
      };
    };
    platforms = lib.platforms.all;
    maintainers = with lib.maintainers; [ KristijanZic ];
  };
})