add_eso_version.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env bash
  2. # Script to add a new ESO version to the stability-support.md file
  3. # Usage: ./add_eso_version.sh <ESO_VERSION>
  4. # Set ROOT to the repository root (two levels up from this script)
  5. ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
  6. # Check if all required arguments are provided
  7. if [ $# -ne 1 ]; then
  8. echo "Usage: $0 <ESO_VERSION>"
  9. echo "Example: $0 '0.17.x'"
  10. exit 1
  11. fi
  12. # Assign parameters to variables
  13. ESO_VERSION="$1"
  14. K8S_VERSION="$(echo 1.$(cat "${ROOT}"/go.mod | grep 'k8s.io/client-go' | cut -d'v' -f2 | cut -d'.' -f2))"
  15. RELEASE_DATE=$(date +%B\ %d,\ %Y)
  16. # Path to the stability-support.md file
  17. FILE_PATH="$ROOT/docs/introduction/stability-support.md"
  18. # Check if the file exists
  19. if [ ! -f "$FILE_PATH" ]; then
  20. echo "Error: File $FILE_PATH does not exist."
  21. exit 1
  22. fi
  23. echo "Checking for version: $ESO_VERSION"
  24. current=$(cat "${ROOT}"/docs/introduction/stability-support.md | grep "$ESO_VERSION") || true
  25. if [[ "${current}" != "" ]]; then
  26. echo "Version already exists. Nothing to do"
  27. exit 0
  28. fi
  29. # Set End of Life to "Release of next version"
  30. END_OF_LIFE="Release of $(echo "${ESO_VERSION}" | awk -F. '{print $1"."$2+1}')"
  31. # Create the new line to insert
  32. NEW_LINE="| $ESO_VERSION | $K8S_VERSION | $RELEASE_DATE | $END_OF_LIFE |"
  33. # Create a temporary file
  34. TEMP_FILE=$(mktemp)
  35. # Process the file with awk to:
  36. # 1. Add the new version after the table header
  37. # 2. Keep the previous version's release date intact
  38. # 3. Update only the End of Life date for the previous version
  39. awk -v new_line="$NEW_LINE" -v release_date="$RELEASE_DATE" '
  40. BEGIN {
  41. found_table = 0;
  42. added_new_line = 0;
  43. in_eso_table = 0;
  44. updated_first_version = 0;
  45. }
  46. # Match the ESO Version table specifically (to avoid affecting other tables)
  47. /\| ESO Version \| Kubernetes Version \| Release Date[[:space:]]+\| End of Life/ {
  48. in_eso_table = 1;
  49. found_table = 1;
  50. print $0;
  51. next;
  52. }
  53. # Match the separator line (dashes) only in the ESO Version table
  54. in_eso_table == 1 && /\| -+/ {
  55. print $0;
  56. print new_line;
  57. added_new_line = 1;
  58. next;
  59. }
  60. # For the first version line after we added our new line, update only the End of Life
  61. added_new_line == 1 && in_eso_table == 1 && /\|.*\|.*\|.*\|/ && !updated_first_version {
  62. # Split the line by | and reconstruct with new End of Life (which should be the release date of the new version)
  63. split($0, fields, "|");
  64. # fields[1] is empty, fields[2] is version, fields[3] is k8s version, fields[4] is release date
  65. # Trim whitespace and format properly
  66. gsub(/^ +| +$/, "", fields[2]);
  67. gsub(/^ +| +$/, "", fields[3]);
  68. gsub(/^ +| +$/, "", fields[4]);
  69. printf "| %-10s | %-18s | %-14s | %s |\n", fields[2], fields[3], fields[4], release_date;
  70. updated_first_version = 1;
  71. next;
  72. }
  73. # Detect when we leave the ESO Version table (blank line or start of new section)
  74. in_eso_table == 1 && (/^$/ || /^##/) {
  75. in_eso_table = 0;
  76. }
  77. # Print all other lines unchanged
  78. { print $0; }
  79. ' "$FILE_PATH" > "$TEMP_FILE"
  80. # Replace the original file with the temporary file
  81. mv "$TEMP_FILE" "$FILE_PATH"
  82. echo "Successfully added ESO version $ESO_VERSION to $FILE_PATH"
  83. echo "New line: $NEW_LINE"
  84. echo "Updated previous version's End of Life to: $RELEASE_DATE"