Module: Polyrun::Prepare::Artifacts

Defined in:
lib/polyrun/prepare/artifacts.rb

Overview

Writes polyrun-artifacts.json (spec2 §3) for cache keys and CI upload lists.

Constant Summary collapse

VERSION =
1

Class Method Summary collapse

Class Method Details

.normalize_entry(e) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/polyrun/prepare/artifacts.rb', line 27

def normalize_entry(e)
  h = e.transform_keys(&:to_s)
  p = h["path"].to_s
  kind = h["kind"] || (File.directory?(p) ? "directory" : "file")
  out = {"path" => p, "kind" => kind}
  if File.exist?(p)
    out["size"] = File.size(p) if File.file?(p)
    out["digest"] = h["digest"] || (File.file?(p) ? "sha256:#{Digest::SHA256.file(p).hexdigest}" : nil)
  end
  out.compact
end

.write!(root:, recipe:, entries:, dry_run: false) ⇒ Object

entries is array of hashes: { “path” => …, “kind” => “file”|“directory”, optional “digest”, “size” }



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/polyrun/prepare/artifacts.rb', line 13

def write!(root:, recipe:, entries:, dry_run: false)
  list = entries.map { |e| normalize_entry(e) }
  doc = {
    "version" => VERSION,
    "recipe" => recipe,
    "dry_run" => dry_run,
    "generated_at" => Time.now.utc.iso8601,
    "artifacts" => list
  }
  path = File.join(root, "polyrun-artifacts.json")
  File.write(path, JSON.pretty_generate(doc))
  path
end