main.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package main
  2. import (
  3. "log"
  4. "os"
  5. "path/filepath"
  6. condaenvupdate "github.com/paketo-buildpacks/conda-env-update"
  7. gomodvendor "github.com/paketo-buildpacks/go-mod-vendor"
  8. npminstall "github.com/paketo-buildpacks/npm-install"
  9. "github.com/paketo-buildpacks/packit"
  10. pipenvinstall "github.com/paketo-buildpacks/pipenv-install"
  11. pythonstart "github.com/paketo-buildpacks/python-start"
  12. yarninstall "github.com/paketo-buildpacks/yarn-install"
  13. )
  14. const GoModLocation = "go.mod"
  15. var workingDir string
  16. func detectGo() {
  17. /* First check if it is a go.mod project */
  18. goModParser := gomodvendor.NewGoModParser()
  19. detect := gomodvendor.Detect(goModParser)
  20. _, err := detect(packit.DetectContext{
  21. WorkingDir: workingDir,
  22. })
  23. if err == nil {
  24. log.Println("go.mod project detected")
  25. return
  26. }
  27. /* Next, check if it is a Gopkg.toml */
  28. _, err = os.Stat(filepath.Join(workingDir, "Gopkg.toml"))
  29. if err == nil {
  30. log.Println("Gopkg.toml project detected")
  31. return
  32. }
  33. /* Finally, check if it is a Go vendor */
  34. _, err = os.Stat(filepath.Join(workingDir, "vendor"))
  35. if err == nil {
  36. log.Println("Go vendor project detected")
  37. return
  38. }
  39. // FIXME: what about Go projects that do not use any of the
  40. // above but contain a Makefile to call 'go build'
  41. /* Not a Go project */
  42. log.Println("Not a Go project")
  43. }
  44. func detectPython() {
  45. /* Check for Pipfile project */
  46. pipfileParser := pipenvinstall.NewPipfileParser()
  47. pipfileLockParser := pipenvinstall.NewPipfileLockParser()
  48. detect := pipenvinstall.Detect(pipfileParser, pipfileLockParser)
  49. _, err := detect(packit.DetectContext{
  50. WorkingDir: workingDir,
  51. })
  52. if err == nil {
  53. log.Println("Python Pipfile project detected")
  54. return
  55. }
  56. /* Check for pip project */
  57. _, err = os.Stat(filepath.Join(workingDir, "requirements.txt"))
  58. if err == nil {
  59. log.Println("Python pip project detected")
  60. return
  61. }
  62. /* Check for conda project */
  63. detect = condaenvupdate.Detect()
  64. _, err = detect(packit.DetectContext{
  65. WorkingDir: workingDir,
  66. })
  67. if err == nil {
  68. log.Println("Python conda project detected")
  69. return
  70. }
  71. /* Check for all other possibilities of a Python project */
  72. detect = pythonstart.Detect()
  73. _, err = detect(packit.DetectContext{
  74. WorkingDir: workingDir,
  75. })
  76. if err == nil {
  77. log.Println("Python project detected")
  78. return
  79. }
  80. /* Not a Python project */
  81. log.Println("Not a Python project")
  82. }
  83. func detectNode() {
  84. /* Check for yarn project */
  85. yarnProjectPathParser := yarninstall.NewProjectPathParser()
  86. yarnVersionParser := yarninstall.NewPackageJSONParser()
  87. detect := yarninstall.Detect(yarnProjectPathParser, yarnVersionParser)
  88. _, err := detect(packit.DetectContext{
  89. WorkingDir: workingDir,
  90. })
  91. if err == nil {
  92. log.Println("Node yarn project detected")
  93. return
  94. }
  95. /* Check for npm project */
  96. npmProjectPathParser := npminstall.NewProjectPathParser()
  97. npmVersionParser := npminstall.NewPackageJSONParser()
  98. detect = npminstall.Detect(npmProjectPathParser, npmVersionParser)
  99. _, err = detect(packit.DetectContext{
  100. WorkingDir: workingDir,
  101. })
  102. if err == nil {
  103. log.Println("Node npm project detected")
  104. return
  105. }
  106. /* Not a Node project */
  107. log.Println("Not a Node project")
  108. }
  109. func detectRuby() {
  110. /* Not a Ruby project */
  111. log.Println("Not a Ruby project")
  112. }
  113. func main() {
  114. if len(os.Args) < 2 {
  115. log.Fatalln("Usage: ./test-runtime <project directory>")
  116. }
  117. workingDir = os.Args[1]
  118. detectGo()
  119. detectPython()
  120. detectNode()
  121. detectRuby()
  122. }