Merge pull request #14324 from Rylan12/flight-blocks-cask-api
Include `*flight` block source in cask API
This commit is contained in:
commit
a81710542f
@ -15,6 +15,7 @@ end
|
|||||||
gem "bootsnap", require: false
|
gem "bootsnap", require: false
|
||||||
gem "byebug", require: false
|
gem "byebug", require: false
|
||||||
gem "json_schemer", require: false
|
gem "json_schemer", require: false
|
||||||
|
gem "method_source", require: false
|
||||||
gem "minitest", require: false
|
gem "minitest", require: false
|
||||||
gem "parallel_tests", require: false
|
gem "parallel_tests", require: false
|
||||||
gem "ronn", require: false
|
gem "ronn", require: false
|
||||||
|
|||||||
@ -233,6 +233,7 @@ DEPENDENCIES
|
|||||||
did_you_mean
|
did_you_mean
|
||||||
json_schemer
|
json_schemer
|
||||||
mechanize
|
mechanize
|
||||||
|
method_source
|
||||||
minitest
|
minitest
|
||||||
parallel_tests
|
parallel_tests
|
||||||
parlour
|
parlour
|
||||||
|
|||||||
@ -36,6 +36,12 @@ module Cask
|
|||||||
directives.keys.map(&:to_s).join(", ")
|
directives.keys.map(&:to_s).join(", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_h
|
||||||
|
require "method_source"
|
||||||
|
|
||||||
|
directives.transform_values(&:source)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def class_for_dsl_key(dsl_key)
|
def class_for_dsl_key(dsl_key)
|
||||||
|
|||||||
@ -288,13 +288,9 @@ module Cask
|
|||||||
|
|
||||||
def artifacts_list
|
def artifacts_list
|
||||||
artifacts.map do |artifact|
|
artifacts.map do |artifact|
|
||||||
key, value = if artifact.is_a? Artifact::AbstractFlightBlock
|
next artifact.to_h if artifact.is_a? Artifact::AbstractFlightBlock
|
||||||
artifact.summarize
|
|
||||||
else
|
|
||||||
[artifact.class.dsl_key, to_h_gsubs(artifact.to_args)]
|
|
||||||
end
|
|
||||||
|
|
||||||
{ key => value }
|
{ artifact.class.dsl_key => to_h_gsubs(artifact.to_args) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -265,6 +265,46 @@ describe Cask::Cask, :cask do
|
|||||||
}
|
}
|
||||||
JSON
|
JSON
|
||||||
}
|
}
|
||||||
|
let(:expected_flight_variations) {
|
||||||
|
<<~JSON
|
||||||
|
{
|
||||||
|
"arm64_big_sur": {
|
||||||
|
"artifacts": [
|
||||||
|
{
|
||||||
|
"preflight": " preflight do\\n puts \\"preflight on Big Sur\\"\\n end\\n"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uninstall_postflight": " uninstall_postflight do\\n puts \\"uninstall_postflight on Big Sur\\"\\n end\\n"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"big_sur": {
|
||||||
|
"artifacts": [
|
||||||
|
{
|
||||||
|
"preflight": " preflight do\\n puts \\"preflight on Big Sur\\"\\n end\\n"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uninstall_postflight": " uninstall_postflight do\\n puts \\"uninstall_postflight on Big Sur\\"\\n end\\n"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"catalina": {
|
||||||
|
"artifacts": [
|
||||||
|
{
|
||||||
|
"preflight": " preflight do\\n puts \\"preflight on Catalina or older\\"\\n end\\n"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"mojave": {
|
||||||
|
"artifacts": [
|
||||||
|
{
|
||||||
|
"preflight": " preflight do\\n puts \\"preflight on Catalina or older\\"\\n end\\n"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JSON
|
||||||
|
}
|
||||||
|
|
||||||
before do
|
before do
|
||||||
# Use a more limited symbols list to shorten the variations hash
|
# Use a more limited symbols list to shorten the variations hash
|
||||||
@ -300,5 +340,13 @@ describe Cask::Cask, :cask do
|
|||||||
expect(h).to be_a(Hash)
|
expect(h).to be_a(Hash)
|
||||||
expect(JSON.pretty_generate(h["variations"])).to eq expected_sha256_variations.strip
|
expect(JSON.pretty_generate(h["variations"])).to eq expected_sha256_variations.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns the correct variations hash for a cask with conditional flight blocks" do
|
||||||
|
c = Cask::CaskLoader.load("conditional-flight")
|
||||||
|
h = c.to_hash_with_variations
|
||||||
|
|
||||||
|
expect(h).to be_a(Hash)
|
||||||
|
expect(JSON.pretty_generate(h["variations"])).to eq expected_flight_variations.strip
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -0,0 +1,21 @@
|
|||||||
|
cask "conditional-flight" do
|
||||||
|
version "1.2.3"
|
||||||
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
|
|
||||||
|
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine/#{platform}/#{version}/#{arch}.zip"
|
||||||
|
homepage "https://brew.sh/"
|
||||||
|
|
||||||
|
on_big_sur do
|
||||||
|
preflight do
|
||||||
|
puts "preflight on Big Sur"
|
||||||
|
end
|
||||||
|
uninstall_postflight do
|
||||||
|
puts "uninstall_postflight on Big Sur"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
on_catalina :or_older do
|
||||||
|
preflight do
|
||||||
|
puts "preflight on Catalina or older"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user