main.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "os"
  7. )
  8. func main() {
  9. var version string
  10. var whatsNewURL string
  11. var releaseNotesURL string
  12. var dryRun bool
  13. var enterprise bool
  14. var fromLocal bool
  15. var nightly bool
  16. var apiKey string
  17. flag.StringVar(&version, "version", "", "Grafana version (ex: --version v5.2.0-beta1)")
  18. flag.StringVar(&whatsNewURL, "wn", "", "What's new url (ex: --wn http://docs.grafana.org/guides/whats-new-in-v5-2/)")
  19. flag.StringVar(&releaseNotesURL, "rn", "", "Grafana version (ex: --rn https://community.grafana.com/t/release-notes-v5-2-x/7894)")
  20. flag.StringVar(&apiKey, "apikey", "", "Grafana.com API key (ex: --apikey ABCDEF)")
  21. flag.BoolVar(&dryRun, "dry-run", false, "--dry-run")
  22. flag.BoolVar(&enterprise, "enterprise", false, "--enterprise")
  23. flag.BoolVar(&fromLocal, "from-local", false, "--from-local (builds will be tagged as nightly)")
  24. flag.Parse()
  25. nightly = fromLocal
  26. if len(os.Args) == 1 {
  27. fmt.Println("Usage: go run publisher.go main.go --version <v> --wn <what's new url> --rn <release notes url> --apikey <api key> --dry-run false --enterprise false --nightly false")
  28. fmt.Println("example: go run publisher.go main.go --version v5.2.0-beta2 --wn http://docs.grafana.org/guides/whats-new-in-v5-2/ --rn https://community.grafana.com/t/release-notes-v5-2-x/7894 --apikey ASDF123 --dry-run --enterprise")
  29. os.Exit(1)
  30. }
  31. if dryRun {
  32. log.Println("Dry-run has been enabled.")
  33. }
  34. var baseURL string
  35. var builder releaseBuilder
  36. var product string
  37. archiveProviderRoot := "https://dl.grafana.com"
  38. buildArtifacts := completeBuildArtifactConfigurations
  39. if enterprise {
  40. product = "grafana-enterprise"
  41. baseURL = createBaseURL(archiveProviderRoot, "enterprise", product, nightly)
  42. var err error
  43. buildArtifacts, err = filterBuildArtifacts([]artifactFilter{
  44. {os: "deb", arch: "amd64"},
  45. {os: "rhel", arch: "amd64"},
  46. {os: "linux", arch: "amd64"},
  47. {os: "win", arch: "amd64"},
  48. })
  49. if err != nil {
  50. log.Fatalf("Could not filter to the selected build artifacts, err=%v", err)
  51. }
  52. } else {
  53. product = "grafana"
  54. baseURL = createBaseURL(archiveProviderRoot, "oss", product, nightly)
  55. }
  56. if fromLocal {
  57. path, _ := os.Getwd()
  58. builder = releaseLocalSources{
  59. path: path,
  60. artifactConfigurations: buildArtifacts,
  61. }
  62. } else {
  63. builder = releaseFromExternalContent{
  64. getter: getHTTPContents{},
  65. rawVersion: version,
  66. artifactConfigurations: buildArtifacts,
  67. }
  68. }
  69. p := publisher{
  70. apiKey: apiKey,
  71. apiURI: "https://grafana.com/api",
  72. product: product,
  73. dryRun: dryRun,
  74. enterprise: enterprise,
  75. baseArchiveURL: baseURL,
  76. builder: builder,
  77. }
  78. if err := p.doRelease(whatsNewURL, releaseNotesURL, nightly); err != nil {
  79. log.Fatalf("error: %v", err)
  80. }
  81. }
  82. func createBaseURL(root string, bucketName string, product string, nightly bool) string {
  83. var subPath string
  84. if nightly {
  85. subPath = "master"
  86. } else {
  87. subPath = "release"
  88. }
  89. return fmt.Sprintf("%s/%s/%s/%s", root, bucketName, subPath, product)
  90. }