Skip to content

Release notification #594

Release notification

Release notification #594

name: 'Release notification'
on: create
permissions:
contents: write
jobs:
create-notification:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Fetch all tags
run: git fetch --tags
- name: Get latest and previous tags
id: tags
run: |
all_tags=$(git tag -l --sort=-creatordate)
latest_tag=$(echo "$all_tags" | sed -n '1p')
previous_tag=$(echo "$all_tags" | sed -n '2p')
echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT
echo "previous_tag=$previous_tag" >> $GITHUB_OUTPUT
# Debug output
echo "Latest tag: $latest_tag"
echo "Previous tag: $previous_tag"
- name: Generate Release Notes
run: |
echo "Changes between ${{ steps.tags.outputs.previous_tag }} and ${{ steps.tags.outputs.latest_tag }}:" > release-notes.txt
git log ${{ steps.tags.outputs.previous_tag }}..${{ steps.tags.outputs.latest_tag }} --oneline >> release-notes.txt
RELEASE_NOTES=$(cat release-notes.txt)
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
echo "$RELEASE_NOTES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create or Update Release
run: |
if gh release view ${{ steps.tags.outputs.latest_tag }} &>/dev/null; then
echo "Release exists. Updating..."
gh release edit ${{ steps.tags.outputs.latest_tag }} --notes "$RELEASE_NOTES"
else
echo "Creating new release..."
gh release create ${{ steps.tags.outputs.latest_tag }} --notes "$RELEASE_NOTES"
fi
- name: Divide Notes into Chores, Features, and Bugs
id: categorize_notes
run: |
echo "${{ env.RELEASE_NOTES }}" > release_notes.txt
grep -iE 'CHORE|MIJN-[0-9]+-CHORE' release_notes.txt | sort -u > chores.txt || true
grep -iE 'FEATURE:|MIJN-[0-9]+-FEATURE' release_notes.txt > features.txt || true
grep -iE 'BUG:|MIJN-[0-9]+-BUG' release_notes.txt > bugs.txt || true
grep -iE 'MIJN-[0-9]+($|[^-])' release_notes.txt > mijn.txt || true
- name: Output Categorized Notes
run: |
append_to_github_output() {
if [ -s "$1.txt" ]; then
echo "$1<<EOF" >> "$GITHUB_OUTPUT"
cat "$1.txt" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
fi
}
append_to_github_output 'chores'
append_to_github_output 'features'
append_to_github_output 'bugs'
append_to_github_output 'mijn'
- name: Create Customized Release Notes
id: custom_release_notes
run: |
{
echo "## Release Notes"
echo "### Chores"
echo "${{ steps.categorize_notes.outputs.chores }}"
echo "### Features"
echo "${{ steps.categorize_notes.outputs.features }}"
echo "### Bugs"
echo "${{ steps.categorize_notes.outputs.bugs }}"
echo "### Mijn"
echo "${{ steps.categorize_notes.outputs.mijn }}"
} > custom_release_notes.txt
CUSTOM_NOTES=$(cat custom_release_notes.txt)
echo "CUSTOM_NOTES<<EOF" >> $GITHUB_ENV
echo "$CUSTOM_NOTES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Update Release with Custom Notes
run: |
gh release edit ${{ steps.tags.outputs.latest_tag }} --notes "${{ env.CUSTOM_NOTES }}"