unversioned_warning.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. Copyright 2015 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package main
  14. import (
  15. "fmt"
  16. "strings"
  17. )
  18. const unversionedWarningTag = "UNVERSIONED_WARNING"
  19. const unversionedWarningPre = `
  20. <!-- BEGIN STRIP_FOR_RELEASE -->
  21. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  22. width="25" height="25">
  23. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  24. width="25" height="25">
  25. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  26. width="25" height="25">
  27. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  28. width="25" height="25">
  29. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  30. width="25" height="25">
  31. <h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
  32. If you are using a released version of Kubernetes, you should
  33. refer to the docs that go with that version.`
  34. const unversionedWarningLink = `
  35. <!-- TAG RELEASE_LINK, added by the munger automatically -->
  36. <strong>
  37. The latest release of this document can be found
  38. [here](http://releases.k8s.io/%s/%s).`
  39. const unversionedWarningPost = `
  40. Documentation for other releases can be found at
  41. [releases.k8s.io](http://releases.k8s.io).
  42. </strong>
  43. --
  44. <!-- END STRIP_FOR_RELEASE -->
  45. `
  46. func makeUnversionedWarning(fileName string, linkToReleaseDoc bool) mungeLines {
  47. var insert string
  48. if linkToReleaseDoc {
  49. insert = unversionedWarningPre + fmt.Sprintf(unversionedWarningLink, latestReleaseBranch, fileName) + unversionedWarningPost
  50. } else {
  51. insert = unversionedWarningPre + unversionedWarningPost
  52. }
  53. return getMungeLines(insert)
  54. }
  55. // inserts/updates a warning for unversioned docs
  56. func updateUnversionedWarning(file string, mlines mungeLines) (mungeLines, error) {
  57. file, err := makeRepoRelative(file, file)
  58. if err != nil {
  59. return mlines, err
  60. }
  61. if hasLine(mlines, "<!-- TAG IS_VERSIONED -->") {
  62. // No warnings on release branches
  63. return mlines, nil
  64. }
  65. var linkToReleaseDoc bool
  66. checkDocExistence := inJenkins || (len(filesInLatestRelease) != 0)
  67. if checkDocExistence {
  68. linkToReleaseDoc = strings.Contains(filesInLatestRelease, file)
  69. } else {
  70. linkToReleaseDoc = hasLine(mlines, "<!-- TAG RELEASE_LINK, added by the munger automatically -->")
  71. }
  72. if !hasMacroBlock(mlines, unversionedWarningTag) {
  73. mlines = prependMacroBlock(unversionedWarningTag, mlines)
  74. }
  75. mlines, err = updateMacroBlock(mlines, unversionedWarningTag, makeUnversionedWarning(file, linkToReleaseDoc))
  76. if err != nil {
  77. return mlines, err
  78. }
  79. return mlines, nil
  80. }