Skip to content

Commit

Permalink
Fix: Deduplicate repeated entries when building the changelog (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
dleviminzi authored Oct 9, 2024
1 parent 525b5dd commit ddfbc91
Showing 1 changed file with 60 additions and 30 deletions.
90 changes: 60 additions & 30 deletions .github/workflows/release-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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: |
Expand Down

0 comments on commit ddfbc91

Please sign in to comment.