Allow using environment variables for project url and commit.

main
Joshua Potter 2023-12-15 14:41:28 -07:00
parent d2db077fc4
commit c29c914910
1 changed files with 24 additions and 18 deletions

View File

@ -48,28 +48,34 @@ def getGithubBaseUrl (gitUrl : String) : String := Id.run do
/-- /--
Obtain the Github URL of a project by parsing the origin remote. Obtain the Github URL of a project by parsing the origin remote.
-/ -/
def getProjectGithubUrl (directory : System.FilePath := "." ) : IO String := do def getProjectGithubUrl (directory : System.FilePath := ".") : IO String := do
let out ← IO.Process.output { match (<- IO.getEnv "GIT_ORIGIN_URL") with
cmd := "git", | some url => return url
args := #["remote", "get-url", "origin"], | none =>
cwd := directory let out ← IO.Process.output {
} cmd := "git",
if out.exitCode != 0 then args := #["remote", "get-url", "origin"],
throw <| IO.userError <| s!"git exited with code {out.exitCode} while looking for the git remote in {directory}" cwd := directory
return out.stdout.trimRight }
if out.exitCode != 0 then
throw <| IO.userError <| s!"git exited with code {out.exitCode} while looking for the git remote in {directory}"
return out.stdout.trimRight
/-- /--
Obtain the git commit hash of the project that is currently getting analyzed. Obtain the git commit hash of the project that is currently getting analyzed.
-/ -/
def getProjectCommit (directory : System.FilePath := "." ) : IO String := do def getProjectCommit (directory : System.FilePath := ".") : IO String := do
let out ← IO.Process.output { match (<- IO.getEnv "GIT_REVISION") with
cmd := "git", | some rev => return rev
args := #["rev-parse", "HEAD"] | none =>
cwd := directory let out ← IO.Process.output {
} cmd := "git",
if out.exitCode != 0 then args := #["rev-parse", "HEAD"]
throw <| IO.userError <| s!"git exited with code {out.exitCode} while looking for the current commit in {directory}" cwd := directory
return out.stdout.trimRight }
if out.exitCode != 0 then
throw <| IO.userError <| s!"git exited with code {out.exitCode} while looking for the current commit in {directory}"
return out.stdout.trimRight
def getGitUrl (pkg : Package) (lib : LeanLibConfig) (mod : Module) : IO String := do def getGitUrl (pkg : Package) (lib : LeanLibConfig) (mod : Module) : IO String := do
let baseUrl := getGithubBaseUrl (← getProjectGithubUrl pkg.dir) let baseUrl := getGithubBaseUrl (← getProjectGithubUrl pkg.dir)