1111 description : ' End editing at this version (e.g., 0.21.0). Leave empty for all versions from start_version.'
1212 required : false
1313 default : ' ' # Leave empty to process all versions from start_version onwards
14- changelog_commit_ref :
15- description : ' Commit hash or branch where the full changelog.mdx exists (e.g., master or a specific hash). Defaults to current ref.'
16- required : false
17- # IMPORTANT: Use the commit hash where your changelog.mdx has all the correct release notes.
18- # If your 'master' branch has the complete changelog, 'master' is fine.
19- # If the files were at a specific older commit, use that hash (e.g., '96ead5ee413f83fc58796f1661791122cf1a7f60')
20- default : ' master' # Change this if your full changelog is on a different branch or specific commit
2114
2215jobs :
2316 edit_releases :
@@ -26,88 +19,16 @@ jobs:
2619 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
2720
2821 steps :
29- - name : Checkout repository (for changelog)
30- uses : actions/checkout@v4
31- with :
32- ref : ${{ github.event.inputs.changelog_commit_ref }}
33- fetch-depth : 0 # Get full history for accurate changelog parsing
34-
3522 - name : Install GitHub CLI
3623 run : |
3724 sudo apt-get update
3825 sudo apt-get install -y gh
3926
40- - name : Set up Node.js for Changelog Parsing
41- uses : actions/setup-node@v4
42- with :
43- node-version : ' 20'
44-
45- - name : Create release body parser script
46- id : create_parser_script
47- run : |
48- cat << 'EOF' > parse_changelog.js
49- const fs = require('fs');
50- const path = require('path');
51-
52- const changelogPath = path.join(process.env.GITHUB_WORKSPACE, 'documentation', 'docs', 'pages', 'docs', 'changelog.mdx');
53- const rawVersion = process.argv[2]; // Version string passed (e.g., "0.1.0", "0.21.0")
54-
55- let headerToMatch = '';
56- if (rawVersion === '0.1.0') {
57- headerToMatch = `# ${rawVersion}`;
58- } else {
59- headerToMatch = `# ${rawVersion}-beta`;
60- }
61-
62- console.log(`Attempting to parse changelog for header: "${headerToMatch}"`);
63-
64- let releaseNotes = "No specific features/bug fixes mentioned in changelog.";
65-
66- try {
67- const changelogContent = fs.readFileSync(changelogPath, 'utf8');
68- const releasesSection = changelogContent.split(/^## Releases/m)[1];
69- if (!releasesSection) {
70- console.error("Could not find '## Releases' section in changelog.");
71- // This error means the file structure is wrong, but we should still
72- // output something to the workflow command file to avoid script breakage.
73- // We'll proceed with default notes if this happens.
74- } else {
75- const releasePattern = new RegExp(`^${headerToMatch}\\s*-\\s*\\d+(?:st|nd|rd|th) \\w+ \\d{4}([\\s\\S]*?)(?:\\n# \\d+\\.\\d+\\.\\d+|$|^## |$)`, 'm');
76- const match = releasesSection.match(releasePattern);
77-
78- if (match && match[1]) {
79- releaseNotes = match[1].trim();
80- releaseNotes = releaseNotes
81- .replace(/^(github branch - https:\/\/github\.com\/joshstevens19\/rindexer\/tree\/release\/.*)$/gm, '')
82- .replace(/^- (linux|mac|windows) binary - https:\/\/(github|rindexer\.xyz).*$/gm, '')
83- .replace(/^### Features\n-------------------------------------------------$/gm, '### Features')
84- .replace(/^### Bug fixes\n-------------------------------------------------$/gm, '### Bug fixes')
85- .replace(/^### Breaking changes\n-------------------------------------------------$/gm, '### Breaking changes')
86- .replace(/^-+\s*$/gm, '')
87- .replace(/^\s*[\r\n]+/gm, '')
88- .trim();
89-
90- if (releaseNotes === '') {
91- releaseNotes = "No specific features/bug fixes mentioned in changelog.";
92- }
93- }
94- }
95- } catch (error) {
96- console.error(`Error reading or parsing changelog: ${error.message}`);
97- // Still proceed with default notes if file cannot be read
98- }
99-
100- // Write the output to GITHUB_OUTPUT environment file
101- // This is the correct way to set multiline outputs from scripts
102- // without them appearing in stdout capture.
103- fs.writeFileSync(process.env.GITHUB_OUTPUT, `release_body<<EOF_DELIMITER\n${releaseNotes}\nEOF_DELIMITER\n`, { flag: 'a' });
104-
105- EOF
106- chmod +x parse_changelog.js
107-
10827 - name : Get all existing release tags
10928 id : get_tags
11029 run : |
30+ # Get all tags that start with 'v' and look like versions, then sort them.
31+ # This ensures we only process valid version tags that GitHub created.
11132 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 ' ' -)
11233 echo "Found tags: $ALL_TAGS"
11334 echo "all_versions=$ALL_TAGS" >> $GITHUB_OUTPUT
12748 # Filter versions based on optional inputs
12849 FILTERED_VERSIONS=""
12950
51+ # Function for version comparison using sort -V (semantic versioning)
13052 version_ge() {
13153 local v1="$1"
13254 local v2="$2"
@@ -141,13 +63,13 @@ jobs:
14163 for ver in $ALL_VERSIONS; do
14264 if [[ -n "$START_VERSION" ]]; then
14365 if ! version_ge "$ver" "$START_VERSION"; then
144- continue
66+ continue # Skip if less than start_version
14567 fi
14668 fi
14769
14870 if [[ -n "$END_VERSION" ]]; then
14971 if ! version_le "$ver" "$END_VERSION"; then
150- continue
72+ continue # Skip if greater than end_version
15173 fi
15274 fi
15375
@@ -166,30 +88,19 @@ jobs:
16688
16789 TAG="v$VERSION"
16890
169- # Corrected INSTALL_INSTRUCTIONS block
170- INSTALL_INSTRUCTIONS="# Latest version
171- curl -L https://rindexer.xyz/install.sh | bash
172- # Specific version
173- curl -L https://rindexer.xyz/install.sh | bash -s -- --version $VERSION"
174-
175- # Call Node.js script to get release body.
176- # Capture its stdout, but the actual output is now written to GITHUB_OUTPUT
177- node parse_changelog.js "$VERSION "
178-
179- # Read the output from the GITHUB_OUTPUT file
180- # This uses 'sed' to extract the content between the delimiters
181- CLEANED_CHANGELOG_BODY=$(sed -n '/^release_body<<EOF_DELIMITER$/,/^EOF_DELIMITER$/{/^release_body<<EOF_DELIMITER$/! {/^EOF_DELIMITER$/! p}}' "$GITHUB_OUTPUT" | head -n 1) # Capture only the content
91+ # Define the exact release body as per your last request
92+ # No changelog parsing or dynamic content here, just the install instructions.
93+ RELEASE_BODY="
94+ # Install
95+ \`\`\` bash
96+ curl -L https://rindexer.xyz/install.sh | bash -s -- --version $VERSION
97+ \`\`\`"
98+
99+ echo "Attempting to edit release $TAG... "
100+ gh release edit "$TAG" \
101+ --prerelease=false \
102+ --notes "$RELEASE_BODY" \
103+ --target master
182104
183- # Combine all parts for the full release body
184- # Format the final body using markdown code blocks
185- FULL_RELEASE_BODY="${INSTALL_INSTRUCTIONS}\n\n${CLEANED_CHANGELOG_BODY}\n\nSee full changelog for details: https://github.com/joshstevens19/rindexer/blob/master/documentation/docs/pages/docs/changelog.mdx"
186-
187-
188- echo "Attempting to edit release $TAG..."
189- gh release edit "$TAG" \
190- --prerelease=false \
191- --notes "$FULL_RELEASE_BODY" \
192- --target master
193-
194- echo "Successfully edited release $TAG."
195- done
105+ echo "Successfully edited release $TAG."
106+ done
0 commit comments