add_eso_version.sh 3.0 KB

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