Skip to content

Commit

Permalink
Merge pull request #15704 from MikeMcQuaid/generate_api_safer
Browse files Browse the repository at this point in the history
dev-cmd/generate-*-api: be a bit safer.
  • Loading branch information
MikeMcQuaid committed Jul 18, 2023
2 parents 73b40bc + e1a7afb commit 4017034
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ jobs:
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
with:
core: false
core: true
cask: true
test-bot: false

Expand Down Expand Up @@ -195,6 +195,9 @@ jobs:
brew audit --skip-style --except=version --tap=homebrew/cask-fonts
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
run: brew generate-cask-api --dry-run

Expand Down
9 changes: 6 additions & 3 deletions Library/Homebrew/dev-cmd/generate-cask-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,23 @@ def generate_cask_api
end

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!

tap.cask_files.each do |path|
cask = Cask::CaskLoader.load(path)
name = cask.token
json = JSON.pretty_generate(cask.to_hash_with_variations)
cask_source = path.read
html_template_name = html_template(name)

unless args.dry_run?
File.write("_data/cask/#{name}.json", "#{json}\n")
File.write("api/cask/#{name}.json", CASK_JSON_TEMPLATE)
File.write("api/cask-source/#{name}.rb", path.read)
File.write("cask/#{name}.html", html_template(name))
File.write("api/cask-source/#{name}.rb", cask_source)
File.write("cask/#{name}.html", html_template_name)
end
rescue
onoe "Error while generating data for cask '#{path.stem}'."
Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/dev-cmd/generate-formula-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def generate_formula_api
end

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!
Formula.generating_hash!
Expand All @@ -62,11 +63,12 @@ def generate_formula_api
formula = Formulary.factory(name)
name = formula.name
json = JSON.pretty_generate(formula.to_hash_with_variations)
html_template_name = html_template(name)

unless args.dry_run?
File.write("_data/formula/#{name.tr("+", "_")}.json", "#{json}\n")
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
rescue
onoe "Error while generating data for formula '#{name}'."
Expand Down

0 comments on commit 4017034

Please sign in to comment.