Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
MikeMcQuaid marked this conversation as resolved.
Show resolved Hide resolved

- 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 @@
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)

Check warning on line 55 in Library/Homebrew/dev-cmd/generate-cask-api.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/generate-cask-api.rb#L55

Added line #L55 was not covered by tests
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)

Check warning on line 65 in Library/Homebrew/dev-cmd/generate-cask-api.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/generate-cask-api.rb#L64-L65

Added lines #L64 - L65 were not covered by tests

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)

Check warning on line 71 in Library/Homebrew/dev-cmd/generate-cask-api.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/generate-cask-api.rb#L70-L71

Added lines #L70 - L71 were not covered by tests
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 @@
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)

Check warning on line 56 in Library/Homebrew/dev-cmd/generate-formula-api.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/generate-formula-api.rb#L56

Added line #L56 was not covered by tests
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 @@
formula = Formulary.factory(name)
name = formula.name
json = JSON.pretty_generate(formula.to_hash_with_variations)
html_template_name = html_template(name)

Check warning on line 66 in Library/Homebrew/dev-cmd/generate-formula-api.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/generate-formula-api.rb#L66

Added line #L66 was not covered by tests

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)

Check warning on line 71 in Library/Homebrew/dev-cmd/generate-formula-api.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/generate-formula-api.rb#L71

Added line #L71 was not covered by tests
end
rescue
onoe "Error while generating data for formula '#{name}'."
Expand Down