From ddfbc91ed6d936389bf9cfc63ef865fe1ce4e1d7 Mon Sep 17 00:00:00 2001 From: Daniel Levi-Minzi <51272568+dleviminzi@users.noreply.github.com> Date: Tue, 8 Oct 2024 22:24:12 -0400 Subject: [PATCH] Fix: Deduplicate repeated entries when building the changelog (#605) --- .github/workflows/release-changelog.yml | 90 ++++++++++++++++--------- 1 file changed, 60 insertions(+), 30 deletions(-) diff --git a/.github/workflows/release-changelog.yml b/.github/workflows/release-changelog.yml index 67e6adf85..bfc80bed7 100644 --- a/.github/workflows/release-changelog.yml +++ b/.github/workflows/release-changelog.yml @@ -66,12 +66,9 @@ jobs: return; } - const featsString = feats.map(feat => `- ${feat}`).join('\n'); - const fixesString = fixes.map(fix => `- fix ${fix}`).join('\n'); - core.setOutput('name', release.name.replace(/(:\s)/g, '-v')); - core.setOutput('feats', featsString); - core.setOutput('fixes', fixesString); + core.setOutput('new_feats', JSON.stringify(feats)); + core.setOutput('new_fixes', JSON.stringify(fixes)); core.setOutput('created_at', formatDate(release.created_at)); core.setOutput('pretty_date', prettyDate(release.created_at)); core.setOutput('should_continue', 'true'); @@ -84,38 +81,71 @@ jobs: path: beam-docs token: ${{ secrets.BEAM_DOCS_PAT }} + - name: Process changelog + if: steps.release.outputs.should_continue == 'true' + id: process_changelog + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const path = require('path'); + + const filename = `./beam-docs/v2/releases/${process.env.CREATED_AT}.mdx`; + let existingFeats = []; + let existingFixes = []; + + if (fs.existsSync(filename)) { + const content = fs.readFileSync(filename, 'utf8'); + const featuresMatch = content.match(/## Features\n([\s\S]*?)(?=\n## |$)/); + const fixesMatch = content.match(/## Fixes\n([\s\S]*?)(?=\n## |$)/); + + if (featuresMatch) { + existingFeats = featuresMatch[1].split('\n').filter(line => line.trim().startsWith('-')).map(line => line.trim().slice(2)); + } + if (fixesMatch) { + existingFixes = fixesMatch[1].split('\n').filter(line => line.trim().startsWith('-')).map(line => line.trim().slice(2)); + } + } + + const newFeats = JSON.parse(process.env.NEW_FEATS); + const newFixes = JSON.parse(process.env.NEW_FIXES); + + const allFeats = [...new Set([...existingFeats, ...newFeats])]; + const allFixes = [...new Set([...existingFixes, ...newFixes])]; + + const featsString = allFeats.map(feat => `- ${feat}`).join('\n'); + const fixesString = allFixes.map(fix => `- ${fix}`).join('\n'); + + core.setOutput('feats', featsString); + core.setOutput('fixes', fixesString); + + env: + CREATED_AT: ${{ steps.release.outputs.created_at }} + NEW_FEATS: ${{ steps.release.outputs.new_feats }} + NEW_FIXES: ${{ steps.release.outputs.new_fixes }} + - name: Create new release file in beam-docs if: steps.release.outputs.should_continue == 'true' run: | cd beam-docs/v2/releases FILENAME="./${{ steps.release.outputs.created_at }}.mdx" - if [ ! -f "$FILENAME" ]; then - echo "---" >> $FILENAME - echo "title: \"${{ steps.release.outputs.pretty_date }}\"" >> $FILENAME - echo "---" >> $FILENAME - echo "" >> $FILENAME - echo "## Features" >> $FILENAME - echo "${{ steps.release.outputs.feats }}" >> $FILENAME - echo "" >> $FILENAME - echo "## Fixes" >> $FILENAME - echo "${{ steps.release.outputs.fixes }}" >> $FILENAME - echo "" >> $FILENAME - else - awk -v feats="${{ steps.release.outputs.feats }}" -v fixes="${{ steps.release.outputs.fixes }}" ' - /^## Features/ { - print - if (feats != "") print feats - next - } - /^## Fixes/ { - print - if (fixes != "") print fixes - next - } - { print } - ' "$FILENAME" > "${FILENAME}.tmp" && mv "${FILENAME}.tmp" "$FILENAME" + if [ -f "$FILENAME" ]; then + rm -f $FILENAME fi + echo "---" >> $FILENAME + echo "title: \"${{ steps.release.outputs.pretty_date }}\"" >> $FILENAME + echo "---" >> $FILENAME + echo "" >> $FILENAME + echo "## Features" >> $FILENAME + echo "" >> $FILENAME + echo "${{ steps.process_changelog.outputs.feats }}" >> $FILENAME + echo "" >> $FILENAME + echo "## Fixes" >> $FILENAME + echo "" >> $FILENAME + echo "${{ steps.process_changelog.outputs.fixes }}" >> $FILENAME + echo "" >> $FILENAME + - name: Update mint.json if: steps.release.outputs.should_continue == 'true' run: |