Skip to content

Create Release with Changelog #11

Create Release with Changelog

Create Release with Changelog #11

Workflow file for this run

name: Create Release with Changelog
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
- name: Extract changelog for the tag
id: changelog
run: |
# Get the current tag
CURRENT_TAG=${GITHUB_REF#refs/tags/}
# Extract changelog for the current tag using awk
CHANGELOG=$(grep -A 1000 "^## \[$CURRENT_TAG\]" CHANGELOG.md | sed -n '/^## \[v0.2.0\]/,/^<a name/{p}' | sed '$d')
# Handle no match (e.g., if the tag isn't in the changelog)
if [[ -z "$CHANGELOG" ]]; then
echo "Changelog for ${CURRENT_TAG} not found. Please ensure CHANGELOG.md is updated."
exit 1
fi
echo "CHANGELOG_CONTENT<<EOF" >> $GITHUB_ENV
echo "$CHANGELOG" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Step 3: Create a GitHub Release
# - name: Create GitHub Release
# id: create_release
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: ${{ github.ref_name }}
# release_name: Release ${{ github.ref_name }}
# body: ${{ env.CHANGELOG_CONTENT }}
# draft: false
# prerelease: false
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
run: |
echo ${{ env.CHANGELOG_CONTENT }} > temp_changelog.md
gh release create "$tag" \
--repo="$GITHUB_REPOSITORY" \
--title="${tag#v}" \
--notes-file=temp_changelog.md