Skip to content

Edit Existing GitHub Releases (One-Time) #11

Edit Existing GitHub Releases (One-Time)

Edit Existing GitHub Releases (One-Time) #11

Workflow file for this run

name: Edit Existing GitHub Releases (One-Time)
on:
workflow_dispatch:
inputs:
start_version:
description: 'Start editing from this version (e.g., 0.1.0)'
required: false
default: '0.1.0' # Adjust this to the earliest version you want to edit
end_version:
description: 'End editing at this version (e.g., 0.21.0). Leave empty for all versions from start_version.'
required: false
default: '' # Leave empty to process all versions from start_version onwards
jobs:
edit_releases:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install -y gh
- name: Get all existing release tags
id: get_tags
run: |
# Get all tags that start with 'v' and look like versions, then sort them.
# This ensures we only process valid version tags that GitHub created.
ALL_TAGS=$(gh api --paginate "/repos/${{ github.repository }}/tags" --jq '.[].name' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//' | sort -V | paste -sd ' ' -)
echo "Found tags: $ALL_TAGS"
echo "all_versions=$ALL_TAGS" >> $GITHUB_OUTPUT
- name: Edit Releases
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
START_VERSION: ${{ github.event.inputs.start_version }}
END_VERSION: ${{ github.event.inputs.end_version }}
run: |
#!/bin/bash
set -e
ALL_VERSIONS="${{ steps.get_tags.outputs.all_versions }}"
CHANGELOG_FILE="documentation/docs/pages/docs/changelog.mdx"
# Check if changelog file exists
if [[ ! -f "$CHANGELOG_FILE" ]]; then
echo "Changelog file not found: $CHANGELOG_FILE"
exit 1
fi
echo "Debug: Changelog file found. First 20 lines:"
head -20 "$CHANGELOG_FILE"
echo "Debug: ===================="
# Filter versions based on optional inputs
FILTERED_VERSIONS=""
# Function for version comparison using sort -V (semantic versioning)
version_ge() {
local v1="$1"
local v2="$2"
[[ "$v1" = "$v2" ]] || [[ "$(printf '%s\n' "$v1" "$v2" | sort -V | head -n1)" = "$v2" ]]
}
version_le() {
local v1="$1"
local v2="$2"
[[ "$v1" = "$v2" ]] || [[ "$(printf '%s\n' "$v1" "$v2" | sort -V | tail -n1)" = "$v2" ]]
}
# Function to extract changelog content for a specific version
extract_changelog() {
local version="$1"
local changelog_content=""
echo "Debug: Looking for version $version in changelog" >&2
# First, let's see if we can find the version at all
if ! grep -q "$version-beta" "$CHANGELOG_FILE"; then
echo "Debug: Version $version-beta not found in changelog" >&2
return
fi
echo "Debug: Found version $version-beta in changelog" >&2
# Find the section for this version and extract until the next version
changelog_content=$(awk -v version="$version" '
BEGIN { found=0; in_section=0; debug=0 }
/^# [0-9]+\.[0-9]+\.[0-9]+-beta/ {
if (debug) print "Found version header: " $0 > "/dev/stderr"
if (found && in_section) {
if (debug) print "Exiting - found next version" > "/dev/stderr"
exit
}
if ($0 ~ "^# " version "-beta") {
if (debug) print "Found our version: " version > "/dev/stderr"
found=1
in_section=1
next
}
}
found && in_section {
# Skip certain lines but keep most content
if ($0 !~ /^github branch -/ &&
$0 !~ /^- (linux|mac|windows) binary -/ &&
$0 !~ /^all release branches are deployed/ &&
$0 != "") {
print $0
}
}
' "$CHANGELOG_FILE")
echo "Debug: Extracted content length: ${#changelog_content}" >&2
echo "$changelog_content"
}
for ver in $ALL_VERSIONS; do
if [[ -n "$START_VERSION" ]]; then
if ! version_ge "$ver" "$START_VERSION"; then
continue # Skip if less than start_version
fi
fi
if [[ -n "$END_VERSION" ]]; then
if ! version_le "$ver" "$END_VERSION"; then
continue # Skip if greater than end_version
fi
fi
FILTERED_VERSIONS+=" $ver"
done
if [ -z "$FILTERED_VERSIONS" ]; then
echo "No versions to edit after applying filters. Exiting."
exit 0
fi
echo "Editing versions: $FILTERED_VERSIONS"
for VERSION in $FILTERED_VERSIONS; do
echo "--- Processing version: $VERSION ---"
TAG="v$VERSION"
# Extract changelog content for this version
echo "Extracting changelog for version: $VERSION"
CHANGELOG_CONTENT=$(extract_changelog "$VERSION")
echo "Debug: Raw changelog content:"
echo "[$CHANGELOG_CONTENT]"
echo "Debug: Content length: ${#CHANGELOG_CONTENT}"
# Clean up the changelog content - remove empty lines at start and end
CHANGELOG_CONTENT=$(echo "$CHANGELOG_CONTENT" | sed '/^$/d' | sed '/^-\+$/d')
echo "Debug: Cleaned changelog content:"
echo "[$CHANGELOG_CONTENT]"
# Build the release body with install instructions and changelog
INSTALL_SECTION="# Install
\`\`\`bash
curl -L https://rindexer.xyz/install.sh | bash -s -- --version $VERSION
\`\`\`"
if [[ -n "$CHANGELOG_CONTENT" ]]; then
RELEASE_BODY="$INSTALL_SECTION
# Changelog
$CHANGELOG_CONTENT"
else
echo "Warning: No changelog content found for version $VERSION"
RELEASE_BODY="$INSTALL_SECTION"
fi
echo "Attempting to edit release $TAG..."
echo "Release body preview:"
echo "========================"
echo "$RELEASE_BODY"
echo "========================"
gh release edit "$TAG" \
--repo ${{ github.repository }} \
--prerelease=false \
--notes "$RELEASE_BODY" \
--target master
echo "Successfully edited release $TAG."
done