Skip to content

Commit

Permalink
Extract version from version string after app config
Browse files Browse the repository at this point in the history
Closes #318
  • Loading branch information
maltoe committed Jul 29, 2024
1 parent 2f1d923 commit 3c0bd4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

### Fixed

- Small fix `:chrome_version` config switch allowing to pass `Chrome x.y.z.zz` instead of just `x.y.z.zz`

## [1.16.1] - 2024-07-25

### Added
Expand Down
15 changes: 10 additions & 5 deletions lib/chromic_pdf/pdf/chrome_runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ defmodule ChromicPDF.ChromeRunner do

@spec version() :: binary()
def version do
with_app_config_cache(:chrome_version, &do_version/0)
:chrome_version
|> with_app_config_cache(&get_version_from_chrome/0)
|> extract_version()
end

defp do_version do
output = system_cmd!(executable(), ["--version"], stderr_to_stdout: true)
[version] = Regex.run(~r/\d+\.\d+\.\d+\.\d+/, output)
version
defp get_version_from_chrome do
system_cmd!(executable(), ["--version"], stderr_to_stdout: true)
rescue
e ->
reraise(
Expand All @@ -57,6 +57,11 @@ defmodule ChromicPDF.ChromeRunner do
)
end

defp extract_version(value) do
[version] = Regex.run(~r/\d+\.\d+\.\d+\.\d+/, value)
version
end

# Public for unit tests.
@doc false
@spec shell_command(keyword()) :: binary()
Expand Down

0 comments on commit 3c0bd4f

Please sign in to comment.