main.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. if fromLocal {
  38. path, _ := os.Getwd()
  39. builder = releaseLocalSources{
  40. path: path,
  41. artifactConfigurations: buildArtifactConfigurations,
  42. }
  43. } else {
  44. builder = releaseFromExternalContent{
  45. getter: getHttpContents{},
  46. rawVersion: version,
  47. artifactConfigurations: buildArtifactConfigurations,
  48. }
  49. }
  50. archiveProviderRoot := "https://s3-us-west-2.amazonaws.com"
  51. if enterprise {
  52. product = "grafana-enterprise"
  53. baseUrl = createBaseUrl(archiveProviderRoot, "grafana-enterprise-releases", product, nightly)
  54. } else {
  55. product = "grafana"
  56. baseUrl = createBaseUrl(archiveProviderRoot, "grafana-releases", product, nightly)
  57. }
  58. p := publisher{
  59. apiKey: apiKey,
  60. apiUri: "https://grafana.com/api",
  61. product: product,
  62. dryRun: dryRun,
  63. enterprise: enterprise,
  64. baseArchiveUrl: baseUrl,
  65. builder: builder,
  66. }
  67. if err := p.doRelease(whatsNewUrl, releaseNotesUrl, nightly); err != nil {
  68. log.Fatalf("error: %v", err)
  69. }
  70. }
  71. func createBaseUrl(root string, bucketName string, product string, nightly bool) string {
  72. var subPath string
  73. if nightly {
  74. subPath = "master"
  75. } else {
  76. subPath = "release"
  77. }
  78. return fmt.Sprintf("%s/%s/%s/%s", root, bucketName, subPath, product)
  79. }