Skip to content

Commit

Permalink
feat(workflow): Integrate CHANGELOG generation into release action
Browse files Browse the repository at this point in the history
- Merge changelog update logic directly into the workflow file
- Remove separate update_changelog.sh script
- Improve function order and variable definitions in the script
- Ensure proper handling of existing changelog entries
- Maintain compatibility with existing release creation/update steps
  • Loading branch information
joshuadanpeterson committed Jul 20, 2024
1 parent a97d369 commit b6196ea
Showing 1 changed file with 67 additions and 9 deletions.
76 changes: 67 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,79 @@ jobs:
- name: Update CHANGELOG.md
shell: bash
run: |
# Set execute permissions
chmod +x $GITHUB_WORKSPACE/.github/scripts/update_changelog.sh
# Convert line endings
sed -i 's/\r$//' $GITHUB_WORKSPACE/.github/scripts/update_changelog.sh
# Set variables
NEW_VERSION='${{ steps.determine_version.outputs.NEW_VERSION }}'
CHANGELOG=$(cat << 'EOF'
${{ steps.get_changelog.outputs.CHANGELOG }}
EOF
)
# Run the update changelog script
$GITHUB_WORKSPACE/.github/scripts/update_changelog.sh "$NEW_VERSION" "$CHANGELOG"
CURRENT_DATE=$(TZ='America/Denver' date +%Y-%m-%d)
REPO_URL="https://github.com/joshuadanpeterson/typewriter.nvim"
format_entry() {
local version=$1
local date=$2
local content=$3
local prev_version=$4
echo "## [$version]($REPO_URL/tree/$version) ($date)"
echo "$content"
echo
echo "[Full Changelog]($REPO_URL/compare/$prev_version...$version)"
echo
}
remove_duplicates() {
echo "$1" | awk '!seen[$0]++'
}
echo "# Changelog" > temp_changelog.md
echo >> temp_changelog.md
# Add new version
NEW_CHANGELOG=$(remove_duplicates "$CHANGELOG")
format_entry "$NEW_VERSION" "$CURRENT_DATE" "$NEW_CHANGELOG" "${{ steps.determine_version.outputs.LATEST_TAG }}" >> temp_changelog.md
prev_version="$NEW_VERSION"
declare -A processed_versions
while IFS= read -r line; do
if [[ $line =~ ^##[[:space:]]+(\[v[0-9]+\.[0-9]+\.[0-9]+\])(.*)$ ]]; then
version="${BASH_REMATCH[1]}"
version="${version:1:-1}"
if [[ -n "${processed_versions[$version]}" ]] || [[ "$version" == "$NEW_VERSION" ]]; then
continue
fi
processed_versions[$version]=1
date_part="${BASH_REMATCH[2]}"
date=$(echo "$date_part" | grep -oP '\(\K[0-9]{4}-[0-9]{2}-[0-9]{2}(?=\))' || echo "Unknown Date")
if [ "$date" != "Unknown Date" ]; then
date=$(TZ='America/Denver' date -d "$date" +%Y-%m-%d)
fi
content=$(sed -n "/^## \[$version\]/,/^## \[v[0-9]/{ /^## \[v[0-9]/d; p; }" CHANGELOG.md)
content=$(echo "$content" | sed '/^\[Full Changelog\]/d' | sed '/^$/N;/^\n$/D')
content=$(remove_duplicates "$content")
format_entry "$version" "$date" "$content" "$prev_version" >> temp_changelog.md
prev_version="$version"
fi
done < CHANGELOG.md
mv temp_changelog.md CHANGELOG.md
if ! grep -q "^# Changelog" CHANGELOG.md || ! grep -q "^## \[v[0-9]\+\.[0-9]\+\.[0-9]\+\]" CHANGELOG.md; then
echo "Error: CHANGELOG.md formatting verification failed"
exit 1
fi
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add CHANGELOG.md
git commit -m "docs: update CHANGELOG.md for ${NEW_VERSION} and remove duplicate entries"
git push
- name: Check if release exists
id: check_release
Expand Down

0 comments on commit b6196ea

Please sign in to comment.