Class: Everywhere::Receipt

Inherits:
Object
  • Object
show all
Defined in:
lib/everywhere/receipt.rb

Overview

Builds the machine-readable build receipt (release.json) — the same shape emitted by local, CI, and Platform builds. See platform/docs/build-engine.md §7.

Two layers:

* the *resolved manifest* — the deterministic build request (app,
framework, ruby, toolchain versions, source checksums, target,
permissions). Everything here is knowable BEFORE the build runs and
carries no volatile fields, so the same source + toolchain hashes
identically (manifest_checksum).
* the *artifact* record — filename, checksum, size, and the generic
`signing` block, layered on once a build has produced something.

Constant Summary collapse

SCHEMA =
1

Instance Method Summary collapse

Constructor Details

#initialize(root:, config:, framework:, ruby:, target:, channel:, shell_dir: nil) ⇒ Receipt

Returns a new instance of Receipt.



25
26
27
28
29
30
31
32
# File 'lib/everywhere/receipt.rb', line 25

def initialize(root:, config:, framework:, ruby:, target:, channel:, shell_dir: nil)
  @root = File.expand_path(root)
  @config = config
  @framework = framework
  @ruby = ruby
  @target = parse_target(target, channel)
  @shell_dir = shell_dir
end

Instance Method Details

#manifestObject

The deterministic build request.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/everywhere/receipt.rb', line 35

def manifest
  {
    "app" => {
      "name" => @config.name,
      "bundle_id" => @config.bundle_id,
      "version" => @config.version
    },
    "framework" => framework_info,
    "ruby" => @ruby,
    "versions" => versions,
    "source" => {
      "checksum" => source_checksum,
      "lockfile_checksum" => lockfile_checksum
    },
    "target" => @target,
    "permissions" => @config.permissions
  }
end

#manifest_checksumObject

sha256 over the canonical (sorted-key) JSON of the manifest. Ties a receipt to the exact request that produced it.



56
57
58
# File 'lib/everywhere/receipt.rb', line 56

def manifest_checksum
  "sha256:#{Digest::SHA256.hexdigest(canonical_json(manifest))}"
end

#to_h(artifact:, signing:, build_id: nil, logs_url: nil) ⇒ Object

The full receipt: manifest + artifact record. signing is the generic block from the spec — common fields + a platform-specific bag.



62
63
64
65
66
67
68
69
70
71
# File 'lib/everywhere/receipt.rb', line 62

def to_h(artifact:, signing:, build_id: nil, logs_url: nil)
  {
    "schema" => SCHEMA,
    "build_id" => build_id,
    "manifest_checksum" => manifest_checksum
  }.merge(manifest).merge(
    "artifact" => artifact_record(artifact).merge("signing" => signing),
    "logs_url" => logs_url
  )
end

#write(path, **kwargs) ⇒ Object



73
74
75
76
# File 'lib/everywhere/receipt.rb', line 73

def write(path, **kwargs)
  File.write(path, "#{JSON.pretty_generate(to_h(**kwargs))}\n")
  path
end