|
21 | 21 | default: false |
22 | 22 | changelog: |
23 | 23 | type: string |
24 | | - description: "Changelog (required if publishing, markdown format, do NOT include version or date header. Use sections like ### Added, ### Changed, etc.)" |
| 24 | + description: "Changelog (required if publishing, markdown format, do NOT include version or date header. Use sections like ### Added, ### Changed, etc. Each section should be on a new line, and bullet points should start with -)" |
25 | 25 | default: "" |
26 | 26 | discord_notify: |
27 | 27 | type: boolean |
@@ -159,37 +159,36 @@ jobs: |
159 | 159 | echo -e "# Changelog\n" > "$FILE" |
160 | 160 | fi |
161 | 161 |
|
162 | | - # Find the line number of the "# Changelog" header |
163 | | - HEADER_LINE=$(grep -n "^# Changelog" "$FILE" | cut -d: -f1) |
164 | | - if [ -z "$HEADER_LINE" ]; then |
165 | | - # If not found, just prepend |
166 | | - HEADER_LINE=0 |
167 | | - fi |
| 162 | + # Find the insertion point - look for the first version entry (## [version]) |
| 163 | + # This ensures we insert after the intro section but before any existing versions |
| 164 | + FIRST_VERSION_LINE=$(grep -n "^## \[" "$FILE" | head -1 | cut -d: -f1) |
168 | 165 |
|
169 | | - # Find the line number after the intro section (after the first blank line following '# Changelog') |
170 | | - INTRO_END_LINE=$(awk '/^# Changelog/{flag=1; next} flag && /^$/{print NR; exit}' "$FILE") |
171 | | - if [ -z "$INTRO_END_LINE" ]; then |
172 | | - # Fallback: if not found, use header line |
173 | | - HEADER_LINE=$(grep -n "^# Changelog" "$FILE" | cut -d: -f1) |
174 | | - if [ -z "$HEADER_LINE" ]; then |
175 | | - HEADER_LINE=0 |
176 | | - fi |
177 | | - INTRO_END_LINE=$((HEADER_LINE + 1)) |
| 166 | + if [ -z "$FIRST_VERSION_LINE" ]; then |
| 167 | + # No existing versions found, append to end of file |
| 168 | + INSERTION_LINE=$(wc -l < "$FILE") |
| 169 | + else |
| 170 | + # Insert before the first version entry |
| 171 | + INSERTION_LINE=$((FIRST_VERSION_LINE - 1)) |
178 | 172 | fi |
179 | 173 |
|
180 | 174 | # Process the changelog input to ensure proper formatting |
181 | | - # Handle both multi-line and single-line input from GitHub UI |
182 | | - PRETTY_CHANGELOG=$(echo "$CHANGELOG" | sed -E 's/\\n/\n/g' | sed -E 's/\\1/\n/g' | sed -E 's/^[[:space:]]*//' | sed -E 's/[[:space:]]*$//') |
183 | | -
|
184 | | - # Write up to and including the intro |
185 | | - if [ "$INTRO_END_LINE" -gt 0 ]; then |
186 | | - head -n "$INTRO_END_LINE" "$FILE" > "$TEMP_FILE" |
| 175 | + # Python3 is pre-installed on ubuntu-latest runners (free, no extra cost) |
| 176 | + PRETTY_CHANGELOG=$(python3 scripts/format-changelog.py "$CHANGELOG") |
| 177 | +
|
| 178 | + # Write the file up to insertion point |
| 179 | + if [ "$INSERTION_LINE" -gt 0 ]; then |
| 180 | + head -n "$INSERTION_LINE" "$FILE" > "$TEMP_FILE" |
| 181 | + else |
| 182 | + # If no insertion point found, start with the header |
| 183 | + echo -e "# Changelog\n" > "$TEMP_FILE" |
187 | 184 | fi |
188 | | - # Add the new entry |
| 185 | +
|
| 186 | + # Add the new entry with proper formatting |
189 | 187 | echo -e "\n${HEADER}\n\n${PRETTY_CHANGELOG}\n" >> "$TEMP_FILE" |
190 | | - # Add the rest of the file |
191 | | - if [ "$INTRO_END_LINE" -gt 0 ]; then |
192 | | - tail -n "+$((INTRO_END_LINE + 1))" "$FILE" >> "$TEMP_FILE" |
| 188 | +
|
| 189 | + # Add the rest of the file (existing versions) |
| 190 | + if [ "$INSERTION_LINE" -gt 0 ] && [ "$INSERTION_LINE" -lt $(wc -l < "$FILE") ]; then |
| 191 | + tail -n "+$((INSERTION_LINE + 1))" "$FILE" >> "$TEMP_FILE" |
193 | 192 | fi |
194 | 193 | mv "$TEMP_FILE" "$FILE" |
195 | 194 |
|
|
0 commit comments