|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +# This script automatically updates the release calendar in docs/install/releases/index.md |
| 6 | +# It calculates the releases based on the first Tuesday of each month rule |
| 7 | +# and updates the status of each release (Not Supported, Security Support, Stable, Mainline, Not Released) |
| 8 | + |
| 9 | +DOCS_FILE="docs/install/releases/index.md" |
| 10 | + |
| 11 | +# Define unique markdown comments as anchors |
| 12 | +CALENDAR_START_MARKER="<!-- RELEASE_CALENDAR_START -->" |
| 13 | +CALENDAR_END_MARKER="<!-- RELEASE_CALENDAR_END -->" |
| 14 | + |
| 15 | +# Get current date |
| 16 | +current_date=$(date +"%Y-%m-%d") |
| 17 | +current_month=$(date +"%m") |
| 18 | +current_year=$(date +"%Y") |
| 19 | + |
| 20 | +# Function to get the first Tuesday of a given month and year |
| 21 | +get_first_tuesday() { |
| 22 | +local year=$1 |
| 23 | +local month=$2 |
| 24 | +local first_day |
| 25 | +local days_until_tuesday |
| 26 | +local first_tuesday |
| 27 | + |
| 28 | +# Find the first day of the month |
| 29 | +first_day=$(date -d"$year-$month-01" +"%u") |
| 30 | + |
| 31 | +# Calculate days until first Tuesday (if day 1 is Tuesday, first_day=2) |
| 32 | +days_until_tuesday=$((first_day==2?0: (9- first_day)%7)) |
| 33 | + |
| 34 | +# Get the date of the first Tuesday |
| 35 | +first_tuesday=$(date -d"$year-$month-01 +$days_until_tuesday days" +"%Y-%m-%d") |
| 36 | + |
| 37 | +echo"$first_tuesday" |
| 38 | +} |
| 39 | + |
| 40 | +# Function to format date as "Month DD, YYYY" |
| 41 | +format_date() { |
| 42 | +date -d"$1" +"%B %d, %Y" |
| 43 | +} |
| 44 | + |
| 45 | +# Function to get the latest patch version for a minor release |
| 46 | +get_latest_patch() { |
| 47 | +local version_major=$1 |
| 48 | +local version_minor=$2 |
| 49 | +local tags |
| 50 | +local latest |
| 51 | + |
| 52 | +# Get all tags for this minor version |
| 53 | +tags=$(cd"$(git rev-parse --show-toplevel)"&& git tag| grep"^v$version_major\\.$version_minor\\."| sort -V) |
| 54 | + |
| 55 | +# Get the latest one |
| 56 | +latest=$(echo"$tags"| tail -1) |
| 57 | + |
| 58 | +if [-z"$latest" ];then |
| 59 | +# If no tags found, return empty |
| 60 | +echo"" |
| 61 | +else |
| 62 | +# Return without the v prefix |
| 63 | +echo"${latest#v}" |
| 64 | +fi |
| 65 | +} |
| 66 | + |
| 67 | +# Generate releases table showing: |
| 68 | +# - 3 previous unsupported releases |
| 69 | +# - 1 security support release (n-2) |
| 70 | +# - 1 stable release (n-1) |
| 71 | +# - 1 mainline release (n) |
| 72 | +# - 1 next release (n+1) |
| 73 | +generate_release_calendar() { |
| 74 | +local result="" |
| 75 | +local version_major=2 |
| 76 | +local latest_version |
| 77 | +local version_minor |
| 78 | +local start_minor |
| 79 | + |
| 80 | +# Find the current minor version by looking at the last mainline release tag |
| 81 | +latest_version=$(cd"$(git rev-parse --show-toplevel)"&& git tag| grep'^v[0-9]*\.[0-9]*\.[0-9]*$'| sort -V| tail -1) |
| 82 | +version_minor=$(echo"$latest_version"| cut -d. -f2) |
| 83 | + |
| 84 | +# Start with 3 unsupported releases back |
| 85 | +start_minor=$((version_minor-5)) |
| 86 | + |
| 87 | +# Initialize the calendar table with an additional column for latest release |
| 88 | +result="| Release name | Release Date | Status | Latest Release |\n" |
| 89 | +result+="|--------------|--------------|--------|----------------|\n" |
| 90 | + |
| 91 | +# Generate rows for each release (7 total: 3 unsupported, 1 security, 1 stable, 1 mainline, 1 next) |
| 92 | +foriin {0..6};do |
| 93 | +# Calculate release minor version |
| 94 | +local rel_minor=$((start_minor+ i)) |
| 95 | +# Format release name without the .x |
| 96 | +local version_name="$version_major.$rel_minor" |
| 97 | +local release_date |
| 98 | +local formatted_date |
| 99 | +local latest_patch |
| 100 | +local patch_link |
| 101 | +local status |
| 102 | +local formatted_version_name |
| 103 | + |
| 104 | +# Calculate release month and year based on release pattern |
| 105 | +# This is a simplified calculation assuming monthly releases |
| 106 | +local rel_month=$(((current_month- (5- i)+12)%12)) |
| 107 | +[[$rel_month-eq 0 ]]&& rel_month=12 |
| 108 | +local rel_year=$current_year |
| 109 | +if [[$rel_month-gt$current_month ]];then |
| 110 | +rel_year=$((rel_year-1)) |
| 111 | +fi |
| 112 | +if [[$rel_month-lt$current_month&&$i-gt 5 ]];then |
| 113 | +rel_year=$((rel_year+1)) |
| 114 | +fi |
| 115 | + |
| 116 | +# Skip January releases starting from 2025 |
| 117 | +if [[$rel_month-eq 1&&$rel_year-ge 2025 ]];then |
| 118 | +rel_month=2 |
| 119 | +# No need to reassign rel_year to itself |
| 120 | +fi |
| 121 | + |
| 122 | +# Get release date (first Tuesday of the month) |
| 123 | +release_date=$(get_first_tuesday"$rel_year""$(printf"%02d""$rel_month")") |
| 124 | +formatted_date=$(format_date"$release_date") |
| 125 | + |
| 126 | +# Get latest patch version |
| 127 | +latest_patch=$(get_latest_patch"$version_major""$rel_minor") |
| 128 | +if [-n"$latest_patch" ];then |
| 129 | +patch_link="[v${latest_patch}](https://github.com/coder/coder/releases/tag/v${latest_patch})" |
| 130 | +else |
| 131 | +patch_link="N/A" |
| 132 | +fi |
| 133 | + |
| 134 | +# Determine status |
| 135 | +if [["$release_date">"$current_date" ]];then |
| 136 | +status="Not Released" |
| 137 | +elif [[$i-eq 6 ]];then |
| 138 | +status="Not Released" |
| 139 | +elif [[$i-eq 5 ]];then |
| 140 | +status="Mainline" |
| 141 | +elif [[$i-eq 4 ]];then |
| 142 | +status="Stable" |
| 143 | +elif [[$i-eq 3 ]];then |
| 144 | +status="Security Support" |
| 145 | +else |
| 146 | +status="Not Supported" |
| 147 | +fi |
| 148 | + |
| 149 | +# Format version name and patch link based on release status |
| 150 | +# No links for unreleased versions |
| 151 | +if [["$status"=="Not Released" ]];then |
| 152 | +formatted_version_name="$version_name" |
| 153 | +patch_link="N/A" |
| 154 | +else |
| 155 | +formatted_version_name="[$version_name](https://coder.com/changelog/coder-$version_major-$rel_minor)" |
| 156 | +fi |
| 157 | + |
| 158 | +# Add row to table |
| 159 | +result+="|$formatted_version_name |$formatted_date |$status |$patch_link |\n" |
| 160 | +done |
| 161 | + |
| 162 | +echo -e"$result" |
| 163 | +} |
| 164 | + |
| 165 | +# Check if the markdown comments exist in the file |
| 166 | +if! grep -q"$CALENDAR_START_MARKER""$DOCS_FILE"||! grep -q"$CALENDAR_END_MARKER""$DOCS_FILE";then |
| 167 | +echo"Error: Markdown comment anchors not found in$DOCS_FILE" |
| 168 | +echo"Please add the following anchors around the release calendar table:" |
| 169 | +echo"$CALENDAR_START_MARKER" |
| 170 | +echo"$CALENDAR_END_MARKER" |
| 171 | +exit 1 |
| 172 | +fi |
| 173 | + |
| 174 | +# Generate the new calendar table content |
| 175 | +NEW_CALENDAR=$(generate_release_calendar) |
| 176 | + |
| 177 | +# Update the file while preserving the rest of the content |
| 178 | +awk -v start_marker="$CALENDAR_START_MARKER" \ |
| 179 | +-v end_marker="$CALENDAR_END_MARKER" \ |
| 180 | +-v new_calendar="$NEW_CALENDAR" \ |
| 181 | +' |
| 182 | + BEGIN { found_start = 0; found_end = 0; print_line = 1; } |
| 183 | + $0 ~ start_marker { |
| 184 | + print; |
| 185 | + print new_calendar; |
| 186 | + found_start = 1; |
| 187 | + print_line = 0; |
| 188 | + next; |
| 189 | + } |
| 190 | + $0 ~ end_marker { |
| 191 | + found_end = 1; |
| 192 | + print_line = 1; |
| 193 | + print; |
| 194 | + next; |
| 195 | + } |
| 196 | + print_line || !found_start || found_end { print } |
| 197 | +'"$DOCS_FILE">"${DOCS_FILE}.new" |
| 198 | + |
| 199 | +# Replace the original file with the updated version |
| 200 | +mv"${DOCS_FILE}.new""$DOCS_FILE" |
| 201 | + |
| 202 | +# run make fmt/markdown |
| 203 | +make fmt/markdown |
| 204 | + |
| 205 | +echo"Successfully updated release calendar in$DOCS_FILE" |