dev-cmd/generate-*-api: be a bit safer.

- also try generating formula API on macOS
- pull more logic out of `unless args.dry_run?` in case it fails
This commit is contained in:
Mike McQuaid 2023-07-18 12:37:32 +01:00
parent 6b012b6592
commit e1a7afb3cf
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829
3 changed files with 14 additions and 6 deletions

View File

@ -167,7 +167,7 @@ jobs:
id: set-up-homebrew id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master uses: Homebrew/actions/setup-homebrew@master
with: with:
core: false core: true
cask: true cask: true
test-bot: false test-bot: false
@ -195,6 +195,9 @@ jobs:
brew audit --skip-style --except=version --tap=homebrew/cask-fonts brew audit --skip-style --except=version --tap=homebrew/cask-fonts
brew audit --skip-style --except=version --tap=homebrew/cask-versions brew audit --skip-style --except=version --tap=homebrew/cask-versions
- name: Generate formula API
run: brew generate-formula-api --dry-run
- name: Generate cask API - name: Generate cask API
run: brew generate-cask-api --dry-run run: brew generate-cask-api --dry-run

View File

@ -52,7 +52,8 @@ module Homebrew
end end
Homebrew.with_no_api_env do Homebrew.with_no_api_env do
File.write("api/cask_tap_migrations.json", JSON.dump(tap.tap_migrations)) unless args.dry_run? tap_migrations_json = JSON.dump(tap.tap_migrations)
File.write("api/cask_tap_migrations.json", tap_migrations_json) unless args.dry_run?
Cask::Cask.generating_hash! Cask::Cask.generating_hash!
@ -60,12 +61,14 @@ module Homebrew
cask = Cask::CaskLoader.load(path) cask = Cask::CaskLoader.load(path)
name = cask.token name = cask.token
json = JSON.pretty_generate(cask.to_hash_with_variations) json = JSON.pretty_generate(cask.to_hash_with_variations)
cask_source = path.read
html_template_name = html_template(name)
unless args.dry_run? unless args.dry_run?
File.write("_data/cask/#{name}.json", "#{json}\n") File.write("_data/cask/#{name}.json", "#{json}\n")
File.write("api/cask/#{name}.json", CASK_JSON_TEMPLATE) File.write("api/cask/#{name}.json", CASK_JSON_TEMPLATE)
File.write("api/cask-source/#{name}.rb", path.read) File.write("api/cask-source/#{name}.rb", cask_source)
File.write("cask/#{name}.html", html_template(name)) File.write("cask/#{name}.html", html_template_name)
end end
rescue rescue
onoe "Error while generating data for cask '#{path.stem}'." onoe "Error while generating data for cask '#{path.stem}'."

View File

@ -53,7 +53,8 @@ module Homebrew
end end
Homebrew.with_no_api_env do Homebrew.with_no_api_env do
File.write("api/formula_tap_migrations.json", JSON.dump(tap.tap_migrations)) unless args.dry_run? tap_migrations_json = JSON.dump(tap.tap_migrations)
File.write("api/formula_tap_migrations.json", tap_migrations_json) unless args.dry_run?
Formulary.enable_factory_cache! Formulary.enable_factory_cache!
Formula.generating_hash! Formula.generating_hash!
@ -62,11 +63,12 @@ module Homebrew
formula = Formulary.factory(name) formula = Formulary.factory(name)
name = formula.name name = formula.name
json = JSON.pretty_generate(formula.to_hash_with_variations) json = JSON.pretty_generate(formula.to_hash_with_variations)
html_template_name = html_template(name)
unless args.dry_run? unless args.dry_run?
File.write("_data/formula/#{name.tr("+", "_")}.json", "#{json}\n") File.write("_data/formula/#{name.tr("+", "_")}.json", "#{json}\n")
File.write("api/formula/#{name}.json", FORMULA_JSON_TEMPLATE) File.write("api/formula/#{name}.json", FORMULA_JSON_TEMPLATE)
File.write("formula/#{name}.html", html_template(name)) File.write("formula/#{name}.html", html_template_name)
end end
rescue rescue
onoe "Error while generating data for formula '#{name}'." onoe "Error while generating data for formula '#{name}'."