Skip to content

Commit

Permalink
Print the rust version.
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Sep 15, 2024
1 parent 9d3d9f6 commit 5ba0de8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/godot-sandbox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ paths:
gccVersion:
type: string
example: "GCC 9.3.0"
rustVersion:
type: string
example: "rustc 1.58.0"
/cache/{hash}:
get:
tags:
Expand Down
17 changes: 14 additions & 3 deletions lib/web_compiler_web/controllers/version_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@ defmodule WebCompilerWeb.VersionController do
{gcc_version_output, 0} = System.cmd("gcc", ["--version"])
gcc_version = parse_gcc_version(gcc_version_output)

{rust_version_output, 0} = System.cmd("rustc", ["--version"])
rust_version = parse_rust_version(rust_version_output)

version_info = %{
apiVersion: "1.0.0",
gccVersion: gcc_version
gccVersion: gcc_version,
rustVersion: rust_version
}

json(conn, version_info)
end

defp parse_gcc_version(output) do
# Extract the version number from the first line of the output
# Extract and trim the version number from the first line of the output
[first_line | _] = String.split(output, "\n")
Regex.replace(~r/^gcc \(.*\) (\d+\.\d+\.\d+).*$/, first_line, "\\1")
version = Regex.replace(~r/^gcc \(.*\) (\d+\.\d+\.\d+).*$/, first_line, "\\1")
String.trim(version)
end

defp parse_rust_version(output) do
# Extract and trim the version number from the output
version = Regex.replace(~r/^rustc (\d+\.\d+\.\d+).*$/, output, "\\1")
String.trim(version)
end
end
1 change: 0 additions & 1 deletion test/support/conn_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ defmodule WebCompilerWeb.ConnCase do
end

setup tags do
WebCompiler.DataCase.setup_sandbox(tags)
{:ok, conn: Phoenix.ConnTest.build_conn()}
end
end
15 changes: 15 additions & 0 deletions test/web_compiler_version_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,19 @@ defmodule WebCompilerWeb.VersionControllerTest do
assert major_version >= 13
end
end

test "returns Rust version 1.83 or higher", %{conn: conn} do
conn = get(conn, "/version")
assert json_response(conn, 200)
version_data = json_response(conn, 200)
rust_version = version_data["rustVersion"]

version_struct = rust_version
|> Version.parse!()

major_version = version_struct.major
minor_version = version_struct.minor

assert major_version >= 1 and minor_version >= 83
end
end

0 comments on commit 5ba0de8

Please sign in to comment.