Generate Release Notes #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Generate Release Notes | |
| on: | |
| # Triggered via repository_dispatch from bluez/bluez or manually | |
| repository_dispatch: | |
| types: [new-release] | |
| # Allow manual trigger with tag override | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Release tag (e.g., 5.87)' | |
| required: true | |
| previous_tag: | |
| description: 'Previous release tag (auto-detected if empty)' | |
| required: false | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| generate-release-notes: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Determine tags | |
| id: tags | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Get the new tag from dispatch event or manual input | |
| if [ "${{ github.event_name }}" = "repository_dispatch" ]; then | |
| NEW_TAG="${{ github.event.client_payload.tag }}" | |
| else | |
| NEW_TAG="${{ inputs.tag }}" | |
| fi | |
| if [ -z "$NEW_TAG" ]; then | |
| echo "::error::No tag specified" | |
| exit 1 | |
| fi | |
| # Determine previous tag if not provided | |
| PREV_TAG="${{ inputs.previous_tag }}" | |
| if [ -z "$PREV_TAG" ]; then | |
| # Parse version number and decrement | |
| MAJOR=$(echo "$NEW_TAG" | cut -d. -f1) | |
| MINOR=$(echo "$NEW_TAG" | cut -d. -f2) | |
| PREV_MINOR=$((MINOR - 1)) | |
| PREV_TAG="${MAJOR}.${PREV_MINOR}" | |
| fi | |
| echo "new_tag=${NEW_TAG}" >> "$GITHUB_OUTPUT" | |
| echo "previous_tag=${PREV_TAG}" >> "$GITHUB_OUTPUT" | |
| echo "Tags: ${PREV_TAG} -> ${NEW_TAG}" | |
| - name: Generate release notes | |
| id: generate | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| chmod +x .github/scripts/fetch-release-prs.sh | |
| .github/scripts/fetch-release-prs.sh \ | |
| "${{ steps.tags.outputs.previous_tag }}" \ | |
| "${{ steps.tags.outputs.new_tag }}" \ | |
| > release_notes.md 2>fetch.log | |
| cat fetch.log | |
| echo "" | |
| echo "Release notes size: $(wc -l < release_notes.md) lines, $(wc -c < release_notes.md) bytes" | |
| if [ ! -s release_notes.md ]; then | |
| echo "::error::No release notes generated" | |
| exit 1 | |
| fi | |
| - name: Create Hugo post | |
| id: post | |
| run: | | |
| NEW_TAG="${{ steps.tags.outputs.new_tag }}" | |
| PREV_TAG="${{ steps.tags.outputs.previous_tag }}" | |
| YEAR=$(date +%Y) | |
| TODAY=$(date +%Y-%m-%d) | |
| POST_DIR="content/news/${YEAR}" | |
| POST_FILE="${POST_DIR}/bluez-${NEW_TAG//\./-}-release.md" | |
| mkdir -p "${POST_DIR}" | |
| # Build the Hugo post | |
| cat > "${POST_FILE}" << FRONTMATTER | |
| --- | |
| title: "Release of BlueZ ${NEW_TAG}" | |
| date: ${TODAY} | |
| summary: "BlueZ ${NEW_TAG} has been released with improvements and bug fixes." | |
| draft: false | |
| --- | |
| FRONTMATTER | |
| # Remove leading spaces from heredoc | |
| sed -i 's/^ //' "${POST_FILE}" | |
| # Append the release notes body | |
| echo "" >> "${POST_FILE}" | |
| cat release_notes.md >> "${POST_FILE}" | |
| echo "post_file=${POST_FILE}" >> "$GITHUB_OUTPUT" | |
| echo "branch=release-${NEW_TAG}" >> "$GITHUB_OUTPUT" | |
| echo "Created: ${POST_FILE}" | |
| - name: Create Pull Request | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| NEW_TAG="${{ steps.tags.outputs.new_tag }}" | |
| PREV_TAG="${{ steps.tags.outputs.previous_tag }}" | |
| BRANCH="${{ steps.post.outputs.branch }}" | |
| POST_FILE="${{ steps.post.outputs.post_file }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git checkout -b "${BRANCH}" | |
| git add "${POST_FILE}" | |
| git commit -m "Add release notes for BlueZ ${NEW_TAG}" | |
| git push --force origin "${BRANCH}" | |
| gh pr create \ | |
| --title "Add release notes for BlueZ ${NEW_TAG}" \ | |
| --body "$(cat <<EOF | |
| ## Release Notes - BlueZ ${NEW_TAG} | |
| Auto-generated release notes for BlueZ ${NEW_TAG}. | |
| - **Changelog**: [${PREV_TAG}...${NEW_TAG}](https://github.com/bluez/bluez/compare/${PREV_TAG}...${NEW_TAG}) | |
| - **Data source**: GitHub PRs closed between releases | |
| > **Note**: Please review categories and descriptions before merging. | |
| EOF | |
| )" \ | |
| --base main \ | |
| --head "${BRANCH}" | |
| - name: Upload release notes artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-notes-${{ steps.tags.outputs.new_tag }} | |
| path: release_notes.md |