Skip to content

fix: use pipe delimiter in sed for changelog workflow #11

fix: use pipe delimiter in sed for changelog workflow

fix: use pipe delimiter in sed for changelog workflow #11

Workflow file for this run

name: Update Changelog
on:
push:
branches: [main]
workflow_dispatch:
jobs:
changelog:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
run: |
# Get all commits with email in descending order (newest first), excluding changelog bot commits
git log --pretty=format:'%ad|%s|%an|%ae' --date=short | grep -v '\[skip ci\]' > /tmp/commits.txt
# Generate changelog content grouped by date
echo "" > /tmp/changelog_content.md
current_date=""
while IFS='|' read -r date message author email; do
if [ "$date" != "$current_date" ]; then
if [ -n "$current_date" ]; then
echo "" >> /tmp/changelog_content.md
fi
echo "### $date" >> /tmp/changelog_content.md
echo "" >> /tmp/changelog_content.md
current_date="$date"
fi
# Extract GitHub username from email if it's a GitHub email
if [[ "$email" == *"@users.noreply.github.com" ]]; then
github_user=$(echo "$email" | sed 's/@users.noreply.github.com//' | sed 's/^[0-9]*+//')
author_link="[@${author}](https://github.com/${github_user})"
else
author_link="@${author}"
fi
# Check if message is a merge commit (contains PR number)
if [[ "$message" =~ Merge\ pull\ request\ \#([0-9]+) ]]; then
pr_number="${BASH_REMATCH[1]}"
pr_link="[#${pr_number}](https://github.com/kaic/win-post-install/pull/${pr_number})"
message=$(echo "$message" | sed "s|Merge pull request #${pr_number}|${pr_link}|")
fi
echo "- $message (${author_link})" >> /tmp/changelog_content.md
done < /tmp/commits.txt
# Update CHANGELOG.md between markers
head -n $(grep -n "CHANGELOG_START" CHANGELOG.md | cut -d: -f1) CHANGELOG.md > /tmp/changelog_new.md
echo "" >> /tmp/changelog_new.md
cat /tmp/changelog_content.md >> /tmp/changelog_new.md
echo "" >> /tmp/changelog_new.md
tail -n +$(grep -n "CHANGELOG_END" CHANGELOG.md | cut -d: -f1) CHANGELOG.md >> /tmp/changelog_new.md
mv /tmp/changelog_new.md CHANGELOG.md
- name: Commit and push if changed
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git diff --staged --quiet || git commit -m "docs: update changelog [skip ci]"
git push